Skip to content

Commit 8982ede

Browse files
committed
feat(dev): deleted orgs;
- Raise NotFound for non-active orgs.
1 parent aacc7ff commit 8982ede

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pytest
2+
3+
from ckan.tests.factories import Organization
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.lc = LocalCKAN()
21+
22+
def test_deleted_org(self):
23+
"""
24+
Deleted orgs should not show Recombinant.
25+
"""
26+
org = Organization()
27+
_get_plugin().update_config(config)
28+
self.lc.action.recombinant_create(dataset_type='sample',
29+
owner_org=org['name'])
30+
_lc, _geno, dataset = _action_get_dataset({'ignore_auth': True},
31+
{'dataset_type': 'sample',
32+
'owner_org': org['name']})
33+
self.lc.action.package_delete(id=dataset['id'])
34+
self.lc.action.organization_delete(id=org['id'])
35+
with pytest.raises(ObjectNotFound):
36+
self.lc.action.recombinant_show(dataset_type='sample',
37+
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)