|
2 | 2 | import requests |
3 | 3 |
|
4 | 4 | from dataverse import Dataverse |
5 | | -from utils import get_elements |
| 5 | +from utils import get_elements, is_not_root_dataverse |
6 | 6 |
|
7 | 7 |
|
8 | 8 | class Connection(object): |
@@ -36,21 +36,19 @@ def connect(self): |
36 | 36 | self.connected = True if self.status == 200 else False |
37 | 37 | self.service_document = etree.XML(resp.content) |
38 | 38 |
|
39 | | - def get_dataverses(self): |
| 39 | + def get_dataverses(self, allow_root=False): |
40 | 40 | # Get latest dataverse information |
41 | 41 | self.connect() |
42 | 42 |
|
43 | | - # Dataverse 4.0 beta currently returns collection for "Harvard" DV, |
44 | | - # which the user may not have permissions on. Could cause problems. |
45 | 43 | collections = get_elements( |
46 | 44 | self.service_document[0], |
47 | 45 | tag="collection", |
48 | 46 | ) |
49 | | - # removes the Harvard dataverse; this is gross |
50 | | - # also removes the root dataverse (which users do not have read permission on) |
51 | | - def is_not_harvard_or_root(collection): |
52 | | - return (collection.attrib['href'].split('/')[-1] != 'harvard') and (collection.attrib['href'].split('/')[-1] != 'root') |
53 | | - collections = filter(is_not_harvard_or_root, collections) |
| 47 | + |
| 48 | + # Remove root Dataverses, which may cause permission issues |
| 49 | + # See https://github.com/IQSS/dataverse/issues/1070 |
| 50 | + if not allow_root: |
| 51 | + collections = filter(is_not_root_dataverse, collections) |
54 | 52 |
|
55 | 53 | return [Dataverse(self, col) for col in collections] |
56 | 54 |
|
|
0 commit comments