Skip to content

Commit

Permalink
[#4827] More robust auth functions for resource_view_show
Browse files Browse the repository at this point in the history
Fixes #4827.

Right now they rely on resource objects being present in the context.
You should be able to call the auth function with the same parameters
 as the action (ie just the resource view id). This is not an issue
 in core but it can be problematic when extending auth from extensions.
  • Loading branch information
amercader committed Jun 3, 2019
1 parent e2e33e4 commit 6d03ad6
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions ckan/logic/auth/get.py
Expand Up @@ -163,11 +163,29 @@ def resource_show(context, data_dict):


def resource_view_show(context, data_dict):
return authz.is_authorized('resource_show', context, data_dict)

model = context['model']
resource = context.get('resource')
if not resource:
resource_view = model.ResourceView.get(data_dict['id'])
if not resource_view:
raise logic.NotFound(_('Resource view not found, cannot check auth.'))
resource = model.Resource.get(resource_view.resource_id)

return authz.is_authorized('resource_show', context, {'id': resource.id})


def resource_view_list(context, data_dict):
return authz.is_authorized('resource_show', context, data_dict)

model = context['model']
resource = context.get('resource')
if not resource:
resource_view = model.ResourceView.get(data_dict['id'])
if not resource_view:
raise logic.NotFound(_('Resource view not found, cannot check auth.'))
resource = model.Resource.get(resource_view.resource_id)

return authz.is_authorized('resource_show', context, {'id': resource['id']})


def revision_show(context, data_dict):
Expand Down

0 comments on commit 6d03ad6

Please sign in to comment.