Skip to content

Commit 8954b48

Browse files
authored
Merge pull request #939 from scitran/search-non-user
Superuser searches don't have permissions in filter
2 parents 226f425 + b579da6 commit 8954b48

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

api/handlers/dataexplorerhandler.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ def _parse_request(self, request_type='search'):
379379
else:
380380
modified_filters.append(f)
381381

382-
# Add permissions filter to list if user is not requesting all data
383-
if not request.get('all_data', False):
382+
# Add permissions filter to list if user is not requesting all data or is superuser
383+
if not request.get('all_data', False) and not self.superuser_request:
384384
modified_filters.append({'term': {'permissions._id': self.uid}})
385385

386386
# Parse and "validate" search_string, allowed to be non-existent
@@ -400,8 +400,9 @@ def aggregate_field_values(self):
400400
field_name = self.request.json_body['field_name']
401401
except (KeyError, ValueError):
402402
self.abort(400, 'Field name is required')
403-
404-
filters = [{'term': {'permissions._id': self.uid}}]
403+
filters = []
404+
if not self.superuser_request:
405+
filters = [{'term': {'permissions._id': self.uid}}]
405406
try:
406407
field = config.es.get(index='data_explorer_fields', id=field_name, doc_type='flywheel_field')
407408
except TransportError as e:

test/unit_tests/python/test_dataexplorer.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ def test_search(as_public, as_drone, es):
4747
'must': {'match': {'_all': 'search'}},
4848
'filter': {'bool': {'must': [
4949
{'terms': {filter_key + '.raw': filter_value}},
50-
{'range': filter_range},
51-
{'term': {'permissions._id': None}}
50+
{'range': filter_range}
5251
]}},
5352
}},
5453
'aggs': {'by_container': {'terms':
@@ -146,6 +145,30 @@ def test_search(as_public, as_drone, es):
146145
assert r.ok
147146
assert r.json['results'] == formatted_file_results
148147

148+
# Drone search without self.uid and all_data set to false
149+
es.search.return_value = {'hits': {'hits': copy.deepcopy(raw_file_results)}}
150+
r = as_drone.post('/dataexplorer/search', json={'return_type': cont_type, 'all_data': False, 'search_string': search_str, 'filters': [
151+
{'terms': {filter_key: filter_value}},
152+
{'range': filter_range},
153+
]})
154+
es.search.assert_called_with(
155+
body={
156+
'_source': deh.SOURCE[cont_type],
157+
'query': {'bool': {
158+
'must': {'match': {'_all': search_str}},
159+
'filter': {'bool': {'must': [
160+
{'term': {'container_type': cont_type}},
161+
{'terms': {filter_key + '.raw': filter_value}},
162+
{'range': filter_range},
163+
]}}
164+
}},
165+
'script_fields': {'info_exists': deh.INFO_EXISTS_SCRIPT},
166+
'size': 100},
167+
doc_type='flywheel',
168+
index='data_explorer')
169+
assert r.ok
170+
assert r.json['results'] == formatted_file_results
171+
149172
# file search w/ search null filter
150173
es.search.return_value = {'hits': {'hits': copy.deepcopy(raw_file_results)}}
151174
r = as_drone.post('/dataexplorer/search', json={'return_type': cont_type, 'all_data': True, 'filters': [
@@ -350,7 +373,7 @@ def test_aggregate_field_values(as_public, as_drone, es):
350373
r = as_drone.post('/dataexplorer/search/fields/aggregate', json={'field_name': field_name})
351374
es.search.assert_called_with(
352375
body={'aggs': {'results': {'terms': {'field': field_name + '.raw', 'size': 15, 'missing': 'null'}}},
353-
'query': {'bool': {'filter': [{'term': {'permissions._id': None}}], 'must': {'match_all': {}}}},
376+
'query': {'bool': {'must': {'match_all': {}}}},
354377
'size': 0},
355378
doc_type='flywheel',
356379
index='data_explorer')
@@ -361,7 +384,7 @@ def test_aggregate_field_values(as_public, as_drone, es):
361384
r = as_drone.post('/dataexplorer/search/fields/aggregate', json={'field_name': field_name, 'search_string': search_str})
362385
es.search.assert_called_with(
363386
body={'aggs': {'results': {'terms': {'field': field_name + '.raw', 'size': 15, 'missing': 'null'}}},
364-
'query': {'bool': {'filter': [{'term': {'permissions._id': None}}], 'must': {'match': {'field': search_str}}}},
387+
'query': {'bool': {'must': {'match': {'field': search_str}}}},
365388
'size': 0},
366389
doc_type='flywheel',
367390
index='data_explorer')
@@ -373,7 +396,7 @@ def test_aggregate_field_values(as_public, as_drone, es):
373396
r = as_drone.post('/dataexplorer/search/fields/aggregate', json={'field_name': field_name})
374397
es.search.assert_called_with(
375398
body={'aggs': {'results': {'stats': {'field': field_name}}},
376-
'query': {'bool': {'filter': [{'term': {'permissions._id': None}}], 'must': {'match_all': {}}}},
399+
'query': {'bool': {'must': {'match_all': {}}}},
377400
'size': 0},
378401
doc_type='flywheel',
379402
index='data_explorer')
@@ -384,7 +407,7 @@ def test_aggregate_field_values(as_public, as_drone, es):
384407
r = as_drone.post('/dataexplorer/search/fields/aggregate', json={'field_name': field_name, 'search_string': search_str})
385408
es.search.assert_called_with(
386409
body={'aggs': {'results': {'stats': {'field': field_name}}},
387-
'query': {'bool': {'filter': [{'term': {'permissions._id': None}}], 'must': {'match': {'field': search_str}}}},
410+
'query': {'bool': {'must': {'match': {'field': search_str}}}},
388411
'size': 0},
389412
doc_type='flywheel',
390413
index='data_explorer')

0 commit comments

Comments
 (0)