Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ckanext/datavic_odp_theme/logic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def auth_functions():
package_activity_list=get.vic_package_activity_list,
organization_activity_list=get.vic_organization_activity_list,
user_activity_list=get.vic_user_activity_list,
organization_member_create=get.organization_member_create,
)


Expand Down
14 changes: 13 additions & 1 deletion ckanext/datavic_odp_theme/logic/auth/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,16 @@ def vic_organization_activity_list(


def vic_datatables_view_prioritize(context, data_dict):
return {"success": False}
return {"success": False}

@tk.chained_auth_function
def organization_member_create(next_auth, context, data_dict):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a tip with auth functions in CKAN.
If the auth check is only to allow sysadmin access, all the auth function needs to do is return {'success': False}.
This is because when the CKAN helper check_access is used, it includes logic that skips the auth check for sysadmin users in ckan.authz.is_authorized (which ckan.plugins.toolkit.check_access uses).
As long as the auth function does not use @auth_sysadmins_check docstring in ckan/logic/init.py)
This means only non-sysadmin users would reach this code and we can just return false with a optional message.

user_obj = context.get('auth_user_obj')

if not user_obj or not user_obj.sysadmin:
return {
'success': False,
'msg': 'Only sysadmins can manage organization members'
}

return next_auth(context, data_dict)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% ckan_extends %}

{% block page_primary_action %}
{% if h.check_access('organization_update', {'id': organization.id}) %}
{% if g.userobj.sysadmin %}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is absolutely fine because it is inside the above if check_access, but be aware that g.userobj is '' for anonymous users.
Just a FYI, another way to check sysadmin user access is h.check_access('sysadmin').
Both work fine and are just a preference.

{% link_for _('Add Member'), named_route=group_type+'.member_new', id=group_dict.id, class_='btn btn-primary', icon='plus-square' %}
{% endif %}
{% link_for _('CSV'), named_route=group_type+'.member_dump', id=group_dict.id, class_='btn btn-primary', icon='download' %}
{% endif %}
{% endblock %}