Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
CSCMETAX-407: [ADD] Query parameter to filter datasets by field metad…
Browse files Browse the repository at this point in the history
…ata_owner_org
  • Loading branch information
Hannu Kamarainen committed May 29, 2018
1 parent 2fbcd7c commit 934f759
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/metax_api/services/catalog_record_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']})
Expand Down
9 changes: 9 additions & 0 deletions src/metax_api/tests/api/rest/base/views/datasets/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 934f759

Please sign in to comment.