[FIX] ir.ui.menu: menu items should be filtered only in tree view

The normal list view should display them all, otherwise menus without children are invisible for example
Also ensured that create() clears the menu cache, otherwise adding children to an invisible menu
may not cause it to appear until the server is restarted.

lp bug: https://launchpad.net/bugs/671745 fixed

bzr revid: odo@openerp.com-20101210161708-txdxidrr3k4c6hk5
This commit is contained in:
Olivier Dony 2010-12-10 17:17:08 +01:00
parent 098b92a207
commit 498a04ae2d
2 changed files with 30 additions and 13 deletions

View File

@ -1412,6 +1412,7 @@
<field name="res_model">ir.ui.menu</field>
<field name="view_type">form</field>
<field name="view_id" ref="edit_menu"/>
<field name="context">{'ir.ui.menu.full_list':True}</field>
<field name="search_view_id" ref="edit_menu_access_search"/>
<field name="help">Manage and customize the items available and displayed in your OpenERP system menu. You can delete an item by clicking on the box at the beginning of each line and then delete it through the button that appeared. Items can be assigned to specific groups in order to make them accessible to some users within the system.</field>
</record>

View File

@ -97,22 +97,15 @@ class ir_ui_menu(osv.osv):
self._cache[key] = True
return action_id
def search(self, cr, uid, args, offset=0, limit=None, order=None,
context=None, count=False):
ids = super(ir_ui_menu, self).search(cr, uid, args, offset=0,
limit=None, order=order, context=context, count=False)
if not ids:
if count:
return 0
return []
def _filter_visible_menus(self, cr, uid, ids, context=None):
"""Filters the give menu ids to only keep the menu items that should be
visible in the menu hierarchy of the current user.
Uses a cache for speeding up the computation.
"""
modelaccess = self.pool.get('ir.model.access')
user_groups = set(self.pool.get('res.users').read(cr, 1, uid, ['groups_id'])['groups_id'])
result = []
for menu in self.browse(cr, uid, ids):
for menu in self.browse(cr, uid, ids, context=context):
# this key works because user access rights are all based on user's groups (cfr ir_model_access.check)
key = (cr.dbname, menu.id, tuple(user_groups))
if key in self._cache:
@ -153,6 +146,25 @@ class ir_ui_menu(osv.osv):
result.append(menu.id)
self._cache[key] = True
return result
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
if context is None:
context = {}
ids = super(ir_ui_menu, self).search(cr, uid, args, offset=0,
limit=None, order=order, context=context, count=False)
if not ids:
if count:
return 0
return []
# menu filtering is done only on main menu tree, not other menu lists
if context.get('ir.ui.menu.full_list'):
result = ids
else:
result = self._filter_visible_menus(cr, uid, ids, context=context)
if offset:
result = result[long(offset):]
@ -178,6 +190,10 @@ class ir_ui_menu(osv.osv):
parent_path = ''
return parent_path + menu.name
def create(self, *args, **kwargs):
self.clear_cache()
return super(ir_ui_menu, self).create(*args, **kwargs)
def write(self, *args, **kwargs):
self.clear_cache()
return super(ir_ui_menu, self).write(*args, **kwargs)