Skip to content

Commit

Permalink
[#2457] Return all organizations the user belongs to
Browse files Browse the repository at this point in the history
Regardless of capacity, not just the ones where the user is an
administrator.
  • Loading branch information
amercader committed Aug 30, 2016
1 parent 0f3a55f commit cf979ce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Expand Up @@ -9,8 +9,13 @@ Changelog

v2.6.0 TBA
=================

API changes and deprecations:
* Replace `c.__version__` with new helper `h.ckan_version()` (#3103)
* Replace ``c.__version__`` with new helper ``h.ckan_version()`` (#3103)
* ``organization_list_for_user`` (and the ``h.organizations_available()``
helper) now return all organizations a user belongs to regardless of
capacity (Admin, Editor or Member), not just the ones where she is an
administrator (#2457)

Major:
* Private datasets are now included in the default dataset search results (#3191)
Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/helpers.py
Expand Up @@ -1640,7 +1640,7 @@ def groups_available(am_member=False):


@core_helper
def organizations_available(permission='admin'):
def organizations_available(permission='read'):
'''Return a list of organizations that the current user has the specified
permission for.
'''
Expand Down
6 changes: 3 additions & 3 deletions ckan/logic/action/get.py
Expand Up @@ -622,7 +622,7 @@ def organization_list_for_user(context, data_dict):
:param permission: the permission the user has against the
returned organizations, for example ``"read"`` or ``"create_dataset"``
(optional, default: ``"admin"``)
(optional, default: ``"read"``)
:type permission: string
:returns: list of organizations that the user has the given permission for
Expand All @@ -643,15 +643,15 @@ def organization_list_for_user(context, data_dict):
sysadmin = authz.is_sysadmin(user)

orgs_q = model.Session.query(model.Group) \
.filter(model.Group.is_organization == True) \
.filter(model.Group.is_organization is True) \
.filter(model.Group.state == 'active')

if sysadmin:
orgs_and_capacities = [(org, 'admin') for org in orgs_q.all()]
else:
# for non-Sysadmins check they have the required permission

permission = data_dict.get('permission', 'admin')
permission = data_dict.get('permission', 'read')

roles = authz.get_roles_with_permission(permission)

Expand Down

0 comments on commit cf979ce

Please sign in to comment.