[Zope-dev] Defining permissions in inherited classes
Itai Tavor
itavor@bigpond.net.au
Thu, 16 Dec 1999 15:35:52 +1100
> > 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!
Thanks... and 3 cheers for the power of inside information!
Sadly, it doesn't work. I added default__class_init__ to all my
products and the inherited permissions still don't show up. I
inserted 'print self.meta_Type' into default__class_init__, and it
looks like it gets called for all my classes even when I do not
explicitly include that call, when I do include it
default__class_init__ gets called twice for every class.
Can you think of anything that would prevent the inherited
permissions from being included?
--
Itai Tavor -- "Je sautille, donc je suis." --
itavor@vic.bigpond.net.au -- - Kermit the Frog --
-- "What he needs now is understanding... and a confederate victory" --
-- Dr. Jacobi, Twin Peaks --