Hi there,

I have some issues with using declareProtected() outside product
classes (deriving from ObjectManager or SimpleItem). An external method
example that _does_ work, taken from the ZDG:

import Globals
import Acquisition
from AccessControl import ClassSecurityInfo

class Book(Acquisition.Implicit):
  def __init__(self, title):
  # Create a SecurityInfo for this class
  security = ClassSecurityInfo()
  def getTitle(self):
    return self._title
# The actual external method
def GetBooks(self):
  books.append(Book('King Lear'))
  books.append(Book('Romeo and Juliet'))
  books.append(Book('The Tempest'))
  return books

Now replace the line "security.declarePublic('getTitle')" with something like
"security.declareProtected('View', 'getTitle')", and suddenly nobody is
allowed to call getTitle() on a Book object anymore.

This doesn't only occur in external method code, but also in product code,
which is where I ran into it. Take for instance this class:

class TOCEntry(Acquisition.Implicit):
    security = ClassSecurityInfo()
    def __init__(self, id):
        self.id = id

    security.declareProtected('View', 'render')
    def render(self):
        """Render entry.
        return self.id


'render()' can now never be called from a DTML method or a ZPT template,
while using 'security.declarePublic('render') does work.

One gets errors like this:

Error Type: Undefined

Error Value: You are not allowed to access render in this context not found in 
'entry/render', at line 8, column 3

which doesn't look very grammatical either. :)

I haven't been able to figure out what causes the difference; classes
that are initialized with Zope don't seem to have this problem, but this little
class does. I've tried inheriting from Persistent or SimpleItem.Item but
that doesn't seem to make any difference..

So what's going on? Am I missing something? If so, where is this documented?


Zope-Dev maillist  -  [EMAIL PROTECTED]
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope )

Reply via email to