From 8982ede6bb2e0235618837b684a2e26f8e53888a Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Fri, 12 Sep 2025 15:32:00 +0000 Subject: [PATCH 1/2] feat(dev): deleted orgs; - Raise NotFound for non-active orgs. --- ckanext/recombinant/logic.py | 3 ++ ckanext/recombinant/tests/test_logic.py | 37 +++++++++++++++++++++++++ ckanext/recombinant/views.py | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 ckanext/recombinant/tests/test_logic.py 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..a4dc20d --- /dev/null +++ b/ckanext/recombinant/tests/test_logic.py @@ -0,0 +1,37 @@ +import pytest + +from ckan.tests.factories import Organization +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.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}, + {'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( From 695dc543411f9268146f0c1ec6a045be597ed8ad Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Fri, 12 Sep 2025 15:38:12 +0000 Subject: [PATCH 2/2] feat(misc): changelog; - Added change log file. --- changes/149.changes | 1 + ckanext/recombinant/tests/test_logic.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changes/149.changes 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/tests/test_logic.py b/ckanext/recombinant/tests/test_logic.py index a4dc20d..9bf9674 100644 --- a/ckanext/recombinant/tests/test_logic.py +++ b/ckanext/recombinant/tests/test_logic.py @@ -1,6 +1,6 @@ import pytest -from ckan.tests.factories import Organization +from ckan.tests.factories import Organization, Sysadmin from ckanext.recombinant.tests import RecombinantTestBase from ckanapi import LocalCKAN @@ -17,6 +17,7 @@ def setup_method(self, method): """ super(TestRecombinantLogic, self).setup_method(method) + self.sysadmin = Sysadmin() self.lc = LocalCKAN() def test_deleted_org(self): @@ -27,7 +28,8 @@ def test_deleted_org(self): _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}, + _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'])