[Zope-CMF] fine grained permissions for adding objects
Jens Wolk
jewo_lists@gmx.de
Sat, 29 Jun 2002 15:50:33 +0200
Hi everybody,
Zope 2.5.1 / CMF 1.2
How do I set different permissions for the creation of two different kinds of
objects from the same python based CMF product?
I have two classes in a product, let's call them ManagerContent and
MemberContent. In the CMF site to be created, only Managers should be able to
create ManagerContent objects, but both Managers and Members should be able
to create MemberContent. ManagerContent and MemberContent objects lie in the
same folders.
The best way to get this behavior, I thought, is to create an new permission
'Add MemberContent' and to give Members this permission while Managers have
the standard 'Add portal content' and 'Add MemberContent' permission.
However, in the call to utils.ContentInit in __init.py__ for a product, I can
pass only one Permission for all classes. Therefore, I do this twice, but
this seems to confuse the portal_types tool: when I try to add a new type
under "Contents" of the portal_type tool (through the ZMI) and select
Factory-based Type information only those objects which I are passed in the
second call to utils.ContentInit are listed.
I tried to use different 'product' parameters in the fti's but this didn't
help.
Once the types are added they work just fine, so this problem isn't too
serious (could probably solved by an Install.py script). Nonetheless I would
like to know if there is a better solution.
Yours. Jens Wolk
For the sake of completeness:
import MemberContent
import ManagerContent
contentClasses_EL = (ManagerContent.ManagerContent,)
contentConstructors_EL = (ManagerContent.manageAddManagerContent,)
contentFactories_EL = (ManagerContent.factory_type_information,)
# MemberContent needs special treatment as its creation is bound to another
# permission
contentClasses = (MemberContent.MemberContent,)
contentConstructors = (MemberContent.manage_addMemberContent,)
contentFactories = (MemberContent.factory_type_information,)
import sys
this_module = sys.modules [ __name__ ]
z_bases = utils.initializeBasesPhase1 (contentClasses, this_module)
z_bases_EL = utils.initializeBasesPhase1 (contentClasses_EL, this_module)
def initialize (context):
utils.initializeBasesPhase2 (z_bases, context)
utils.ContentInit ('MyProduct',
content_types = contentClasses,
permission = MyPermissions.AddMemberContent,
extra_constructors = contentConstructors,
fti = contentFactories).initialize(context)
utils.initializeBasesPhase2 (z_bases_EL, context)
utils.ContentInit ('MyProduct',
content_types = contentClasses_EL,
permission = CMFCorePermissions.AddPortalContent,
extra_constructors = contentConstructors_EL,
fti = contentFactories_EL).initialize(context)