Commit bd89a732 authored by Jérome Perrin's avatar Jérome Perrin

website: do not accumulate before traversal hook when cloning web sites

parent 6263cc2b
...@@ -201,6 +201,18 @@ class WebSite(WebSection): ...@@ -201,6 +201,18 @@ class WebSite(WebSection):
BeforeTraverse.registerBeforeTraverse(item, WebSiteTraversalHook(), handle) BeforeTraverse.registerBeforeTraverse(item, WebSiteTraversalHook(), handle)
WebSection.manage_afterAdd(self, item, container) WebSection.manage_afterAdd(self, item, container)
security.declarePrivate( 'manage_afterClone' )
def manage_afterClone(self, item):
# unregister all before traversal hooks that do not belong to us.
my_handle = self.meta_type + '/' + self.getId()
handle_to_unregister_list = []
for priority, handle in self.__before_traverse__.keys():
if handle != my_handle:
handle_to_unregister_list.append(handle)
for handle in handle_to_unregister_list:
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):
""" """
......
...@@ -169,6 +169,33 @@ class TestERP5Web(ERP5TypeTestCase): ...@@ -169,6 +169,33 @@ class TestERP5Web(ERP5TypeTestCase):
except: except:
self.fail('Cataloging of the Web Site failed.') self.fail('Cataloging of the Web Site failed.')
def test_WebSiteTraversalHook_on_newContent(self):
"""a WebSiteTraversalHook is added on websites automatically.
"""
web_site = self.portal.web_site_module.newContent(
portal_type='Web Site',
)
self.assertEquals(1, len(web_site.__before_traverse__))
def test_WebSiteTraversalHook_on_clone(self):
"""a WebSiteTraversalHook is correctly updated after cloning a website.
"""
web_site = self.portal.web_site_module.newContent(
portal_type='Web Site',
)
cloned_web_site = web_site.Base_createCloneDocument(batch_mode=True)
self.assertEquals(1, len(cloned_web_site.__before_traverse__))
def test_WebSiteTraversalHook_on_change_id(self):
"""a WebSiteTraversalHook is correctly updated after changing website id.
"""
web_site = self.portal.web_site_module.newContent(
portal_type='Web Site',
)
self.tic()
web_site.setId("new_id")
self.assertEquals(1, len(web_site.__before_traverse__))
def test_02_EditSimpleWebPage(self): def test_02_EditSimpleWebPage(self):
""" """
Simple Case of creating a web page. Simple Case of creating a web page.
......
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