Commit c9496701 authored by Kevin Deldycke's avatar Kevin Deldycke

Apply Jerome's patch to modify request only if we traverse a website

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@8843 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3e4d0937
......@@ -29,19 +29,74 @@ from AccessControl import ClassSecurityInfo
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__')
# Use a request key to store access attributes and prevent infinite recursion
......@@ -118,4 +173,20 @@ class WebSite(Domain):
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)
......@@ -42,7 +42,6 @@ from Products.ERP5Type.patches import ActionProviderBase
from Products.ERP5Type.patches import CookieCrumbler
from Products.ERP5Type.patches import Localizer
from Products.ERP5Type.patches import CMFMailIn
from Products.ERP5Type.patches import HTTPRequest
# These symbols are required for backward compatibility
from Products.ERP5Type.patches.PropertyManager import ERP5PropertyManager
......
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