Merge lp:~unifield-team/unifield-web/us-1315 into lp:unifield-web

Proposed by Quentin THEURET @Amaris
Status: Merged
Merged at revision: 4805
Proposed branch: lp:~unifield-team/unifield-web/us-1315
Merge into: lp:unifield-web
Diff against target: 170 lines (+118/-3)
4 files modified
addons/openerp/controllers/form.py (+56/-0)
addons/openerp/static/javascript/form.js (+56/-0)
addons/openerp/widgets/form/templates/button.mako (+1/-0)
addons/openerp/widgets/templates/listgrid/button.mako (+5/-3)
To merge this branch: bzr merge lp:~unifield-team/unifield-web/us-1315
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+295795@code.launchpad.net
To post a comment you must log in.
4791. By Quentin THEURET @Amaris

US-1315 [IMP] Add the name of the groups defined in the BAR

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/openerp/controllers/form.py'
2--- addons/openerp/controllers/form.py 2015-08-28 15:24:55 +0000
3+++ addons/openerp/controllers/form.py 2016-06-01 07:26:57 +0000
4@@ -276,6 +276,62 @@
5 def close_or_disable_tips(self):
6 rpc.RPCProxy('res.users').write(rpc.session.uid,{'menu_tips':False}, rpc.session.context)
7
8+ def get_sd_ref(self, model, res_id):
9+ """
10+ Get the sdref of the record
11+ """
12+ data_pool = rpc.RPCProxy('ir.model.data')
13+ data_ids = data_pool.search([
14+ ('model', '=', model),
15+ ('res_id', '=', res_id)
16+ ])
17+ if not data_ids:
18+ return False
19+
20+ return data_pool.read(data_ids[0], ['name'])['name']
21+
22+ @expose('json', methods=('POST',))
23+ def display_button_sd_ref(self, view_id, btn_name, btn_model, btn_id):
24+ """
25+ Get sdref values of Button Access Rule and Model
26+ :param view_id: The ID of the ir.ui.view where the button is on
27+ :param btn_name: Name of the button to get values
28+ :param btn_model: Name (model) of the ir.model on which the button act
29+ :param btn_id: ID of the button
30+ """
31+ bar_sdref = ''
32+ model_sdref = ''
33+ group_names = False
34+
35+ # If the user is not the administrator, don't display values
36+ if rpc.session.uid != 1:
37+ return dict(admin=False)
38+
39+ rules_pool = rpc.RPCProxy('msf_button_access_rights.button_access_rule')
40+ model_pool = rpc.RPCProxy('ir.model')
41+
42+ if btn_name and view_id:
43+ view_ids = rules_pool.get_family_ids(int(view_id))
44+ if not view_ids:
45+ view_ids = [view_id]
46+
47+ rule_ids = rules_pool.search([
48+ ('name', '=', btn_name),
49+ ('view_id', 'in', view_ids),
50+ ])
51+
52+ if rule_ids:
53+ bar_sdref = self.get_sd_ref('msf_button_access_rights.button_access_rule', rule_ids[0])
54+ group_names = rules_pool.read(rule_ids[0], ['group_names'])['group_names']
55+
56+ model_ids = model_pool.search([
57+ ('model', '=', btn_model)
58+ ])
59+ if model_ids:
60+ model_sdref = self.get_sd_ref('ir.model', model_ids[0])
61+
62+ return dict(model=btn_model, name=btn_name, btn_id=btn_id, bar_sdref=bar_sdref, model_sdref=model_sdref, admin=True, group_names=group_names)
63+
64 def _read_form(self, context, count, domain, filter_domain, id, ids, kw,
65 limit, model, offset, search_data, search_domain, source,
66 view_ids, view_mode, view_type, notebook_tab, o2m_edit=False,
67
68=== modified file 'addons/openerp/static/javascript/form.js'
69--- addons/openerp/static/javascript/form.js 2016-03-16 15:50:01 +0000
70+++ addons/openerp/static/javascript/form.js 2016-06-01 07:26:57 +0000
71@@ -20,6 +20,62 @@
72 ////////////////////////////////////////////////////////////////////////////////
73
74 var form_controller;
75+
76+function showBtnSdref(ev, btn_name, btn_model, btn_id, src)
77+{
78+ if(ev.ctrlKey === true) {
79+ var prefix = src && src != '_terp_list' ? src + '/' : '';
80+ if (prefix !== '') {
81+ // In case of one2many, get the o2m view id and the parent model
82+ o2m_view_id = openobject.dom.get(prefix + '_terp_view_id').value;
83+ o2m_model = openobject.dom.get(prefix + '_terp_model').value;
84+ parent_model = openobject.dom.get('_terp_model').value;
85+ parent_view_id = openobject.dom.get('_terp_view_id').value;
86+
87+ if (o2m_view_id === 'False' || o2m_view_id === false) {
88+ view_id = parent_view_id;
89+ btn_model = parent_model;
90+ }
91+ else {
92+ view_id = o2m_view_id;
93+ btn_model = o2m_model;
94+ }
95+ }
96+ else {
97+ view_id = openobject.dom.get('_terp_view_id').value;
98+ if (btn_model === false || btn_model === '') {
99+ btn_model = openobject.dom.get('_terp_model').value;
100+ }
101+ }
102+
103+ openobject.http.postJSON('/openerp/form/display_button_sd_ref', {
104+ 'view_id': view_id,
105+ 'btn_name': btn_name,
106+ 'btn_model': btn_model,
107+ 'btn_id': btn_id,
108+ }).addCallback(function(obj){
109+ if (obj.admin === true) {
110+ model_name_msg = obj.model != false ? obj.model : 'No model found';
111+ model_sdref_msg = obj.model_sdref != false ? obj.model_sdref : 'No model found';
112+ btn_name_msg = obj.name != false ? obj.name : 'No button found';
113+ btn_id_msg = obj.btn_id != false ? obj.btn_id : 'No button found';
114+ bar_sdref_msg = obj.bar_sdref != false ? obj.bar_sdref : 'No BAR found';
115+ group_names_msg = obj.group_names != false ? obj.group_names : 'No group defined for this rule';
116+
117+ alert(
118+ 'Model name: ' + model_name_msg + '\n' +
119+ 'Model SDRef: ' + model_sdref_msg + '\n' +
120+ 'Button name: ' + btn_name_msg + '\n' +
121+ //'Button ID: ' + btn_id_msg + '\n' +
122+ 'BAR SDRef: ' + bar_sdref_msg + '\n' +
123+ 'Groups: ' + group_names_msg
124+ );
125+ }
126+ });
127+ ev.preventDefault();
128+ }
129+}
130+
131 function get_form_action(action, params){
132 var act = typeof(form_controller) == 'undefined' ? '/openerp/form' : form_controller;
133 act = action && action.indexOf('/') == 0 ? action : act + '/' + action;
134
135=== modified file 'addons/openerp/widgets/form/templates/button.mako'
136--- addons/openerp/widgets/form/templates/button.mako 2013-05-15 12:32:42 +0000
137+++ addons/openerp/widgets/form/templates/button.mako 2016-06-01 07:26:57 +0000
138@@ -5,6 +5,7 @@
139 href="javascript: void(0)"
140 title="${help}"
141 onclick="buttonClicked('${name}', '${btype}', '${model}', '${id}', getNodeAttribute(this, 'confirm'), '${target}', getNodeAttribute(this, 'context'));"
142+ oncontextmenu="showBtnSdref(event, '${name}', '${model}', '${id}');"
143 style="height: 20px;"
144 ${py.attrs(attrs, confirm=confirm, context=ctx)}>
145 % if string:
146
147=== modified file 'addons/openerp/widgets/templates/listgrid/button.mako'
148--- addons/openerp/widgets/templates/listgrid/button.mako 2013-03-10 21:13:47 +0000
149+++ addons/openerp/widgets/templates/listgrid/button.mako 2016-06-01 07:26:57 +0000
150@@ -1,15 +1,17 @@
151 % if visible:
152 % if icon:
153 <a class="listImage-container" name="${name}" id="${name}" title="${help}" context="${ctx}" ${py.attrs(attrs, confirm=confirm)}
154- onclick="new ListView('${parent_grid}').onButtonClick('${name}', '${btype}', ${id}, getNodeAttribute(this, 'confirm'), getNodeAttribute(this, 'context'));">
155+ onclick="new ListView('${parent_grid}').onButtonClick('${name}', '${btype}', ${id}, getNodeAttribute(this, 'confirm'), getNodeAttribute(this, 'context'));"
156+ oncontextmenu="showBtnSdref(event, '${name}', '${model}', '${id}', '${parent_grid}');">
157 <img height="16" width="16" class="listImage" src="${icon}"/>
158 </a>
159 % else:
160 <a class="button-b" name="${name}" id="${name}" href="javascript: void(0)" ${py.attrs(attrs, context=ctx, confirm=confirm)} title="${help}"
161- onclick="new ListView('${parent_grid}').onButtonClick('${name}', '${btype}', ${id}, getNodeAttribute(this, 'confirm'), getNodeAttribute(this, 'context'))">
162+ onclick="new ListView('${parent_grid}').onButtonClick('${name}', '${btype}', ${id}, getNodeAttribute(this, 'confirm'), getNodeAttribute(this, 'context'))"
163+ oncontextmenu="showBtnSdref(event, '${name}', '${model}', '${id}'), '${parent_grid}';">
164 ${string}
165 </a>
166 % endif
167 % elif not icon:
168- <span><img style="display:none" name="${name}" id="${name}" height="16" width="16" class="listImage" src="${icon}" title="${help}" context="${ctx}" ${py.attrs(attrs, confirm=confirm)} onclick="new ListView('${parent_grid}').onButtonClick('${name}', '${btype}', ${id}, getNodeAttribute(this, 'confirm'), getNodeAttribute(this, 'context'))"/></span>
169+ <span><img style="display:none" name="${name}" id="${name}" height="16" width="16" class="listImage" src="${icon}" title="${help}" context="${ctx}" ${py.attrs(attrs, confirm=confirm)} onclick="new ListView('${parent_grid}').onButtonClick('${name}', '${btype}', ${id}, getNodeAttribute(this, 'confirm'), getNodeAttribute(this, 'context'))" oncontextmenu="showBtnSdref(event, '${name}', '${model}', '${id}', '${parent_grid}');"/></span>
170 % endif

Subscribers

People subscribed via source and target branches

to all changes: