From 463d18420b736dba135ac1f1dd5b26d52aefcc5d Mon Sep 17 00:00:00 2001 From: kindly Date: Thu, 13 Dec 2012 01:32:35 +0000 Subject: [PATCH] [2939] fix organization availible helper so can take permission as argument. This was in order to give an org editor the ability to create a dataset --- ckan/lib/helpers.py | 5 +++-- ckan/logic/action/get.py | 10 ++++++++-- .../package/snippets/package_basic_fields.html | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index 34251e31eb0..910cc9abdb2 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -1185,12 +1185,13 @@ def groups_available(): return logic.get_action('group_list_authz')(context, data_dict) -def organizations_available(): +def organizations_available(permission='edit_group'): ''' return a list of available organizations ''' import ckan.logic as logic context = {'model': model, 'session': model.Session, 'user': c.user} - return logic.get_action('organization_list_for_user')(context, {}) + data_dict = {'permission': permission} + return logic.get_action('organization_list_for_user')(context, data_dict) def user_in_org_or_group(group_id): diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py index 43cc130e36a..8c4de91d91d 100644 --- a/ckan/logic/action/get.py +++ b/ckan/logic/action/get.py @@ -445,7 +445,11 @@ def group_list_authz(context, data_dict): def organization_list_for_user(context, data_dict): '''Return the list of organizations that the user is a member of. - :returns: the names of organizations that the user is authorized to edit + :param permission: the permission the user has against the returned organizations + (optional, default: ``edit_group``) + :type permission: string + + :returns: the names of organizations the user is authorized to do specific permission :rtype: list of strings ''' @@ -454,7 +458,9 @@ def organization_list_for_user(context, data_dict): _check_access('organization_list_for_user',context, data_dict) - roles = ckan.new_authz.get_roles_with_permission('edit_group') + permission = data_dict.get('permission', 'edit_group') + + roles = ckan.new_authz.get_roles_with_permission(permission) if not roles: return [] diff --git a/ckan/templates/package/snippets/package_basic_fields.html b/ckan/templates/package/snippets/package_basic_fields.html index cc06d87e7d5..ae106206b25 100644 --- a/ckan/templates/package/snippets/package_basic_fields.html +++ b/ckan/templates/package/snippets/package_basic_fields.html @@ -39,7 +39,7 @@ {% endif %} {% if h.check_access('sysadmin') or data.get('state', 'draft').startswith('draft') or data.get('state', 'none') == 'none' %} - {% set organizations_available = h.organizations_available() %} + {% set organizations_available = h.organizations_available('create_dataset') %} {% if organizations_available %}