[ckan-dev] Function called on resource update

Stefan Oderbolz stefan.oderbolz at liip.ch
Thu Apr 27 15:21:49 UTC 2017


Hi Lucia,

this seems like a perfect case for the IDomainObjectModification interface (
http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html#ckan.plugins.interfaces.IDomainObjectModification
).

You can implement that in your extension and every time a resource is
updated, the notify() method is called. E.g. the datastore part in CKAN
core uses that:
https://github.com/ckan/ckan/blob/af2f061fdd08219d5070415be118d6063d38341f/ckanext/datastore/plugin.py#L130
You then have to check that the entity is acutally a resource with
something like isinstance(entity, model.Resource)
and that the operation is "changed" (operation ==
model.domain_object.DomainObjectOperation.changed).

Once that is clear, then you'll have to check if the allowed_users field
has changed (I guess the value should be in entity.allowed_users).

If this seems like overkill, then maybe using the IResourceController
interface with the after_update method is the better choice (
http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html#ckan.plugins.interfaces.IResourceController.after_update
)

Hope this helps.

- Stefan

On Thu, Apr 27, 2017 at 3:33 PM, <lucia.espona at wsl.ch> wrote:

> Dear all
>
> I would like to know how to define a function that will be called when a
> resource is updated. The function will need to know which information
> (field, new value, old value) was changed.
> What would be the best way to do this? I am using scheming and was
> thinking of using a validator.
>
> Here is the context: in my ckanext-restricted extension, I would like that
> the user is notified by mail when he/she is granted access to access a
> restricted resource. This happens when the owner updates a field called
> "allowed_users" in the resource metadata. It is important that only the new
> added users get a mail.
>
> Any help will be appreciated :)
>
> Best regards,
> 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 <+41%2044%20739%2028%2071> phone direct
> +41 44 739 21 11 <+41%2044%20739%2021%2011> 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
>
>


-- 
Liip AG  // Limmatstrasse 183 //  CH-8005 Zürich
Tel +41 43 500 39 80 // GnuPG 0x7B588C67 // www.liip.ch
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20170427/28303f95/attachment-0003.html>


More information about the ckan-dev mailing list