Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/149.changes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Raise `NotFound` exceptions for in-active Organizations.
3 changes: 3 additions & 0 deletions ckanext/recombinant/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
39 changes: 39 additions & 0 deletions ckanext/recombinant/tests/test_logic.py
Original file line number Diff line number Diff line change
@@ -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'])
2 changes: 1 addition & 1 deletion ckanext/recombinant/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down