[FIX] ir.ui.menu: safer eval of action contexts when computing needaction

Unchecked eval of a context may fail for various reasons,
such as the use of client-side variables like `active_id`

bzr revid: odo@openerp.com-20130507104025-em6w03pcxeq92az9
This commit is contained in:
Olivier Dony 2013-05-07 12:40:25 +02:00
parent 0d21c3eba3
commit 82e4bb826a
1 changed files with 9 additions and 1 deletions

View File

@ -298,13 +298,21 @@ class ir_ui_menu(osv.osv):
- the needaction counter of the related action, taking into account
the action domain
"""
if context is None:
context = {}
res = {}
menu_ids = set()
for menu in self.browse(cr, uid, ids, context=context):
menu_ids.add(menu.id)
ctx = None
if menu.action and menu.action.type in ('ir.actions.act_window', 'ir.actions.client') and menu.action.context:
ctx = eval(menu.action.context, context) or None
try:
# use magical UnquoteEvalContext to ignore undefined client-side variables such as `active_id`
eval_ctx = tools.UnquoteEvalContext(**context)
ctx = eval(menu.action.context, locals_dict=eval_ctx, nocopy=True) or None
except Exception:
# if the eval still fails for some reason, we'll simply skip this menu
pass
menu_ref = ctx and ctx.get('needaction_menu_ref')
if menu_ref:
if not isinstance(menu_ref, list):