nti.webhooks.subscribers¶
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
orsubscribers_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.
Important
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 forObjectCreatedEvent
, but does forObjectAddedEvent
. See configuration for more.Caution
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.
- Queries for all active subscriptions in the
-
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.Parameters: - principal –
The principal being removed. It should still be located (having a proper
__parent__
) when this subscriber is invoked; this is the default forzope.container
objects that usezope.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 toIPrincipal
, and if that fails, it is used as-is. The final object must have theid
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) inExhaustiveWebhookSubscriptionManagers
.- principal –