Commit dff1fda4 authored by Georgios Dagkakis's avatar Georgios Dagkakis

TypeMixIn: Introduce for methods to be shared between Base and ERP5Site

Also, this commit renames some incosistent with convention
methods (e.g. getRelativeUrl to getRelativeURL),
giving also aliases for backwards compatibility
parent 91ea5604
...@@ -19,6 +19,7 @@ import threading ...@@ -19,6 +19,7 @@ import threading
from weakref import ref as weakref from weakref import ref as weakref
from OFS.Application import Application, AppInitializer from OFS.Application import Application, AppInitializer
from Products.ERP5Type import Globals from Products.ERP5Type import Globals
from Products.ERP5Type.TypeMixIn import TypeMixIn
from Products.ERP5Type.Globals import package_home from Products.ERP5Type.Globals import package_home
from Products.SiteErrorLog.SiteErrorLog import manage_addErrorLog from Products.SiteErrorLog.SiteErrorLog import manage_addErrorLog
...@@ -225,7 +226,7 @@ class _site(threading.local): ...@@ -225,7 +226,7 @@ class _site(threading.local):
getSite, setSite = _site() getSite, setSite = _site()
class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin): class ERP5Site(TypeMixIn, FolderMixIn, CMFSite, CacheCookieMixin):
""" """
The *only* function this class should have is to help in the setup The *only* function this class should have is to help in the setup
of a new ERP5. It should not assist in the functionality at all. of a new ERP5. It should not assist in the functionality at all.
...@@ -582,24 +583,6 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin): ...@@ -582,24 +583,6 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
def setLastId(self, id): def setLastId(self, id):
self.last_id = id self.last_id = id
security.declareProtected(Permissions.AccessContentsInformation, 'getUrl')
def getUrl(self, REQUEST=None):
"""
Returns the absolute path of an object
"""
return join(self.getPhysicalPath(),'/')
security.declareProtected(Permissions.AccessContentsInformation, 'getRelativeUrl')
def getRelativeUrl(self):
"""
Returns the url of an object relative to the portal site.
"""
return self.getPortalObject().portal_url.getRelativeUrl(self)
# Old name - for compatibility
security.declareProtected(Permissions.AccessContentsInformation, 'getPath')
getPath = getUrl
security.declareProtected(Permissions.AccessContentsInformation, 'opaqueValues') security.declareProtected(Permissions.AccessContentsInformation, 'opaqueValues')
def opaqueValues(self, *args, **kw): def opaqueValues(self, *args, **kw):
# XXX nonsense of inheriting from CMFSite that calls __before_traversal__ # XXX nonsense of inheriting from CMFSite that calls __before_traversal__
......
...@@ -34,6 +34,7 @@ import types ...@@ -34,6 +34,7 @@ import types
import thread, threading import thread, threading
from Products.ERP5Type.Globals import InitializeClass, DTMLFile from Products.ERP5Type.Globals import InitializeClass, DTMLFile
from Products.ERP5Type.TypeMixIn import TypeMixIn
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from AccessControl.Permission import pname, Permission from AccessControl.Permission import pname, Permission
from AccessControl.PermissionRole import rolesForPermissionOn from AccessControl.PermissionRole import rolesForPermissionOn
...@@ -670,7 +671,8 @@ def initializePortalTypeDynamicWorkflowMethods(ptype_klass, portal_workflow): ...@@ -670,7 +671,8 @@ def initializePortalTypeDynamicWorkflowMethods(ptype_klass, portal_workflow):
else: else:
method.registerTransitionAlways(portal_type, wf_id, tr_id) method.registerTransitionAlways(portal_type, wf_id, tr_id)
class Base( CopyContainer, class Base( TypeMixIn,
CopyContainer,
PortalContent, PortalContent,
ActiveObject, ActiveObject,
OFS.History.Historical, OFS.History.Historical,
...@@ -1694,32 +1696,6 @@ class Base( CopyContainer, ...@@ -1694,32 +1696,6 @@ class Base( CopyContainer,
objectlist.append(objectlist[-1][element]) objectlist.append(objectlist[-1][element])
return '/' + '/'.join(object.getCompactTitle() for object in objectlist[1:]) return '/' + '/'.join(object.getCompactTitle() for object in objectlist[1:])
security.declareProtected(Permissions.AccessContentsInformation, 'getUrl')
def getUrl(self, REQUEST=None):
"""
Returns the absolute path of an object
"""
return '/'.join(self.getPhysicalPath())
# Old name - for compatibility
security.declareProtected(Permissions.AccessContentsInformation, 'getPath')
getPath = getUrl
security.declareProtected(Permissions.AccessContentsInformation, 'getRelativeUrl')
def getRelativeUrl(self):
"""
Returns the url of an object relative to the portal site.
"""
return self.getPortalObject().portal_url.getRelativeUrl(self)
security.declareProtected(Permissions.AccessContentsInformation,
'getAbsoluteUrl')
def getAbsoluteUrl(self):
"""
Returns the absolute url of an object.
"""
return self.absolute_url()
security.declarePublic('getPortalObject') security.declarePublic('getPortalObject')
def getPortalObject(self): def getPortalObject(self):
""" """
......
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions
class TypeMixIn():
"""
A mixin class for methods needed to be shared by all ERP5 objects,
including Base and ERP5Site
(not ERP5Site is not Base for bootstraping reasons)
"""
# Declarative security - in ERP5 we use AccessContentsInformation to
# define the right of accessing content properties as opposed
# to view which is the right to view the object with a form
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
security.declareProtected(
Permissions.AccessContentsInformation, 'getRelativeURL'
)
def getRelativeURL(self):
"""
Returns the url of an object relative to the portal site.
"""
return self.getPortalObject().portal_url.getRelativeUrl(self)
# Old name - for compatibility
security.declareProtected(
Permissions.AccessContentsInformation, 'getRelativeUrl'
)
getRelativeUrl = getRelativeURL
security.declareProtected(
Permissions.AccessContentsInformation, 'getAbsoluteURL'
)
def getAbsoluteURL(self):
"""
Returns the absolute url of an object.
"""
return self.absolute_url()
# Old name - for compatibility
security.declareProtected(
Permissions.AccessContentsInformation, 'getAbsoluteUrl'
)
getAbsoluteUrl = getAbsoluteURL
security.declareProtected(Permissions.AccessContentsInformation, 'getURL')
def getURL(self, REQUEST=None):
"""
Returns the absolute path of an object
"""
return '/'.join(self.getPhysicalPath())
# Old names - for compatibility
security.declareProtected(Permissions.AccessContentsInformation, 'getUrl')
getUrl = getURL
security.declareProtected(Permissions.AccessContentsInformation, 'getPath')
getPath = getURL
...@@ -3244,6 +3244,46 @@ return [ ...@@ -3244,6 +3244,46 @@ return [
# but this did not affect the other role # but this did not affect the other role
self.assertTrue(hasRole(role2)) self.assertTrue(hasRole(role2))
def test_type_mixin(self):
'''
test methods that are shared between Base and ERP5Type
'''
# First for ERP5Type (portal)
self.assertEqual(
self.portal.getAbsoluteURL(),
self.portal.absolute_url()
)
self.assertEqual(
self.portal.getAbsoluteURL(),
self.portal.getAbsoluteUrl()
)
self.assertEqual(self.portal.getRelativeURL(), '')
self.assertEqual(
self.portal.getRelativeURL(),
self.portal.getRelativeUrl()
)
self.assertEqual(self.portal.getURL(), '/' + self.portal.getId())
self.assertEqual(self.portal.getURL(), self.portal.getUrl())
self.assertEqual(self.portal.getURL(), self.portal.getPath())
# Now for Base, creating a Person as test object.
# Maybe something more abstract could be used?
base_object = self.portal.person_module.newContent(portal_type='Person')
base_object_id = base_object.getId()
self.assertEqual(base_object.getAbsoluteURL(), base_object.absolute_url())
self.assertEqual(base_object.getAbsoluteURL(), base_object.getAbsoluteUrl())
self.assertEqual(
base_object.getRelativeURL(),
'person_module/' + base_object_id
)
self.assertEqual(base_object.getRelativeURL(), base_object.getRelativeUrl())
self.assertEqual(
base_object.getURL(),
'/' + self.portal.getId() + '/person_module/' + base_object_id
)
self.assertEqual(base_object.getURL(), base_object.getUrl())
self.assertEqual(base_object.getURL(), base_object.getPath())
class TestAccessControl(ERP5TypeTestCase): class TestAccessControl(ERP5TypeTestCase):
# Isolate test in a dedicaced class in order not to break other tests # Isolate test in a dedicaced class in order not to break other tests
# when this one fails. # when this one fails.
......
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