Commit 2f06c766 authored by Jérome Perrin's avatar Jérome Perrin

website: cleanup old before traverse hooks that may exist on website

parent b91d40f6
...@@ -203,15 +203,18 @@ class WebSite(WebSection): ...@@ -203,15 +203,18 @@ class WebSite(WebSection):
security.declarePrivate( 'manage_afterClone' ) security.declarePrivate( 'manage_afterClone' )
def manage_afterClone(self, item): def manage_afterClone(self, item):
self._cleanupBeforeTraverseHooks()
WebSection.manage_afterClone(self, item)
def _cleanupBeforeTraverseHooks(self):
# unregister all before traversal hooks that do not belong to us. # unregister all before traversal hooks that do not belong to us.
my_handle = self.meta_type + '/' + self.getId() my_handle = self.meta_type + '/' + self.getId()
handle_to_unregister_list = [] handle_to_unregister_list = []
for priority, handle in self.__before_traverse__.keys(): for (priority, handle), hook in self.__before_traverse__.items():
if handle != my_handle: if isinstance(hook, WebSiteTraversalHook) and handle != my_handle:
handle_to_unregister_list.append(handle) handle_to_unregister_list.append(handle)
for handle in handle_to_unregister_list: for handle in handle_to_unregister_list:
BeforeTraverse.unregisterBeforeTraverse(self, handle) BeforeTraverse.unregisterBeforeTraverse(self, handle)
WebSection.manage_afterClone(self, item)
security.declareProtected(Permissions.AccessContentsInformation, 'getPermanentURLList') security.declareProtected(Permissions.AccessContentsInformation, 'getPermanentURLList')
def getPermanentURLList(self, document): def getPermanentURLList(self, document):
...@@ -278,8 +281,12 @@ class WebSite(WebSection): ...@@ -278,8 +281,12 @@ class WebSite(WebSection):
return [] return []
def _edit(self, **kw): def _edit(self, **kw):
# migrate beforeTraverse hook if missing if self.getPortalType() == 'Web Site':
if getattr(self, '__before_traverse__', None) is None and self.getPortalType() == 'Web Site': if getattr(self, '__before_traverse__', None) is None:
handle = self.meta_type + '/' + self.getId() # migrate beforeTraverse hook if missing
BeforeTraverse.registerBeforeTraverse(self, WebSiteTraversalHook(), handle) handle = self.meta_type + '/' + self.getId()
BeforeTraverse.registerBeforeTraverse(self, WebSiteTraversalHook(), handle)
else:
# cleanup beforeTraverse hooks that may exist after this document was cloned.
self._cleanupBeforeTraverseHooks()
super(WebSite, self)._edit(**kw) super(WebSite, self)._edit(**kw)
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