diff --git a/changes/149.changes b/changes/149.changes new file mode 100644 index 0000000..c028f17 --- /dev/null +++ b/changes/149.changes @@ -0,0 +1 @@ +Raise `NotFound` exceptions for in-active Organizations. \ No newline at end of file diff --git a/ckanext/recombinant/logic.py b/ckanext/recombinant/logic.py index 644e6ee..40e18b3 100644 --- a/ckanext/recombinant/logic.py +++ b/ckanext/recombinant/logic.py @@ -159,6 +159,9 @@ def _action_find_dataset(context: Context, data_dict: DataDict) -> Tuple[ raise ValidationError( {'owner_org': _("Organization not found")}) + if getattr(owner_org, 'state') != 'active': + raise NotFound(_("Organization not found")) + try: geno = get_geno(dataset_type) except RecombinantException: diff --git a/ckanext/recombinant/tests/test_logic.py b/ckanext/recombinant/tests/test_logic.py new file mode 100644 index 0000000..9bf9674 --- /dev/null +++ b/ckanext/recombinant/tests/test_logic.py @@ -0,0 +1,39 @@ +import pytest + +from ckan.tests.factories import Organization, Sysadmin +from ckanext.recombinant.tests import RecombinantTestBase + +from ckanapi import LocalCKAN +from ckan.plugins.toolkit import config, ObjectNotFound +from ckanext.recombinant.tables import _get_plugin +from ckanext.recombinant.logic import _action_get_dataset + + +class TestRecombinantLogic(RecombinantTestBase): + @classmethod + def setup_method(self, method): + """Method is called at class level before EACH test methods of the class are called. + Setup any state specific to the execution of the given class methods. + """ + super(TestRecombinantLogic, self).setup_method(method) + + self.sysadmin = Sysadmin() + self.lc = LocalCKAN() + + def test_deleted_org(self): + """ + Deleted orgs should not show Recombinant. + """ + org = Organization() + _get_plugin().update_config(config) + self.lc.action.recombinant_create(dataset_type='sample', + owner_org=org['name']) + _lc, _geno, dataset = _action_get_dataset({'ignore_auth': True, + 'user': self.sysadmin['name']}, + {'dataset_type': 'sample', + 'owner_org': org['name']}) + self.lc.action.package_delete(id=dataset['id']) + self.lc.action.organization_delete(id=org['id']) + with pytest.raises(ObjectNotFound): + self.lc.action.recombinant_show(dataset_type='sample', + owner_org=org['name']) diff --git a/ckanext/recombinant/views.py b/ckanext/recombinant/views.py index 2ec90c3..2938132 100644 --- a/ckanext/recombinant/views.py +++ b/ckanext/recombinant/views.py @@ -596,7 +596,7 @@ def preview_table(resource_name: str, return h.redirect_to('user.login') org_object = Group.get(owner_org) - if not org_object: + if not org_object or getattr(org_object, 'state') != 'active': return abort(404, _('Organization not found')) if org_object.name != owner_org: return h.redirect_to(