Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare a subscriber that will be enable for only one plone site?

Tags:

plone

In a Plone instance I have two plone sites. In one of them, I have a product dedicated to it.

I want to declare a subscriber in that product for Products.PluggableAuthService.interfaces.events.IPrincipalCreatedEvent that will be fired only for this plone site.

I have tried with zcml:condition="installed my.product" but it test only if it can be imported or not, so the subscriber is also available to the other plone site.

Moving the second plone site to another instance is not an option.

Thanks.

like image 339
Jihaisse Avatar asked Sep 29 '22 03:09

Jihaisse


1 Answers

In plone you have the concept of Browserlayer.

Since you can install a browserlayer thru generic setup, you can activate/deactivate it per plone site.

I would implement a condition in the subscriber, which checks for a installed browserlayer.

Note: Browserlayers are applied on the REQUEST with a before traverse hook.

Example function for a subscriber:

from my.package.interfaces import IMyPackageLayer


def my_function(obj, event):
    if IMyPackageLayer.providedBy(obj.REQUEST):
        #  Do something
    else:
        #  Do nothing

You can register/create a browserlayer in your package the following way:

  1. Create a interfaces.py

    from zope.interface import Interface
    
    class IMyPackageLayer(Interface):
        """A layer specific to my package
        """
    
  2. Create a browserlayer.xml in your package profile

    <layers>
        <layer name="my.package"
           interface="my.package.interfaces.IMyPackageLayer" />
    </layers>
    

The browserlayer example is taken from the plone.browserlayer readme

like image 170
Mathias Avatar answered Oct 13 '22 01:10

Mathias