1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2012-today OpenERP SA (<http://www.openerp.com>)
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>
20 ##############################################################################
22 from openerp.osv import osv
23 from openerp.osv import fields
25 class ir_ui_menu(osv.osv):
26 """ Override of ir.ui.menu class. When adding mail_thread module, each
27 new mail.group will create a menu entry. This overrides checks that
28 the current user is in the mail.group followers. If not, the menu
29 entry is taken off the list of menu ids. This way the user will see
30 menu entries for the mail.group he is following.
32 _inherit = 'ir.ui.menu'
35 'mail_group_id': fields.many2one('mail.group', 'Mail Group')
38 def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
39 """ Remove mail.group menu entries when the user is not a follower."""
40 ids = super(ir_ui_menu, self).search(cr, uid, args, offset=offset,
41 limit=limit, order=order,
42 context=context, count=False)
45 SELECT id FROM ir_ui_menu m
46 WHERE m.mail_group_id IS NULL OR EXISTS (
47 SELECT 1 FROM mail_followers
48 WHERE res_model = 'mail.group' AND res_id = m.mail_group_id
49 AND partner_id = (SELECT partner_id FROM res_users WHERE id = %s)
51 """, (uid, tuple(ids)))
52 # Preserve original search order
53 visible_ids = set(x[0] for x in cr.fetchall())
54 ids = [i for i in ids if i in visible_ids]