2
# -*- encoding: utf-8 -*-
3
##############################################################################
5
# OpenERP, Open Source Management Solution
6
# Copyright (C) 2011 TeMPO Consulting, MSF. All Rights Reserved
7
# Developer: Max Mumford
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU Affero General Public License as
11
# published by the Free Software Foundation, either version 3 of the
12
# License, or (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU Affero General Public License for more details.
19
# You should have received a copy of the GNU Affero General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
##############################################################################
25
from osv import fields
29
class button_access_rule(osv.osv):
31
Lets user create access rules for buttons in views.
32
This class defines which model, view, button, and groups to target
35
_name = "msf_button_access_rights.button_access_rule"
37
def _get_group_names(self, cr, uid, ids, field_name, arg, context):
38
res = dict.fromkeys(ids, '')
39
records = self.browse(cr, uid, ids)
40
for record in records:
41
res[record.id] = ', '.join([g.name for g in record.group_ids])
45
'name': fields.char('Name', size=256, required=True),
46
'label': fields.char('Label', size=256),
47
'type': fields.selection((('workflow','Workflow'), ('object','Object'), ('action', 'Action')), 'Button Type'),
48
'model_id': fields.many2one('ir.model', 'Model', help='The type of data to which this rule applies', required=True, ondelete='cascade'),
49
'view_id': fields.many2one('ir.ui.view', 'View', help='The view to which this rule applies', required=True, ondelete='cascade'),
50
'group_ids': fields.many2many('res.groups', 'button_access_rule_groups_rel', 'button_access_rule_id', 'group_id', 'Groups', help='A list of groups who have access to this button. If you leave this empty, everybody will have access.'),
51
'comment': fields.text('Comment', help='A description of what this rule does'),
52
'group_names': fields.function(_get_group_names, type='char', method=True, string='Group Names', help='A list of all group names given button access by this rule'),
53
'active': fields.boolean('Active', help='If checked, this rule will be applied.'),
61
('name_view_unique', 'unique (name, view_id)', "The combination of Button Name and View ID must be unique - i.e. you cannot have two rules for the same button in the same view"),
64
def _get_family_ids(self, cr, view_id):
66
Return a list of ids for all the children of view_id (and contains the view_id itself)
68
family_ids = [view_id]
70
view_pool = self.pool.get('ir.ui.view')
73
last_ids = view_pool.search(cr, 1, [('inherit_id','in',last_ids)])
74
family_ids = family_ids + last_ids