pythonckan

How to remove registering and make only sysadmin add users in ckan?


I am trying to do some changes in my ckan plugin but I cant seem to get a hold of the signed in user sysadmin role, I am trying to do it with Jinja2 using:

{% if user and if user_roles == "admin" %}

And this works, but I am trying to make this only an option for sysadmins, not organization level admins, so naturally I am doing:

{% if user_roles == "sysadmin" %}

but it throws an error, apparently sysadmin is not in user_roles I guess. How can I get a hold of the sysadmin role ? Or is this even the right way to do it ?

Thank you.


Solution

  • You can use the check_access to see if the logged-in user is a sysadmin as:

      {% set user_is_sysadmin = h.check_access('sysadmin') %}
    

    Also, you will need to disable creating users from API by adding the

    ckan.auth.create_user_via_api = False
    

    To the configuration file. Read more here