diff options
| author | Olivier Dony <odo@openerp.com> | 2010-12-10 17:17:08 +0100 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2010-12-10 17:17:08 +0100 |
| commit | 498a04ae2d5f9cbb170ea1d2f08e9ab773d9a8a9 (patch) | |
| tree | 2cf0823e45dfa2cadfae5fe3cbf40358bbe0d263 /bin/addons/base/ir/ir_ui_menu.py | |
| parent | 098b92a207f685f1e6b8beb36ca970d4efe48c25 (diff) | |
[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
Diffstat (limited to 'bin/addons/base/ir/ir_ui_menu.py')
| -rw-r--r-- | bin/addons/base/ir/ir_ui_menu.py | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/bin/addons/base/ir/ir_ui_menu.py b/bin/addons/base/ir/ir_ui_menu.py index 800a3ede95a..9baff950c4f 100644 --- a/bin/addons/base/ir/ir_ui_menu.py +++ b/bin/addons/base/ir/ir_ui_menu.py @@ -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) |
