[Zope-dev] Defining permissions in inherited classes
Brian Lloyd
Brian@digicool.com
Wed, 15 Dec 1999 09:37:26 -0500
> I've been stuck with this problems for weeks... I posted an earlier
> question bug got no replies, so I thought I'd try again.
>
> I have a product that is used as a mix-in class in several other
> products. This product adds a management interface screen and I want
> to define permissions to control that screen in this class. So, I do:
>
> class Publisher(RoleManager):
>
> __ac_permissions__ = (
> ('Change publishing', ('manage_publish'))
> )
>
> manage_publish = HTMLFile('publish', globals())
>
> In the product that uses this class:
>
> class Something(Folder, Publisher.Publisher):
>
> __ac_permissions__ = (
> ('View management screens', ('manage_tabs',
> 'manage_main', ....))
> .....
> )
>
> manage_options = (
> {'label':'Edit', 'action':'manage_main'},
> {'label':'Publish', 'action':'manage_publish'}
> )
>
> Now, I think this should work... that's how it's done in
> AccessRole.Role.RoleManager - it defines __ac_permissions__ that get
> added to the classes that inherit from it. But it doesn't work for
> me... the permissions defined in Publisher don't appear anywhere. Any
> idea why, or what I'm doing wrong?
There is a little bit of non-obvious initialization work that
needs to be done to gather the permission information from all
the subclasses of an object. This is done by calling the method
default__class_init__ (found in the Globals module), passing the
class that represents the creatable object. The default__class_init__
method does the correct permission initialization for you. *Note
that you must do this for the class of each creatable object your
product defines. In your case, you would add to the bottom of your
module:
import Globals
# pass the class of the creatable object
# that we are defining so that permissions
# are gathered up automatically from the
# base classes
Globals.default__class_init__(Something)
Hope this helps!
Brian Lloyd brian@digicool.com
Software Engineer 540.371.6909
Digital Creations http://www.digicool.com