Since subscribers and adapters are not allowing us to define a browser layer in the registration, like browser views do, we have to find another way, to make sure our subscribe only effects the Plone side where we enable the addon.
Let's define the code for the event subscriber.
from ../interfaces import IAddonBrowserLayer
def handler(event):
""" Event handler
"""
if not IAddonBrowserLayer.providedBy(event.object.REQUEST):
return
# handle your event here
Here we exist the subscriber when ever the current request, does not have the needed Browser Layer attached.
Now let's register this function for the Plone PrincipalCreatedEvent event, in our configure.zcml.
<subscriber
for="* Products.PluggableAuthService.interfaces.events.IPrincipalCreatedEvent"
handler=".user_added.handler"
/>