Commit 9c2de450 authored by Julien Muchembled's avatar Julien Muchembled

Define interfaces for actions

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/portal_types@29258 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 547fdec0
......@@ -34,7 +34,10 @@ import unittest
# manually and treated as reference to what implements what
implements_tuple_list = [
## ERP5Type
('ERP5Type.Tool.TypesTool.TypesTool', 'IActionProvider'),
('ERP5Type.ERP5Type.ERP5TypeInformation', 'IActionProvider'),
('ERP5Type.ERP5Type.ERP5TypeInformation', 'ILocalRoleAssignor'),
('ActionInformation', 'IAction'),
('RoleInformation', 'ILocalRoleGenerator'),
## ERP5
('BusinessPath', 'IArrowBase'),
......
......@@ -28,21 +28,19 @@
#
##############################################################################
import zope.interface
from AccessControl import ClassSecurityInfo, getSecurityManager
from Acquisition import aq_base
from Products.CMFCore.Expression import Expression
from Products.CMFCore.ActionInformation import ActionInfo
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type import interfaces, Constraint, Permissions, PropertySheet
from Products.ERP5Type.Permissions import AccessContentsInformation
from Products.ERP5Type.XMLObject import XMLObject
from zLOG import LOG
class ActionInformation(XMLObject):
"""
ActionInformation is an ERP5 type which will eventually replace respective ActionInformation from CMF.
"""
# XXX 'icon' property is not used. We can problably drop it.
meta_type = 'ERP5 Action Information'
portal_type = 'Action Information'
add_permission = Permissions.AddPortalContent
......@@ -54,14 +52,17 @@ class ActionInformation(XMLObject):
security = ClassSecurityInfo()
security.declareObjectProtected(AccessContentsInformation)
zope.interface.implements(interfaces.IAction)
# Declarative properties
property_sheets = ( PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.ActionInformation
)
security.declarePrivate('test')
security.declareProtected(AccessContentsInformation, 'test')
def test(self, ec):
"""Test if the action should be displayed or not for the given context"""
if self.isVisible():
permission_list = self.getActionPermissionList()
if permission_list:
......@@ -84,10 +85,19 @@ class ActionInformation(XMLObject):
return condition is None or condition(ec)
return False
security.declarePrivate('getActionUrl')
def getActionUrl(self, ec):
security.declareProtected(AccessContentsInformation, 'getActionInfo')
def getActionInfo(self, ec):
"""Return a dict with values required to display the action"""
action = self.getAction()
return action is not None and action(ec) or ''
icon = self.getIcon()
return {'id': self.getReference(),
'name': self.getTitle(),
'description': self.getDescription(),
'category': self.getActionType(),
'priority': self.getFloatIndex(),
'icon': icon is not None and icon(ec) or '',
'url': action is not None and action(ec) or '',
}
def _setAction(self, value):
"""Overridden setter for 'action' to accept strings and clean null values
......
......@@ -230,6 +230,8 @@ class ERP5TypeInformation(XMLObject,
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
zope.interface.implements(interfaces.IActionProvider)
# Declarative properties
property_sheets = ( PropertySheet.BaseType, )
......@@ -475,6 +477,7 @@ class ERP5TypeInformation(XMLObject,
security.declarePrivate('getFilteredActionListFor')
def getFilteredActionListFor(self, ob=None):
"""Return all actions applicable to the object"""
ec = getExprContext(self, ob)
return (action for action in self.getActionInformationList()
if action.test(ec))
......
......@@ -66,7 +66,7 @@ class ActionInformation:
'description': 'TALES Expression to define the URL of the action',
'mode': 'w',
},
{ 'id': 'icon', # XXX not used
{ 'id': 'icon',
'type': 'object',
'description': 'TALES Expression to define the URL of the icon of the' \
' action',
......
......@@ -16,6 +16,7 @@
##############################################################################
import imp, sys
import zope.interface
from Acquisition import aq_base
from AccessControl import ClassSecurityInfo
from OFS.Folder import Folder as OFSFolder
......@@ -23,7 +24,7 @@ import transaction
from Products.CMFCore import TypesTool as CMFCore_TypesTool
from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5Type import Permissions
from Products.ERP5Type import interfaces, Permissions
from Products.ERP5Type.ERP5Type import ERP5TypeInformation
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from zLOG import LOG, WARNING, PANIC
......@@ -39,8 +40,11 @@ class TypesTool(BaseTool, CMFCore_TypesTool.TypesTool):
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
zope.interface.implements(interfaces.IActionProvider)
security.declarePrivate('getFilteredActionListFor')
def getFilteredActionListFor(self, ob=None):
"""Return all actions applicable to the object"""
if ob is not None:
type_info = self.getTypeInfo(ob)
if type_info is not None:
......
......@@ -32,14 +32,9 @@ def listFilteredActionsFor(self, object=None):
elif hasattr(provider, 'getFilteredActionListFor'):
from Products.ERP5Type.ERP5Type import getExprContext
ec = getExprContext(self, object)
actions += sorted(({
'id': action.getReference(),
'name': action.getTitle(),
'description': action.getDescription(),
'category': action.getActionType(),
'priority': action.getFloatIndex(),
'url': action.getActionUrl(ec),
} for action in provider.getFilteredActionListFor(object)),
actions += sorted(
(action.getActionInfo(ec)
for action in provider.getFilteredActionListFor(object)),
key=lambda x: x['priority'])
else:
# for Action Providers written for CMF versions before 1.5
......
......@@ -47,8 +47,8 @@ def CMFCoreUtils_getViewFor(obj, view='view'):
if action.test(ec):
break
else:
# In case that "view" action is not present or not allowed,
# find something that's allowed.
# 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):
......@@ -59,7 +59,7 @@ def CMFCoreUtils_getViewFor(obj, view='view'):
raise AccessControl_Unauthorized('No accessible views available for %r'
% obj.getPath())
target = action.getActionUrl(context).strip()
target = action.getAction()(context).strip()
if target.startswith('/'):
target = target[1:]
__traceback_info__ = ti.getId(), target
......
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