Event subscribers.

class nti.webhooks.subscribers.ExhaustiveWebhookSubscriptionManagers(context)[source]

Bases: object

Finds all subscription managers that are located in the same root as the context.

This is done using an exhaustive, expensive process of adapting the root to zope.container.interfaces.ISublocations and inspecting each of them for subscription managers.

This is not registered by default.

nti.webhooks.subscribers.dispatch_webhook_event(data, event)[source]

A subscriber installed to dispatch events to webhook subscriptions.

This is usually registered in the global registry by loading subscribers.zcml or subscribers_promiscuous.zcml, but the event and data for which it is registered may be easily customized. See Configuration for more information.

This function:

  • Queries for all active subscriptions in the IWebhookSubscriptionManager instances in the current site hierarchy;
  • And queries for all active subscriptions in the IWebhookSubscriptionManager instances in the context of the data, which may be separate.
  • Determines if any of those actually apply to the data, and if so, joins the transaction to prepare for sending them.


Checking whether a subscription is applicable depends on the security policy in use. Most security policies inspect the object’s lineage or location (walking up the __parent__ tree) so it’s important to use this subscriber only for events where that part of the object is intact. For example, it does not usually apply for ObjectCreatedEvent, but does for ObjectAddedEvent. See configuration for more.


This function assumes the global, thread-local transaction manager. If any objects belong to ZODB connections that are using a different transaction manager, this won’t work.

nti.webhooks.subscribers.remove_subscriptions_for_principal(principal, event)[source]

Subscriber to find and remove all subscriptions for the principal when it is removed.

This is an adapter for (IPrincipal, IObjectRemovedEvent) by default, but that may not be the correct event in every system. Register it for the appropriate events in your system.

  • principal

    The principal being removed. It should still be located (having a proper __parent__) when this subscriber is invoked; this is the default for zope.container objects that use zope.container.contained.uncontained() in their __delitem__ method.

    This can be any type of object. It is first adapted to nti.webhooks.interfaces.IWebhookPrincipal; if that fails, it is adapted to IPrincipal, and if that fails, it is used as-is. The final object must have the id attribute.

  • event – This is not used by this subscriber.

This subscriber removes all subscriptions owned by the principal found in subscription managers:

  • in the current site; and
  • in sites up the lineage of the original principal and adapted object (if different).

If the principal may have subscriptions in more places, provide an implementation of nti.webhooks.interfaces.IWebhookSubscriptionManagers for the original principal object. One (exhaustive) implementation is provided (but not registered) in ExhaustiveWebhookSubscriptionManagers.