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, ...@@ -490,22 +490,22 @@ class ERP5TypeInformation(XMLObject,
"""Return the object that renders the default view for the given object """Return the object that renders the default view for the given object
""" """
ec = createExpressionContext(ob) ec = createExpressionContext(ob)
best_action = None other_action = None
for action in self.getActionList(): for action in self.getActionList():
if action['id'] == view and action.test(ec): if action['id'] == view or action['category'].endswith('_' + view):
best_action = action if action.test(ec):
break break
else: elif other_action is None:
# In case that "view" (or "list") 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 (of the same category, if possible). # find something that's allowed (of the same category, if possible).
same_category = action['category'].endswith('_' + view) if action.test(ec):
if same_category and action.test(ec): other_action = action
best_action = action
break
else: else:
raise AccessControl_Unauthorized( action = other_action
'No accessible views available for %r' % ob.getPath()) if action is None:
action = best_action raise AccessControl_Unauthorized(
'No accessible views available for %r' % ob.getPath())
target = action.cook(ec)['url'].strip().split(ec.vars['object_url'])[-1] target = action.cook(ec)['url'].strip().split(ec.vars['object_url'])[-1]
if target.startswith('/'): if target.startswith('/'):
target = target[1:] target = target[1:]
......
...@@ -1427,7 +1427,7 @@ class TestPropertySheet: ...@@ -1427,7 +1427,7 @@ class TestPropertySheet:
# check new default view is resturn # check new default view is resturn
self.assertEquals("Organisation_viewDetails", self.assertEquals("Organisation_viewDetails",
portal_type_object.getDefaultViewFor(obj).getId()) portal_type_object.getDefaultViewFor(obj).getId())
# Add new action with low priority # Add new action with low priority
# We set it no visible # We set it no visible
...@@ -1445,6 +1445,32 @@ class TestPropertySheet: ...@@ -1445,6 +1445,32 @@ class TestPropertySheet:
self.assertEquals("Organisation_viewDetails", self.assertEquals("Organisation_viewDetails",
portal_type_object.getDefaultViewFor(obj).getId()) 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): 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. 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