[ckan-dev] Restrict visible groups in _group_or_organization_list()

Knud Möller knud at datalysator.com
Wed Apr 18 09:23:45 UTC 2018


Hi Adrià,

thanks, I wasn’t aware that I can override actions like that (seems obvious
now…). That’s a much better solution, I prefer not having to touch CKAN
core. Works brilliantly, too! :) This approach will also work for a couple
of other use cases I have.

Just a small remark: instead of user = context['user’], I had to use user =
context.get('auth_user_obj', None), since context[‘user’] is just a string.

There is another problem now, however:

As I said, I have implemented IAuthFunctions group_show() to disallow
showing of specific groups. This means that the call to
group_list.append(logic.get_action(action)(context, data_dict)) will raise
an unhandled NotAuthorized Exception, which leads to a server error. So, I
still have to touch CKAN core to wrap this line in a try/except:

            try:
                group_list.append(logic.get_action(action)(context,
data_dict))
            except logic.NotAuthorized:
                pass

That looks like a useful PR to me. Let me know I should submit one.

Cheers,
Knud


On 17 April 2018 at 14:53:14, Adrià Mercader (adria.mercader at okfn.org)
wrote:

Hi Knud,

On 17 April 2018 at 13:05, Knud Möller <knud at datalysator.com> wrote:
>
>
> So, I have two questions:
>
> - Is this a “good” way of implementing my use case?
>

It is a bit inefficient because you call `group_show` on all groups
returned. You can probably just override the default `group_list` using
`IActions` with something like this:

def my_group_list(context, data_dict_):
    group_list = core_group_list(context, data_dict_)
    user = context['user']
    if not user or not user.sysadmin:
        # Pop the restricted groups from the list
    return group_list





> - Is this of general interest? In that case, I’m happy to make a PR.
>

It sounds like a specific use case so it's probably better off in an
extension like you are implementing it

Hope this helps,

Adrià



>
> Cheers,
> Knud
>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> https://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>
>
_______________________________________________
ckan-dev mailing list
ckan-dev at lists.okfn.org
https://lists.okfn.org/mailman/listinfo/ckan-dev
Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20180418/7f9cc371/attachment-0003.html>


More information about the ckan-dev mailing list