[Zope-CMF] Visibility/creatability of types from TypeInfos
Florent Guillaume
fg@nuxeo.com
Wed, 12 Jun 2002 19:01:57 +0000 (UTC)
David (Hamish) Harvey <david.harvey@bristol.ac.uk> wrote:
> I then want to *change* the permissions on an *existing* method in
> TypesTool to use this new permission (I originally just edited the source
> of TypesTool, and it all worked fine):
>
> from Products.CMFCore.TypesTool import TypesTool
> security = TypesTool.security
> # constructInstance is public in CMFCore.TypesTool
> security.declareProtected( CMFCorePermissions.CreateInstances
> , 'constructInstance' )
I'd do:
security = ClassSecurityInfo()
security.declareProtected(CMFCorePermissions.CreateInstances,
'constructInstance')
security.apply(TypesTool)
security.apply takes your changes into account. It's called
automatically by InitializeClass. Note that the "security" object is not
intrinsically linked to the class.
Also I think InitializeClass (in fact default__class_init__) removes the
security attribute of the class when it's done with it so I'm not sure
doing "security = TypesTool.security" would work.
Another more hackish way to achieve it would be to do:
from AccessControl.PermissionRole import PermissionRole
TypesTool.constructInstance__roles__ = PermissionRole(CMFCorePermissions.CreateInstances)
which is, in the end, what security.apply does. Not very
"new style" though.
Florent
--
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com