Commit fdea9695 authored by Julien Muchembled's avatar Julien Muchembled

Do not use deprecated CMFCore.utils._getViewFor anymore

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/portal_types@29392 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f90d9d1c
...@@ -36,7 +36,6 @@ from Acquisition import aq_base ...@@ -36,7 +36,6 @@ from Acquisition import aq_base
from DateTime import DateTime from DateTime import DateTime
from Products.ERP5Type.Message import Message from Products.ERP5Type.Message import Message
from Products.ERP5Type.DateUtils import addToDate from Products.ERP5Type.DateUtils import addToDate
from Products.CMFCore.PortalContent import _getViewFor
from Products.ERP5Security.ERP5UserManager import SUPER_USER from Products.ERP5Security.ERP5UserManager import SUPER_USER
from AccessControl.SecurityManagement import getSecurityManager, \ from AccessControl.SecurityManagement import getSecurityManager, \
setSecurityManager, newSecurityManager setSecurityManager, newSecurityManager
...@@ -418,12 +417,7 @@ class Alarm(XMLObject, PeriodicityMixin): ...@@ -418,12 +417,7 @@ class Alarm(XMLObject, PeriodicityMixin):
process = self.getLastActiveProcess().getRelativeUrl() process = self.getLastActiveProcess().getRelativeUrl()
elif not isinstance(process, basestring): elif not isinstance(process, basestring):
process = process.getRelativeUrl() process = process.getRelativeUrl()
list_action = _getViewFor(self, view='report') return self._renderDefaultView('report', process=process, reset=reset)
if getattr(aq_base(list_action), 'isDocTemp', 0):
return apply(list_action, (self, self.REQUEST),
process=process, reset=reset)
else:
return list_action(process=process, reset=reset)
security.declareProtected(Permissions.ManagePortal, 'solve') security.declareProtected(Permissions.ManagePortal, 'solve')
def solve(self): def solve(self):
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
from Globals import get_request from Globals import get_request
from Products.Formulator.TALESField import TALESMethod from Products.Formulator.TALESField import TALESMethod
from Products.CMFCore.utils import _getViewFor
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.ERP5Type.Message import translateString from Products.ERP5Type.Message import translateString
...@@ -44,8 +43,8 @@ def getSearchDialog(self, REQUEST=None): ...@@ -44,8 +43,8 @@ def getSearchDialog(self, REQUEST=None):
category_tool = getToolByName(portal, 'portal_categories') category_tool = getToolByName(portal, 'portal_categories')
types_tool = getToolByName(portal, 'portal_types') types_tool = getToolByName(portal, 'portal_types')
workflow_tool = getToolByName(portal, 'portal_workflow') workflow_tool = getToolByName(portal, 'portal_workflow')
default_view = _getViewFor(self) default_view = self.getTypeInfo().getDefaultViewFor(self)
listbox = default_view.listbox listbox = default_view.listbox
temp_form = ERP5Form('Folder_viewSearchDialog', 'Search').__of__(self) temp_form = ERP5Form('Folder_viewSearchDialog', 'Search').__of__(self)
......
...@@ -45,7 +45,7 @@ from OFS.PropertyManager import PropertyManager ...@@ -45,7 +45,7 @@ from OFS.PropertyManager import PropertyManager
from ZopePatch import ERP5PropertyManager from ZopePatch import ERP5PropertyManager
from Products.CMFCore.PortalContent import PortalContent, _getViewFor from Products.CMFCore.PortalContent import PortalContent
from Products.CMFCore.Expression import Expression from Products.CMFCore.Expression import Expression
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.CMFCore.WorkflowCore import ObjectDeleted, ObjectMoved from Products.CMFCore.WorkflowCore import ObjectDeleted, ObjectMoved
...@@ -2597,22 +2597,32 @@ class Base( CopyContainer, ...@@ -2597,22 +2597,32 @@ class Base( CopyContainer,
except (ValueError, TypeError): except (ValueError, TypeError):
return None return None
def _renderDefaultView(self, view, **kw):
ti = self.getTypeInfo()
if ti is None:
raise NotFound('Cannot find default %s for %r' % (view, self.getPath()))
method = ti.getDefaultViewFor(self, view)
if getattr(aq_base(method), 'isDocTemp', 0):
return method(self, self.REQUEST, self.REQUEST['RESPONSE'], **kw)
else:
return method(**kw)
security.declareProtected(Permissions.View, 'view')
def view(self):
"""Returns the default view even if index_html is overridden"""
return self._renderDefaultView('view')
# Default views - the default security in CMFCore # Default views - the default security in CMFCore
# is View - however, security was not defined on # is View - however, security was not defined on
# __call__ - to be consistent, between view and # __call__ - to be consistent, between view and
# __call__ we have to define permission here to View # __call__ we have to define permission here to View
security.declareProtected(Permissions.View, '__call__') security.declareProtected(Permissions.View, '__call__')
__call__ = view
security.declareProtected(Permissions.View, 'list') security.declareProtected(Permissions.View, 'list')
def list(self, reset=0): def list(self, reset=0):
""" """Returns the default list even if folder_contents is overridden"""
Returns the default list even if folder_contents is overridden. return self._renderDefaultView('list', reset=reset)
"""
list_action = _getViewFor(self, view='list')
if getattr(aq_base(list_action), 'isDocTemp', 0):
return apply(list_action, (self, self.REQUEST),reset=reset)
else:
return list_action(reset=reset)
# Proxy methods for security reasons # Proxy methods for security reasons
security.declareProtected(Permissions.AccessContentsInformation, 'getOwnerInfo') security.declareProtected(Permissions.AccessContentsInformation, 'getOwnerInfo')
......
...@@ -486,6 +486,33 @@ class ERP5TypeInformation(XMLObject, ...@@ -486,6 +486,33 @@ class ERP5TypeInformation(XMLObject,
search_source_list += self.getTypeBaseCategoryList(()) search_source_list += self.getTypeBaseCategoryList(())
return ' '.join(filter(None, search_source_list)) return ' '.join(filter(None, search_source_list))
security.declarePrivate('getDefaultViewFor')
def getDefaultViewFor(self, ob, view='view'):
ec = createExpressionContext(ob)
best_action = (), None
for action in self.getFilteredActionListFor(ob):
if action.getReference() == view:
if action.test(ec):
break
else:
# In case that "view" (or "list") action is not present or not allowed,
# find something that's allowed (of the same category, if possible).
index = (action.getActionType().endswith('_' + view),
-action.getFloatIndex())
if best_action[0] < index and action.test(ec):
best_action = index, action
else:
action = best_action[1]
if action is None:
raise AccessControl_Unauthorized(
'No accessible views available for %r' % ob.getPath())
target = action.getAction()(ec).strip().split(ec.vars['object_url'])[-1]
if target.startswith('/'):
target = target[1:]
__traceback_info__ = self.getId(), target
return ob.restrictedTraverse(target)
security.declarePrivate('getFilteredActionListFor') security.declarePrivate('getFilteredActionListFor')
def getFilteredActionListFor(self, ob=None): def getFilteredActionListFor(self, ob=None):
"""Return all actions applicable to the object""" """Return all actions applicable to the object"""
......
...@@ -44,7 +44,6 @@ from Products.ERP5Type.patches import CookieCrumbler ...@@ -44,7 +44,6 @@ from Products.ERP5Type.patches import CookieCrumbler
from Products.ERP5Type.patches import i18n from Products.ERP5Type.patches import i18n
from Products.ERP5Type.patches import Localizer from Products.ERP5Type.patches import Localizer
from Products.ERP5Type.patches import CMFMailIn from Products.ERP5Type.patches import CMFMailIn
from Products.ERP5Type.patches import CMFCoreUtils
from Products.ERP5Type.patches import PropertySheets from Products.ERP5Type.patches import PropertySheets
from Products.ERP5Type.patches import CMFCoreSkinnable from Products.ERP5Type.patches import CMFCoreSkinnable
from Products.ERP5Type.patches import CMFCoreSkinsTool from Products.ERP5Type.patches import CMFCoreSkinsTool
......
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from warnings import warn
from Products.CMFCore.exceptions import AccessControl_Unauthorized, NotFound
from Products.CMFCore.utils import getActionContext
from Products.CMFCore import PortalContent
from Products.ERP5Type.Utils import createExpressionContext
from zLOG import LOG
"""
This patch is based on Products/CMFCore/utils.py file from CMF 1.5.0 package.
Please update the following file if you update CMF to greater version.
The modifications in this method are:
* new filter on default action (= ".endswith('_%s' % view)" statement)
* use action API to check its visibility in the context
This method was patched to let CMF choose between several default actions according conditions.
"""
def CMFCoreUtils_getViewFor(obj, view='view'):
warn('__call__() and view() methods using _getViewFor() as well as '
'_getViewFor() itself are deprecated and will be removed in CMF 1.6. '
'Bypass these methods by defining \'(Default)\' and \'view\' Method '
'Aliases.',
DeprecationWarning)
ti = obj.getTypeInfo()
if ti is None:
raise NotFound('Cannot find default view for %r' % obj.getPath())
context = getActionContext(obj)
ec = createExpressionContext(obj)
best_action = (), None
for action in ti.getFilteredActionListFor(obj):
if action.getReference() == view:
if action.test(ec):
break
else:
# In case that "view" (or "list") action is not present or not allowed,
# find something that's allowed (of the same category, if possible).
index = (action.getActionType().endswith('_' + view),
-action.getFloatIndex())
if best_action[0] < index and action.test(ec):
best_action = index, action
else:
action = best_action[1]
if action is None:
raise AccessControl_Unauthorized('No accessible views available for %r'
% obj.getPath())
target = action.getAction()(context).strip()
if target.startswith('/'):
target = target[1:]
__traceback_info__ = ti.getId(), target
return obj.restrictedTraverse(target)
PortalContent._getViewFor = CMFCoreUtils_getViewFor
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