Skip to content

Commit

Permalink
make sure that the browser:view directive doesn't clobber security de…
Browse files Browse the repository at this point in the history
…clarations for attributes which are not included in allowed_attributes or allowed_interface but which already have security declarations in a base class's security info. This is needed to provide access to, e.g., restrictedTraverse on views that subclass Traversable
  • Loading branch information
davisagli committed Jul 16, 2010
1 parent b7d8e8d commit 63cbf5e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
6 changes: 6 additions & 0 deletions doc/CHANGES.rst
Expand Up @@ -11,6 +11,12 @@ http://docs.zope.org/zope2/releases/.
Bugs Fixed
++++++++++

- Fix support for non-public permission attributes in the
browser:view directive so that attributes which are not included in
allowed_interface or allowed_attributes but which have declarations from a
base class's security info don't get their security overwritten to be
private.

- LP #143755: Also catch TypeError when trying to determine an
indexable value for an object in PluginIndexes.common.UnIndex

Expand Down
2 changes: 1 addition & 1 deletion src/Products/Five/browser/metaconfigure.py
Expand Up @@ -315,7 +315,7 @@ def publishTraverse(self, request, name,
_context.action(
discriminator = ('five:protectName', newclass, attr),
callable = protectName,
args = (newclass, attr, CheckerPrivateId)
args = (newclass, attr, CheckerPrivateId, False)
)

# Protect the class
Expand Down
6 changes: 6 additions & 0 deletions src/Products/Five/browser/tests/pages.py
Expand Up @@ -17,6 +17,7 @@
"""
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from OFS.SimpleItem import SimpleItem

class SimpleView(BrowserView):
"""More docstring. Please Zope"""
Expand All @@ -40,6 +41,11 @@ class CallView(BrowserView):
def __call__(self):
return u"I was __call__()'ed"

class PermissionView(BrowserView, SimpleItem):

def __call__(self):
return u"I was __call__()'ed"

class CallTemplate(BrowserView):

__call__ = ViewPageTemplateFile('falcon.pt')
Expand Down
7 changes: 7 additions & 0 deletions src/Products/Five/browser/tests/pages.txt
Expand Up @@ -275,6 +275,13 @@ The same applies to a view registered with <browser:view /> instead of
>>> aq_parent(aq_inner(context))
<Folder at /test_folder_1_>

Make sure that methods which are not included in the allowed interface or
attributes, but which already had security declarations from a base class,
don't get those declarations overridden to be private. (The roles for
restrictedTraverse should be None, indicating it is public.)

>>> view.restrictedTraverse__roles__

High-level security
-------------------

Expand Down
2 changes: 1 addition & 1 deletion src/Products/Five/browser/tests/pages.zcml
Expand Up @@ -237,7 +237,7 @@
<browser:view
name="permission_view"
for="Products.Five.tests.testing.simplecontent.ISimpleContent"
class=".pages.CallView"
class=".pages.PermissionView"
permission="zope2.ViewManagementScreens"
/>

Expand Down
5 changes: 4 additions & 1 deletion src/Products/Five/security.py
Expand Up @@ -127,12 +127,15 @@ def _getSecurity(klass):
setattr(klass, '__security__', security)
return security

def protectName(klass, name, permission_id):
def protectName(klass, name, permission_id, override_existing_protection=True):
"""Protect the attribute 'name' on 'klass' using the given
permission"""
security = _getSecurity(klass)
# Zope 2 uses string, not unicode yet
name = str(name)
if not override_existing_protection and ('%s__roles__' % name) in dir(klass):
# There is already a declaration for this name from a base class.
return
if permission_id == CheckerPublicId or permission_id is CheckerPublic:
# Sometimes, we already get a processed permission id, which
# can mean that 'zope.Public' has been interchanged for the
Expand Down

0 comments on commit 63cbf5e

Please sign in to comment.