Skip to content

Commit 25ad96b

Browse files
authored
Merge pull request #149 from open-data/feature/handle-deleted-orgs
Handle Organization Stateliness
2 parents aacc7ff + 695dc54 commit 25ad96b

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

changes/149.changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Raise `NotFound` exceptions for in-active Organizations.

ckanext/recombinant/logic.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ def _action_find_dataset(context: Context, data_dict: DataDict) -> Tuple[
159159
raise ValidationError(
160160
{'owner_org': _("Organization not found")})
161161

162+
if getattr(owner_org, 'state') != 'active':
163+
raise NotFound(_("Organization not found"))
164+
162165
try:
163166
geno = get_geno(dataset_type)
164167
except RecombinantException:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import pytest
2+
3+
from ckan.tests.factories import Organization, Sysadmin
4+
from ckanext.recombinant.tests import RecombinantTestBase
5+
6+
from ckanapi import LocalCKAN
7+
from ckan.plugins.toolkit import config, ObjectNotFound
8+
from ckanext.recombinant.tables import _get_plugin
9+
from ckanext.recombinant.logic import _action_get_dataset
10+
11+
12+
class TestRecombinantLogic(RecombinantTestBase):
13+
@classmethod
14+
def setup_method(self, method):
15+
"""Method is called at class level before EACH test methods of the class are called.
16+
Setup any state specific to the execution of the given class methods.
17+
"""
18+
super(TestRecombinantLogic, self).setup_method(method)
19+
20+
self.sysadmin = Sysadmin()
21+
self.lc = LocalCKAN()
22+
23+
def test_deleted_org(self):
24+
"""
25+
Deleted orgs should not show Recombinant.
26+
"""
27+
org = Organization()
28+
_get_plugin().update_config(config)
29+
self.lc.action.recombinant_create(dataset_type='sample',
30+
owner_org=org['name'])
31+
_lc, _geno, dataset = _action_get_dataset({'ignore_auth': True,
32+
'user': self.sysadmin['name']},
33+
{'dataset_type': 'sample',
34+
'owner_org': org['name']})
35+
self.lc.action.package_delete(id=dataset['id'])
36+
self.lc.action.organization_delete(id=org['id'])
37+
with pytest.raises(ObjectNotFound):
38+
self.lc.action.recombinant_show(dataset_type='sample',
39+
owner_org=org['name'])

ckanext/recombinant/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ def preview_table(resource_name: str,
596596
return h.redirect_to('user.login')
597597

598598
org_object = Group.get(owner_org)
599-
if not org_object:
599+
if not org_object or getattr(org_object, 'state') != 'active':
600600
return abort(404, _('Organization not found'))
601601
if org_object.name != owner_org:
602602
return h.redirect_to(

0 commit comments

Comments
 (0)