From caa8b8d0e3e0f2173b7ed021efb040251f3ef80e Mon Sep 17 00:00:00 2001 From: northwestwitch Date: Mon, 25 Mar 2019 21:11:23 +0100 Subject: [PATCH] adapter.cases accepts an array of collaborators or just one --- scout/adapter/mongo/case.py | 15 +++++++++------ scout/server/blueprints/cases/views.py | 10 +++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/scout/adapter/mongo/case.py b/scout/adapter/mongo/case.py index 5570c390d4..291f20daa2 100644 --- a/scout/adapter/mongo/case.py +++ b/scout/adapter/mongo/case.py @@ -19,7 +19,7 @@ class CaseHandler(object): """Part of the pymongo adapter that handles cases and institutes""" - def cases(self, owner=None, collaborator=None, query=None, skip_assigned=False, + def cases(self, owner=None, collaborators=None, query=None, skip_assigned=False, has_causatives=False, reruns=False, finished=False, research_requested=False, is_research=False, status=None, phenotype_terms=False, pinned=False, cohort=False, name_query=None, @@ -27,7 +27,7 @@ def cases(self, owner=None, collaborator=None, query=None, skip_assigned=False, """Fetches all cases from the backend. Args: - collaborator(str): If collaborator should be considered + collaborator(str or list): If collaborator(s) should be considered owner(str): Query cases for specified case owner only query(dict): If a specific query is used skip_assigned(bool) @@ -53,9 +53,12 @@ def cases(self, owner=None, collaborator=None, query=None, skip_assigned=False, LOG.debug("Fetch all cases") query = query or {} - if collaborator: - LOG.debug("Use collaborator {0}".format(collaborator)) - query['collaborators'] = collaborator + if collaborators: + LOG.debug("Use collaborators {0}".format(collaborators)) + if isinstance(collaborators, str): + query['collaborators'] = collaborators + elif isinstance(collaborators, list): + query['collaborators'] = {'$in' : collaborators} if owner: LOG.debug("Use owner {0}".format(owner)) @@ -321,7 +324,7 @@ def load_case(self, config_data, update=False): category=category, rank_threshold=case_obj.get('rank_score_threshold', 0), ) - + except (IntegrityError, ValueError, ConfigError, KeyError) as error: LOG.warning(error) diff --git a/scout/server/blueprints/cases/views.py b/scout/server/blueprints/cases/views.py index 1e9490ea83..21a19efe1f 100644 --- a/scout/server/blueprints/cases/views.py +++ b/scout/server/blueprints/cases/views.py @@ -34,7 +34,7 @@ def index(): """Display a list of all user institutes.""" institute_objs = user_institutes(store, current_user) - institutes_count = ((institute_obj, store.cases(collaborator=institute_obj['_id']).count()) + institutes_count = ((institute_obj, store.cases(collaborators=institute_obj['_id']).count()) for institute_obj in institute_objs if institute_obj) return dict(institutes=institutes_count) @@ -43,16 +43,20 @@ def index(): @templated('cases/cases.html') def cases(institute_id): """Display a list of cases for an institute.""" + query = request.args.get('query') institute_obj = institute_and_case(store, institute_id) - query = request.args.get('query') + collaborators = [] + user_institute_objs = user_institutes(store, current_user) + for user_institute in user_institute_objs: + collaborators.append(user_institute['_id']) limit = 100 if request.args.get('limit'): limit = int(request.args.get('limit')) skip_assigned = request.args.get('skip_assigned') - all_cases = store.cases(institute_id, collaborator=institute_obj['_id'], + all_cases = store.cases(institute_id, collaborators=collaborators, name_query=query, skip_assigned=skip_assigned) data = controllers.cases(store, all_cases, limit)