Skip to content

Commit

Permalink
Merge pull request #56 from opendatazurich/fix-display-showcases
Browse files Browse the repository at this point in the history
Fix display showcases
  • Loading branch information
metaodi authored Feb 8, 2018
2 parents bf568ae + 63f4914 commit 87a7a6e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ckanext/showcase/logic/action/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,15 @@ def package_showcase_list(context, data_dict):
showcase_list = []
if showcase_id_list is not None:
for showcase_id in showcase_id_list:
showcase = toolkit.get_action('package_show')(context,
{'id': showcase_id})
showcase_list.append(showcase)
try:
showcase = toolkit.get_action('package_show')(
context,
{'id': showcase_id}
)
showcase_list.append(showcase)
except NotAuthorized:
log.debug('Not authorized to access Package with ID: '
+ str(showcase_id))
return showcase_list


Expand Down
44 changes: 44 additions & 0 deletions ckanext/showcase/tests/action/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,50 @@ def test_showcase_show_num_datasets_correct_only_count_active_datasets(self):
# the num_datasets should only include active datasets
nosetools.assert_equal(showcase_shown['num_datasets'], 2)

def test_showcase_anon_user_can_see_package_list_when_showcase_association_was_deleted(self):
'''
When a showcase is deleted, the remaining associations with formerly associated
packages or showcases can still be displayed.
'''
app = self._get_test_app()

sysadmin = factories.User(sysadmin=True)

showcase_one = factories.Dataset(type='showcase', name='showcase-one')
showcase_two = factories.Dataset(type='showcase', name='showcase-two')
package_one = factories.Dataset()
package_two = factories.Dataset()

admin_context = {'user': sysadmin['name']}

# create the associations
helpers.call_action('ckanext_showcase_package_association_create',
context=admin_context, package_id=package_one['id'],
showcase_id=showcase_one['id'])
helpers.call_action('ckanext_showcase_package_association_create',
context=admin_context, package_id=package_one['id'],
showcase_id=showcase_two['id'])
helpers.call_action('ckanext_showcase_package_association_create',
context=admin_context, package_id=package_two['id'],
showcase_id=showcase_one['id'])
helpers.call_action('ckanext_showcase_package_association_create',
context=admin_context, package_id=package_two['id'],
showcase_id=showcase_two['id'])

# delete one of the associated showcases
helpers.call_action('package_delete', context=admin_context,
id=showcase_two['id'])

# the anon user can still see the associated packages of remaining showcase
associated_packages = helpers.call_action(
'ckanext_showcase_package_list',
showcase_id=showcase_one['id'])

nosetools.assert_equal(len(associated_packages), 2)

# overview of packages can still be seen
app.get("/dataset", status=200)


class TestShowcaseList(ShowcaseFunctionalTestBase):

Expand Down

0 comments on commit 87a7a6e

Please sign in to comment.