From b89153a78133e7ac37ba8673cf9869d7f595c4c8 Mon Sep 17 00:00:00 2001 From: Nicolas Delaby <nicolas@nexedi.com> Date: Tue, 9 Feb 2010 15:04:19 +0000 Subject: [PATCH] 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 --- product/ERP5Type/ERP5Type.py | 24 +++++++++++----------- product/ERP5Type/tests/testERP5Type.py | 28 +++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/product/ERP5Type/ERP5Type.py b/product/ERP5Type/ERP5Type.py index 04a7b2b224..9ffbc5858f 100644 --- a/product/ERP5Type/ERP5Type.py +++ b/product/ERP5Type/ERP5Type.py @@ -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 - break - else: + if action['id'] == view or action['category'].endswith('_' + view): + if action.test(ec): + break + 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: - raise AccessControl_Unauthorized( - 'No accessible views available for %r' % ob.getPath()) - action = best_action + action = other_action + if action is None: + raise AccessControl_Unauthorized( + 'No accessible views available for %r' % ob.getPath()) + target = action.cook(ec)['url'].strip().split(ec.vars['object_url'])[-1] if target.startswith('/'): target = target[1:] diff --git a/product/ERP5Type/tests/testERP5Type.py b/product/ERP5Type/tests/testERP5Type.py index 8a207383e9..960e1fdb46 100644 --- a/product/ERP5Type/tests/testERP5Type.py +++ b/product/ERP5Type/tests/testERP5Type.py @@ -1427,7 +1427,7 @@ class TestPropertySheet: # check new default view is resturn self.assertEquals("Organisation_viewDetails", - portal_type_object.getDefaultViewFor(obj).getId()) + portal_type_object.getDefaultViewFor(obj).getId()) # Add new action with low priority # We set it no visible @@ -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. -- 2.30.9