[ckan-dev] Extending IAuthFunctions and public access
Hendrik Bunke
bunke.hendrik at gmail.com
Wed Nov 16 08:59:09 UTC 2016
Hi Lucia,
you can use a decorator provided by plugins.toolkit: auth_allow_anonymous_access
See
http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html#ckan.plugins.interfaces.IAuthFunctions
for more details.
regards
hendrik
--On 2016-11-15 17:31, lucia.espona at wsl.ch wrote:
> Dear all
>
> I am developing an extension to restrict the access to some resources (not the full dataset) depending in a datsaset field.
> I extended IAuthFunctions by defining a custom 'resource_show' authorization function.
> The problem is the function only works when a user is registered, otherwise it denies the access automatically.
> For some resources, I would like them to be completely public (also available for non registered users, as default) but it seems impossible to define a custom function and allow public access some cases.
>
> This is the code:
> def restricted_resource_show(context, data_dict=None):
> return {'success': True }
>
> class RestrictedPlugin(plugins.SingletonPlugin):
> plugins.implements(plugins.IAuthFunctions)
>
> [...]
>
> # IAuthFunctions
> def get_auth_functions(self):
> return {'resource_show': restricted_resource_show }
> It should return always True but I get:
>
> {"
> help": "http://envidat02.wsl.ch:5000/api/3/action/help_show?name=resource_show","
> success": false,"
> error": {"
> message": "Access denied: <function restricted_resource_show at 0x7f69e3de68c0> requires an authenticated user","
> __type": "Authorization Error"}}
>
> Any ideas will be appreciated.
>
> Best,
> Lucia
>
>
> _________________________________________________________
> Dr. Lucia Espona Pernas
>
> Swiss Federal Institute for Forest, Snow and Landscape Research WSL
> Hauptgebäaude Labortrakt (HL C21)
> Zürcherstrasse 111
> 8903 Birmensdorf
> Switzerland
>
> +41 44 739 28 71 phone direct
> +41 44 739 21 11 reception
>
> www.wsl.ch
> _______________________________________________
> 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
--
Dr. Hendrik Bunke
http://www.hbxt.org
http://twitter.com/hbunke
More information about the ckan-dev
mailing list