[Zope-dev] declarative security scope question
Joseph Wayne Norton
norton@alum.mit.edu
Thu, 26 Jul 2001 22:59:22 +0900
I'm trying to setup a template for defining declarative security
assertions for a set of classes. Here is an example method that is
not working as I expected:
def MyInitializeClass(klass,priviledge):
klass.security.declareProtected(priviledge, 'listMessages')
Globals.InitializeClass(klass)
Python is complaining about the 'security' attribute not existing. It
appears that the attribute 'security' for a class is not accessible
even though it is assigned within the class. Does anyone have an
experience with this?
regards,
- joe n.
p.s. Here's the full code sample:
-------------------------------------------------------------------
from AccessControl import ClassSecurityInfo
import Globals
class MailboxBase(BaseObject):
"""A mailbox base class."""
# Create a SecurityInfo for this class
security = ClassSecurityInfo()
security.declareProtected('View Mailbox', 'listMessages')
def listMessages(self):
"""Return a sequence of message objects."""
return self._messages[:]
security.setPermissionDefault('View Mailbox', ('Manager', 'Mailbox Owner'))
def MyInitializeClass(klass,priviledge):
klass.security.declareProtected(priviledge, 'listMessages')
Globals.InitializeClass(klass)
# call this to initialize framework classes, which
# does the right thing with the security assertions.
Globals.InitializeClass(MailboxBase)
class MyMailbox(MailboxBase):
"""A mailbox subclass, where we want the security for
listMessages to be public instead of protected (as
defined in the base class)."""
# Create a SecurityInfo for this class
security = ClassSecurityInfo()
security.declarePublic('listMessages')
# call this to initialize framework classes, which
# does the right thing with the security assertions.
MyInitializeClass(MyMailbox, 'View Mailbox')