Hash: SHA1

Tres Seaver wrote:
> Wichert Akkerman wrote:
>> Previously Tres Seaver wrote:
>>> Hash: SHA1
>>> Wichert Akkerman wrote:
>>>> I have a use case where I need to put additional restrictions on object 
>>>> creation, in particular I need to restrict the maximum depth of items 
>>>> inside of a container of a specific type. The ideal place to put such a 
>>>> restriction seems to be the isConstructionAllowed method on the FTI. 
>>>> Currently this method is not very extensible, which leads to complicated 
>>>> code in various FTI types.
>>>> I am considering to add an extension point here, something like this:
>>>> class ITypeConstructionFilter(Interface):
>>>>      def __init__(fti, container):
>>>>          """Adapt on the FTI of the object being created and the target 
>>>> container"""
>>>>      def allowed():
>>>>          """Check if construction is allowed."""
>>>> current checks such as the workflow check that was added in CMF 2.2, or 
>>>> the type constraint logic Plone has in ATContentTypes could be moved to 
>>>> such an adapter. The standard isConstructionAllowed method could then 
>>>> query all registered adapters to check if construction should be possible.
>>>> Does this sound sensible?
>>> I'm not sure about querying all adapters:  I think it would be clearer
>>> to query the one adapter whose name corresponds to the type name of the
>>> FTI (the "query all" case leads to tricky / emergent behavior).
>> Querying a single adapter makes it very hard to use this as an extension
>> point. Being able to have multiple independent validation-hooks is the
>> whole point of my suggestion, and being able to only use a single
>> adapter would make that impossible.
> I don't *want* multiple third-party products to register this adapter:
> I think it belongs to the integrator to set the policy for the site.
> "Reusable policy" is an oxymoron.

Ugh, following up to myself:

If you really *want* to allow every adapter registered anywhere for that
interface to play, you can still get that under my scenario, by
registering the default (unnamed) adapter to do your dance.  That
implementation would be::

  class PromiscuousConstructionFilter:

      def __init__(self, (obj, container):
          self.obj = obj
          self.container = container

      def __call__(self):

          for name, filter in getAdapters((self, container),
              if name: # skip default
                  if not filter.allowed():
                      return False

The policy choice would then be whether to actually register the
"promiscuous" adapter (which would *not* be anabled by default in CMF).

Your alternative makes anybody who does not want the feature responsible
for suppressing the unwanted filter adapter registrations everywhere,
which is unacceptable.

- --
Tres Seaver          +1 540-429-0999          tsea...@palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


Zope-CMF maillist  -  Zope-CMF@lists.zope.org

See https://bugs.launchpad.net/zope-cmf/ for bug reports and feature requests

Reply via email to