Commit b89153a7 authored by Nicolas Delaby's avatar Nicolas Delaby

Handle special use case for Modules

 * action could be categorised as object_list only, getDefaultViewFor
   should fallback to one of them
 * Extend test to avoid regression
Thanks to JM


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32365 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4e437fb6
......@@ -490,22 +490,22 @@ class ERP5TypeInformation(XMLObject,
"""Return the object that renders the default view for the given object
"""
ec = createExpressionContext(ob)
best_action = None
other_action = None
for action in self.getActionList():
if action['id'] == view and action.test(ec):
best_action = action
if action['id'] == view or action['category'].endswith('_' + view):
if action.test(ec):
break
else:
elif other_action is None:
# In case that "view" (or "list") action is not present or not allowed,
# find something that's allowed (of the same category, if possible).
same_category = action['category'].endswith('_' + view)
if same_category and action.test(ec):
best_action = action
break
if action.test(ec):
other_action = action
else:
action = other_action
if action is None:
raise AccessControl_Unauthorized(
'No accessible views available for %r' % ob.getPath())
action = best_action
target = action.cook(ec)['url'].strip().split(ec.vars['object_url'])[-1]
if target.startswith('/'):
target = target[1:]
......
......@@ -1445,6 +1445,32 @@ class TestPropertySheet:
self.assertEquals("Organisation_viewDetails",
portal_type_object.getDefaultViewFor(obj).getId())
# If no action belong to view category, getDefaultViewFor
# should fallback to first valid Action.
# This is the current behaviour for Actions on modules.
# delete all current actions
portal_type_object.manage_delObjects([action.getId() for action in \
portal_type_object.contentValues(portal_type='Action Information')])
# Add new action which does not belong to view category ( action_type: 'object_list')
default_list = portal_type_object.newContent(portal_type='Action Information',
reference="view_list",
title='Web view',
action='string:${object_url}/Organisation_viewFinancialInformationList',
condition=None,
action_permission='View',
action_type='object_list',
visible=1,
float_index=0.2)
# check new custom action '_list' is return
self.assertEquals("Organisation_viewFinancialInformationList",
portal_type_object.getDefaultViewFor(obj).getId())
# Avoid deletion of actions fo rother tests
transaction.abort()
def test_22_securityReindex(self, quiet=quiet, run=run_all_test):
"""
Tests that the security is reindexed when a role is changed on an object.
......
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