[CMF-checkins] CVS: CMF/CMFCore - TypesTool.py:1.41
Florent Guillaume
fg@nuxeo.com
Wed, 31 Jul 2002 20:09:56 -0400
Update of /cvs-repository/CMF/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv9751
Modified Files:
TypesTool.py
Log Message:
Fixed isConstructionAllowed (actually _queryFactoryMethod) to not
complain when validating: validate() can either raise Unauthorized or
return 0 to mean unauthorized.
=== CMF/CMFCore/TypesTool.py 1.40 => 1.41 ===
raise ValueError, ('Product factory for %s was undefined' %
self.getId())
p = container.manage_addProduct[self.product]
-
m = getattr(p, self.factory, None)
if m is None:
raise ValueError, ('Product factory for %s was invalid' %
@@ -460,17 +459,26 @@
return m
raise Unauthorized, ('Cannot create %s' % self.getId())
- def _queryFactoryMethod(self, container, m=None):
+ def _queryFactoryMethod(self, container, default=None):
+ if not self.product or not self.factory:
+ return default
try:
- if self.product and self.factory:
- p = container.manage_addProduct[self.product]
- t = getattr(p, self.factory, None)
- if getSecurityManager().validate(p, p, self.factory, t):
- m = t
+ p = container.manage_addProduct[self.product]
+ m = getattr(p, self.factory, None)
+ if m is None:
+ return default
+ try:
+ # validate() can either raise Unauthorized or return 0 to
+ # mean unauthorized.
+ if getSecurityManager().validate(p, p, self.factory, m):
+ return m
+ except Unauthorized:
+ pass
+ return default
except:
LOG('Types Tool', ERROR, '_queryFactoryMethod raised an exception',
error=sys.exc_info())
- return m
+ return default
security.declarePublic('isConstructionAllowed')
def isConstructionAllowed ( self, container ):