Skip to content

Commit

Permalink
Merge pull request #441 from vrk-kpa/LIKA-606_hide-xroad-removed-subs…
Browse files Browse the repository at this point in the history
…ystems

LIKA-606: Fix subsystem search result count, hide removed subsystems
  • Loading branch information
bzar authored Mar 11, 2024
2 parents 8be9ab4 + 09f7dd8 commit 65daa4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ckanext/ckanext-apicatalog/ckanext/apicatalog/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ def after_search(self, search_results, search_params):
result['num_resources'] = len(allowed_resources)

search_results['results'] = results
search_results['count'] = len(results)
return search_results

# After package_show, filter out the resources which the user doesn't have access to
Expand All @@ -931,6 +932,9 @@ def after_show(self, context, data_dict):
if context.get('ignore_auth') or (context.get('auth_user_obj') and context.get('auth_user_obj').sysadmin):
return data_dict

if data_dict.get('xroad_removed') is True:
raise toolkit.ObjectNotFound

user_name = context.get('user')

org_id = data_dict.get('organization', {}).get('id', '')
Expand Down
15 changes: 15 additions & 0 deletions ckanext/ckanext-apicatalog/ckanext/apicatalog/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,18 @@ def test_old_business_ids_output_with_list(self):
organization_with_python_list = Organization(old_business_ids=['1', '2'])

assert organization_with_python_list['old_business_ids'] == ['1', '2']

def test_user_should_not_see_subsystems_removed_from_xroad(self, app):
org = factories.Organization()
subsystem = factories.Dataset(
owner_org=org["id"],
xroad_removed=True
)

with app.flask_app.test_request_context():
app.flask_app.preprocess_request()
with pytest.raises(ObjectNotFound):
get_action('package_show')({}, {"id": subsystem['id']})

search = get_action('package_search')({}, {})
assert all(result['id'] != subsystem['id'] for result in search['results'])

0 comments on commit 65daa4e

Please sign in to comment.