From 934f7596ef31282e86fe2b292b398188f7bd90cb Mon Sep 17 00:00:00 2001 From: Hannu Kamarainen Date: Tue, 29 May 2018 09:29:57 +0300 Subject: [PATCH] CSCMETAX-407: [ADD] Query parameter to filter datasets by field metadata_owner_org --- src/metax_api/services/catalog_record_service.py | 3 +++ src/metax_api/tests/api/rest/base/views/datasets/read.py | 9 +++++++++ swagger/swagger.yaml | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/src/metax_api/services/catalog_record_service.py b/src/metax_api/services/catalog_record_service.py index f4e8e5e6..4de8beb6 100644 --- a/src/metax_api/services/catalog_record_service.py +++ b/src/metax_api/services/catalog_record_service.py @@ -72,6 +72,9 @@ def get_queryset_search_params(cls, request): if request.query_params.get('editor', False): queryset_search_params['editor__contains'] = { 'identifier': request.query_params['editor'] } + if request.query_params.get('metadata_owner_org', False): + queryset_search_params['metadata_owner_org'] = request.query_params['metadata_owner_org'] + if request.query_params.get('contract_org_identifier', False): if request.user.username not in ('metax', 'tpas'): raise Http403({ 'detail': ['query parameter pas_filter is restricted']}) diff --git a/src/metax_api/tests/api/rest/base/views/datasets/read.py b/src/metax_api/tests/api/rest/base/views/datasets/read.py index 72023638..f5bc1943 100644 --- a/src/metax_api/tests/api/rest/base/views/datasets/read.py +++ b/src/metax_api/tests/api/rest/base/views/datasets/read.py @@ -384,6 +384,15 @@ def test_read_catalog_record_search_by_editor(self): response = self.client.get('/rest/datasets') self.assertNotEqual(response.data['count'], qvain_records_count, 'looks like filtering had no effect') + def test_read_catalog_record_search_by_metadata_owner_org(self): + metadata_owner_org = 'org_id' + for cr in CatalogRecord.objects.filter(pk__in=[1, 2, 3]): + cr.metadata_owner_org = metadata_owner_org + cr.force_save() + response = self.client.get('/rest/datasets?metadata_owner_org=%s' % metadata_owner_org) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(len(response.data['results']), 3) + def test_filter_by_contract_org_identifier(self): """ Test filtering by contract_org_identifier, which matches using iregex diff --git a/swagger/swagger.yaml b/swagger/swagger.yaml index bdfd2972..e28ac841 100644 --- a/swagger/swagger.yaml +++ b/swagger/swagger.yaml @@ -711,6 +711,11 @@ paths: description: TPAS state (field preservation_state). multiple states using OR-logic are queriable in the same request, e.g. state=5,6. see valid values from http://iow.csc.fi/model/mrd/CatalogRecord/ field preservation_state required: false type: string + - name: metadata_owner_org + in: query + description: Filter by dataset field metadata_owner_org + required: false + type: string - name: contract_org_identifier in: query description: Filter by dataset contract.contract_json.organization.organization_identifier. Restricted to permitted users.