Multiple Mountpoint and subscriber/event

I have a Zope Installation with two Mountpoints. In every Mountpoint exists a Plonesite. I have installed an Addon in Site1 with a Subscriber for interface IUserLoggedInEvent.

<!-- Definition in zcml for the Handler when a User logged in-->
  <subscriber
    for="Products.PluggableAuthService.interfaces.events.IUserLoggedInEvent"
    handler=".subscribers.onUserLoggedInEvent" />

In my Site2 the Addon is not installed. But the Handler is triggered. Is it possible to add a Condition in the ZCML for the subscriber? How can i restricted the Trigger? Has anyone an idea?

What you register via ZCML is global. As the registration happens outside any portal context, there can be no condition depending on a portal in ZCML. Of course, you can put an appropriate condition in the handler itself, letting it do real work only in the correct context.

An alternative could be to register your subscriber not globally (via ZCML) but in the portal's "component registry" (--> <portal>.getSiteManager()). This registry manages the portal's utilities, adapters, subscriptions and stores them in the ZODB. The site manager implements zope.components.interfaces.IComponentRegistry and you can register an event handler with the registerHandler method. You would do this once (in an interactive debug session (--> bin/{instance|client1} debug)) and make the registration persistent by committing the transaction (--> transaction.commit()).

Thanks for the tip! I check the implementation an report the success.

I can't remember if it's possible to add ZCML conditions to subscribers; anyway, you can always add your own checks on your subscriber's code.

you can find some examples in collective.fingerpointing:

my solution:

from plone.browserlayer.utils import registered_layers

# Handler/Subscriber
def onUserLoggedInEvent(event):
    layers = registered_layers()
    if MyAddonBrowserLayer not in layers:
        """ nothing to do, addon is not installed in the plonesite
        """
        return
1 Like