Commit c58cc791 authored by Sebastien Robin's avatar Sebastien Robin

The priority on actions was somewhat working only by chance.

There was only a sort for action inside a particular provider,
and there was no sorting at all between actions coming from
different action providers.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38891 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3e9198ec
...@@ -541,7 +541,6 @@ class ERP5TypeInformation(XMLObject, ...@@ -541,7 +541,6 @@ class ERP5TypeInformation(XMLObject,
def _getActionList(self): def _getActionList(self):
action_list = self.getCacheableActionList() action_list = self.getCacheableActionList()
action_list.sort(key=lambda x:x['priority'])
return action_list return action_list
_getActionList = CachingMethod(_getActionList, _getActionList = CachingMethod(_getActionList,
id='getActionList', id='getActionList',
......
...@@ -100,6 +100,7 @@ def listFilteredActionsFor(self, object=None): ...@@ -100,6 +100,7 @@ def listFilteredActionsFor(self, object=None):
# IActionProviders: # IActionProviders:
migrateNonProviders(self) migrateNonProviders(self)
actions.sort(key=lambda x:x.get('priority', 0))
# Reorganize the actions by category. # Reorganize the actions by category.
filtered_actions={'user':[], filtered_actions={'user':[],
'folder':[], 'folder':[],
......
...@@ -2735,6 +2735,43 @@ class TestPropertySheet: ...@@ -2735,6 +2735,43 @@ class TestPropertySheet:
self.assertTrue(o.getIcon().endswith(portal.portal_types['Organisation']\ self.assertTrue(o.getIcon().endswith(portal.portal_types['Organisation']\
.getTypeIcon())) .getTypeIcon()))
def test_actionPriority(self):
"""Tests action priority
"""
portal = self.getPortalObject()
portal_actions = self.getPortal().portal_actions
try:
module = self.getPersonModule()
person = module.newContent(id='1', portal_type='Person')
def addCustomAction(name, priority):
portal_actions.addAction(id=name,
title=name,
description='',
action='string:${object_url}/Base_viewDict',
condition='',
permission='View',
category='object_view',
priority=priority)
initial_action_list = portal_actions.listFilteredActionsFor(person)\
.get('object_view',[])
addCustomAction('test_before', -1)
max_priority = max([x.get('priority', 0) for x in initial_action_list])
addCustomAction('test_after', max_priority + 1)
final_action_list = portal_actions.listFilteredActionsFor(person)\
.get('object_view',[])
self.assertEquals(len(final_action_list), len(initial_action_list) + 2)
self.assertEquals(final_action_list[0]['id'], 'test_before')
self.assertEquals(final_action_list[-1]['id'], 'test_after')
# check that we have another portal types action in the middle
self.assertTrue('view' in [x['id'] for x in final_action_list[1:-1]])
finally:
index_list = []
action_list = portal_actions._cloneActions()
for action in action_list:
if action.id in ('test_before', 'test_after'):
index_list.append(action_list.index(action))
if len(index_list):
portal_actions.deleteActions(selections=index_list)
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
......
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