Commit 3cefffd9 authored by Leonardo Rochael Almeida's avatar Leonardo Rochael Almeida Committed by Sebastien Robin

Override __getitem__, not _getOb, in contribution tool

_getOb() is too low level and is no longer called by Zope during traversal (which uses
__getitem__()), if the object is not an explicity subobject.

__getitem__() is the right interface for a folder to pretend to have objects it
doesn't actually have.
parent 3cc8f88f
...@@ -265,7 +265,7 @@ class ContributionTool(BaseTool): ...@@ -265,7 +265,7 @@ class ContributionTool(BaseTool):
input_parameter_dict=input_parameter_dict input_parameter_dict=input_parameter_dict
) )
object_id = document.getId() object_id = document.getId()
document = self._getOb(object_id) # Call _getOb to purge cache document = self[object_id] # Call __getitem__ to purge cache
kw['filename'] = filename # Override filename property kw['filename'] = filename # Override filename property
# Then edit the document contents (so that upload can happen) # Then edit the document contents (so that upload can happen)
...@@ -427,11 +427,7 @@ class ContributionTool(BaseTool): ...@@ -427,11 +427,7 @@ class ContributionTool(BaseTool):
# Return document to newContent method # Return document to newContent method
return document return document
def _getOb(self, id, default=_marker): def __getitem__(self, id):
"""
Check for volatile temp object info first
and try to find it
"""
# Use the document cache if possible and return result immediately # Use the document cache if possible and return result immediately
# this is only useful for webdav # this is only useful for webdav
volatile_cache = getattr(self, '_v_document_cache', None) volatile_cache = getattr(self, '_v_document_cache', None)
...@@ -453,14 +449,10 @@ class ContributionTool(BaseTool): ...@@ -453,14 +449,10 @@ class ContributionTool(BaseTool):
# when # when
# o = folder._getOb(id) # o = folder._getOb(id)
# was called in DocumentConstructor # was called in DocumentConstructor
if default is _marker: if id in self:
result = BaseTool._getOb(self, id) # NOTE: used 'id in self' instead of catching KeyError because
else: # __getitem__ can return NullResource
result = BaseTool._getOb(self, id, default=default) return super(ContributionTool, self).__getitem__(id)
if result is not None:
# if result is None, ignore it at this stage
# we can be more lucky with portal_catalog
return result
# Return an object listed by listDAVObjects # Return an object listed by listDAVObjects
# ids are concatenation of uid + '-' + standard file name of documents # ids are concatenation of uid + '-' + standard file name of documents
...@@ -469,10 +461,8 @@ class ContributionTool(BaseTool): ...@@ -469,10 +461,8 @@ class ContributionTool(BaseTool):
object = self.getPortalObject().portal_catalog.unrestrictedGetResultValue(uid=uid) object = self.getPortalObject().portal_catalog.unrestrictedGetResultValue(uid=uid)
if object is not None: if object is not None:
return object.getObject() # Make sure this does not break security. XXX return object.getObject() # Make sure this does not break security. XXX
if default is not _marker: # Overriden method can return a NullResource or raise a KeyError:
return default return super(ContributionTool, self).__getitem__(id)
# Raise an AttributeError the same way as in OFS.ObjectManager._getOb
raise AttributeError, id
def listDAVObjects(self): def listDAVObjects(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment