[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/publisher/browser/
Fixed http://collector.zope.org/Zope3-dev/234
Jim Fulton
jim at zope.com
Tue Aug 10 19:23:06 EDT 2004
Log message for revision 26987:
Fixed http://collector.zope.org/Zope3-dev/234
This turned out to be a failure of the global browser menu service to
properly handle menu items defined for classes.
Changed:
U Zope3/trunk/src/zope/app/publisher/browser/globalbrowsermenuservice.py
U Zope3/trunk/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py
-=-
Modified: Zope3/trunk/src/zope/app/publisher/browser/globalbrowsermenuservice.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/globalbrowsermenuservice.py 2004-08-10 23:19:04 UTC (rev 26986)
+++ Zope3/trunk/src/zope/app/publisher/browser/globalbrowsermenuservice.py 2004-08-10 23:23:06 UTC (rev 26987)
@@ -46,14 +46,7 @@
def __init__(self):
self._reg = {}
- def register(self, interface, object):
- if interface is not None and not IInterface.providedBy(interface):
- if isinstance(interface, (type, types.ClassType)):
- interface = implementedBy(interface)
- else:
- raise TypeError(
- "The interface argument must be an interface (or None) or a class.")
-
+ def register(self, interface, object):
self._reg[interface] = object
def get(self, interface, default=None):
@@ -61,7 +54,7 @@
def getAll(self, interface_spec):
result = []
- for interface in interface_spec.flattened():
+ for interface in interface_spec.__sro__:
object = self._reg.get(interface)
if object is not None:
result.append(object)
@@ -264,6 +257,15 @@
if permission == 'zope.Public':
permission = CheckerPublic
+
+ if interface is not None and not IInterface.providedBy(interface):
+ if isinstance(interface, (type, types.ClassType)):
+ interface = implementedBy(interface)
+ else:
+ raise TypeError(
+ "The interface argument must be an interface (or None) "
+ "or a class.")
+
data = registry.get(interface) or []
data.append(
MenuItem(action, title, description, filter, permission, extra)
Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py 2004-08-10 23:19:04 UTC (rev 26986)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py 2004-08-10 23:23:06 UTC (rev 26987)
@@ -98,6 +98,41 @@
menu = r.getMenu('test_id', TestObject(), TestRequest())
self.assertEqual(list(menu), [d(5), d(6), d(3), d(2), d(1)])
+ def test_w_class(self):
+ r = self.__reg()
+ r.menu('test_id', 'test menu')
+ r.menuItem('test_id', Interface, 'a1', 't1', 'd1')
+ r.menuItem('test_id', I1, 'a2', 't2', 'd2')
+ r.menuItem('test_id', I11, 'a3', 't3', 'd3', 'context')
+ r.menuItem('test_id', I11, 'a4', 't4', 'd4', 'not:context')
+ r.menuItem('test_id', I111, 'a5', 't5', 'd5')
+ r.menuItem('test_id', I111, 'a6', 't6', 'd6')
+ r.menuItem('test_id', I111, 'f7', 't7', 'd7')
+ r.menuItem('test_id', I111, 'u8', 't8', 'd8')
+ r.menuItem('test_id', I12, 'a9', 't9', 'd9')
+ r.menuItem('test_id', TestObject, 'a0', 't0', 'd0')
+
+ menu = r.getMenu('test_id', TestObject(), TestRequest())
+ self.assertEqual(list(menu), [d(0), d(5), d(6), d(3), d(2), d(1)])
+
+ def test_w_class_that_does_not_implement(self):
+ r = self.__reg()
+ r.menu('test_id', 'test menu')
+
+ class C:
+ pass
+
+ # We provide a permission so C doesn't have to implement
+ # IBrowserPublisher. We use CheckerPublic so we don't have to set
+ # up any other security machinery.
+
+ from zope.security.checker import CheckerPublic
+ r.menuItem('test_id', C, 'a0', 't0', 'd0', permission=CheckerPublic)
+ r.menuItem('test_id', C, 'a10', 't10', 'd10', permission=CheckerPublic)
+
+ menu = r.getMenu('test_id', C(), TestRequest())
+ self.assertEqual(list(menu), [d(0), d(10)])
+
def test_w_permission(self):
ztapi.provideUtility(IPermission, Permission('p', 'P'), 'p')
More information about the Zope3-Checkins
mailing list