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