Skip to content

Commit

Permalink
[2939] fix organization availible helper so can take permission as ar…
Browse files Browse the repository at this point in the history
…gument. This was in order to give an org editor the ability to create a dataset
  • Loading branch information
kindly committed Dec 13, 2012
1 parent a7c5934 commit 463d184
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 3 additions & 2 deletions ckan/lib/helpers.py
Expand Up @@ -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):
Expand Down
10 changes: 8 additions & 2 deletions ckan/logic/action/get.py
Expand Up @@ -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
'''
Expand All @@ -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 []
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/package/snippets/package_basic_fields.html
Expand Up @@ -39,7 +39,7 @@
<input type="hidden" name="groups__0__id" value="{{ data.group_id }}" />
{% 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 %}
<div class="control-group">
<label for="field-organizations" class="control-label">{{ _('Organization') }}</label>
Expand Down

0 comments on commit 463d184

Please sign in to comment.