[Erp5-report] r8842 - /erp5/trunk/products/ERP5/Document/WebSite.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Jul 27 18:27:34 CEST 2006
Author: kevin
Date: Thu Jul 27 18:27:30 2006
New Revision: 8842
URL: http://svn.erp5.org?rev=8842&view=rev
Log:
Apply Jerome's patch to modify request only if we traverse a website
Modified:
erp5/trunk/products/ERP5/Document/WebSite.py
Modified: erp5/trunk/products/ERP5/Document/WebSite.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/WebSite.py?rev=8842&r1=8841&r2=8842&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/WebSite.py (original)
+++ erp5/trunk/products/ERP5/Document/WebSite.py Thu Jul 27 18:27:30 2006
@@ -29,18 +29,73 @@
from AccessControl import getSecurityManager
from Acquisition import aq_base
from Products.CMFCore.utils import getToolByName
-from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface, Cache
+from Products.ERP5Type import Permissions, PropertySheet,\
+ Constraint, Interface, Cache
from Products.ERP5.Document.Domain import Domain
from Acquisition import ImplicitAcquisitionWrapper, aq_base, aq_inner
from Products.ERP5Type.Base import TempBase
from Globals import get_request
-from Products.CMFCore.utils import UniqueObject, _checkPermission, _getAuthenticatedUser
+from Products.CMFCore.utils import UniqueObject, _checkPermission,\
+ _getAuthenticatedUser
from AccessControl.SecurityManagement import getSecurityManager
from AccessControl.User import emergency_user
-from AccessControl.SecurityManagement import newSecurityManager, setSecurityManager
+from AccessControl.SecurityManagement import newSecurityManager,\
+ setSecurityManager
+from ZPublisher import BeforeTraverse
from Products.ERP5Type.patches.HTTPRequest import website_key
from zLOG import LOG
+
+website_key = 'web_site_value'
+class WebSiteTraversalHook:
+ """This is used by WebSite to rewrite URLs in such way
+ that once a user gets into a Web Site object, all
+ documents referenced by the web site are accessed
+ through the web site rather than directly.
+ """
+
+ def _physicalPathToVirtualPath(self, path):
+ """
+ Remove the path to the VirtualRoot from a physical path
+ and add the path to the WebSite is any
+ """
+ if type(path) is type(''):
+ path = path.split( '/')
+
+ website_path = self.request.get(website_key, None)
+ if website_path:
+ website_path = tuple(website_path) # Make sure all path are tuples
+ path = tuple(path) # Make sure all path are tuples
+ # Search for the common part index
+ # XXX more testing should be added to check
+ # if the URL is the kind of URL which is a Web Site
+ # XXX more support required for ignore_layout
+ common_index = 0
+ i = 0
+ path_len = len(path)
+ for name in website_path:
+ if i >= path_len: break
+ if path[i] == name:
+ common_index = i
+ i += 1
+ # Insert the web site path after the common part of the path
+ if path_len > common_index + 1:
+ path = website_path + path[common_index + 1:]
+
+ rpp = self.request.other.get('VirtualRootPhysicalPath', ('',))
+ i = 0
+ for name in rpp[:len(path)]:
+ if path[i] == name:
+ i = i + 1
+ else:
+ break
+ return path[i:]
+
+ def __call__(self, container, request):
+ """Each time we are traversed, we patch the request instance with our
+ rewritted version of physicalPathToVirtualPath"""
+ self.request = request
+ request.physicalPathToVirtualPath = self._physicalPathToVirtualPath
Domain_getattr = Domain.inheritedAttribute('__getattr__')
@@ -118,4 +173,20 @@
raise
return document
+ security.declarePrivate( 'manage_beforeDelete' )
+ def manage_beforeDelete(self, item, container):
+ if item is self:
+ handle = self.meta_type + '/' + self.getId()
+ BeforeTraverse.unregisterBeforeTraverse(container, handle)
+ Domain.manage_beforeDelete(self, item, container)
+ security.declarePrivate( 'manage_afterAdd' )
+ def manage_afterAdd(self, item, container):
+ if item is self:
+ handle = self.meta_type + '/' + self.getId()
+ container = container.this()
+ BeforeTraverse.registerBeforeTraverse(container,
+ WebSiteTraversalHook(),
+ handle)
+ Domain.manage_afterAdd(self, item, container)
+
More information about the Erp5-report
mailing list