Skip to content

Commit efb24c6

Browse files
committed
added acquisition and analysis level filtering
1 parent 95316ae commit efb24c6

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

api/download.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def summary(self):
344344
'acquisitions': {'session': {'$in': session_ids}},
345345
'analyses': {'parent.id': {'$in': parent_ids}}
346346
}
347-
if level == 'sessions':
347+
elif level == 'sessions':
348348

349349
# Grab acquisitions and their ids
350350
acquisitions = config.db.acquisitions.find({'session': req['_id']}, {'_id': 1})
@@ -361,6 +361,15 @@ def summary(self):
361361
'analyses': {'parent.id': {'$in': parent_ids}}
362362
}
363363
containers = containers[1:]
364+
elif level == 'acquisitions':
365+
366+
cont_query['acquisitions'] = {'_id': req['_id']}
367+
containers = ['acquisitions']
368+
elif level == 'analyses':
369+
cont_query['analyses'] = {'_id': req['_id']}
370+
containers = containers[-1:]
371+
else:
372+
self.abort(400, "{} not a recognized level".format(level))
364373

365374
res = {}
366375
for cont_name in containers:
@@ -382,7 +391,7 @@ def summary(self):
382391
try:
383392
result = config.db.command('aggregate', cont_name, pipeline=pipeline)
384393
except Exception as e: # pylint: disable=broad-except
385-
return e
394+
self.abort(500, str(e))
386395

387396
if result.get("ok"):
388397
for doc in result.get("result"):

test/integration_tests/python/test_download.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,3 +434,12 @@ def test_summary(data_builder, as_admin, file_form):
434434
assert r.ok
435435
assert len(r.json()) == 1
436436
assert r.json().get("csv", {}).get("count",0) == 2
437+
438+
r = as_admin.post('/download/summary', json={"level":"acquisitions", "_id":acquisition})
439+
assert r.ok
440+
assert len(r.json()) == 1
441+
assert r.json().get("csv", {}).get("count",0) == 1
442+
443+
r = as_admin.post('/download/summary', json={"level":"groups", "_id":missing_object_id})
444+
assert r.status_code == 400
445+

0 commit comments

Comments
 (0)