Merge lp:~matthieuchoplin/credativ-openerp/ERP-701-enable-group-on-treeviewlinks into lp:credativ-openerp

Proposed by Matthieu Choplin
Status: Needs review
Proposed branch: lp:~matthieuchoplin/credativ-openerp/ERP-701-enable-group-on-treeviewlinks
Merge into: lp:credativ-openerp
Diff against target: 258 lines (+136/-85)
5 files modified
web_treeviewlinks/__init__.py (+1/-0)
web_treeviewlinks/__openerp__.py (+3/-0)
web_treeviewlinks/security/web_treeviewlinks_security.xml (+9/-0)
web_treeviewlinks/static/src/js/view_list.js (+101/-85)
web_treeviewlinks/treeviewlinks_access.py (+22/-0)
To merge this branch: bzr merge lp:~matthieuchoplin/credativ-openerp/ERP-701-enable-group-on-treeviewlinks
Reviewer Review Type Date Requested Status
credativ Pending
Review via email: mp+208781@code.launchpad.net

Description of the change

Hello,

this development enables to choose for which group of users we want to enable the treeviewlinks.

To post a comment you must log in.

Unmerged revisions

259. By made

ERP-701-enable-group-on-treeviewlinks

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'web_treeviewlinks/__init__.py'
2--- web_treeviewlinks/__init__.py 2012-08-02 15:21:19 +0000
3+++ web_treeviewlinks/__init__.py 2014-02-28 12:01:59 +0000
4@@ -0,0 +1,1 @@
5+import treeviewlinks_access
6\ No newline at end of file
7
8=== modified file 'web_treeviewlinks/__openerp__.py'
9--- web_treeviewlinks/__openerp__.py 2012-08-02 15:21:19 +0000
10+++ web_treeviewlinks/__openerp__.py 2014-02-28 12:01:59 +0000
11@@ -29,6 +29,9 @@
12 "website" : "http://credativ.co.uk",
13 "category" : "Tools",
14 "depends" : ["web"],
15+ 'update_xml' : [
16+ "security/web_treeviewlinks_security.xml",
17+ ],
18 "js": [
19 "static/src/js/view_list.js",
20 ],
21
22=== added directory 'web_treeviewlinks/security'
23=== added file 'web_treeviewlinks/security/web_treeviewlinks_security.xml'
24--- web_treeviewlinks/security/web_treeviewlinks_security.xml 1970-01-01 00:00:00 +0000
25+++ web_treeviewlinks/security/web_treeviewlinks_security.xml 2014-02-28 12:01:59 +0000
26@@ -0,0 +1,9 @@
27+<?xml version="1.0" encoding="utf-8"?>
28+<openerp>
29+<data>
30+ <record id="group_treeviewlinks_users" model="res.groups">
31+ <field name="name">Tree view links Users</field>
32+ </record>
33+
34+</data>
35+</openerp>
36
37=== modified file 'web_treeviewlinks/static/src/js/view_list.js'
38--- web_treeviewlinks/static/src/js/view_list.js 2012-08-16 10:57:41 +0000
39+++ web_treeviewlinks/static/src/js/view_list.js 2014-02-28 12:01:59 +0000
40@@ -3,90 +3,106 @@
41 _lt = openerp.web._lt;
42 var QWeb = openerp.web.qweb;
43
44-openerp.web.ListView.List = openerp.web.ListView.List.extend({
45- render: function () {
46- var self = this;
47- if (this.$current) {
48- this.$current.remove();
49- }
50- this.$current = this.$_element.clone(true);
51- this.$current.empty().append(
52- QWeb.render('ListView.rows', _.extend({
53- render_cell: function () {
54- return self.render_cell.apply(self, arguments); }
55- }, this)));
56- // dodgy hack to get links on things
57- this.records.each(function(record){
58- var $row = self.$current.find('[data-id=' + record.get('id') + ']');
59- for(var i=0, length=self.columns.length; i<length; ++i) {
60- if(self.columns[i].type === 'many2one') {
61- var $cell = $row.find((_.str.sprintf('[data-field=%s]', self.columns[i].id)));
62- $cell.html(_.template('<a class="oe_form_uri" href="#" data-model="<%-model%>" data-id="<%-id%>"><%-text%></a>', {
63- text: openerp.web.format_value(record.get(self.columns[i].id), self.columns[i], ''),
64- model: self.columns[i].relation,
65- id: record.get(self.columns[i].id)[0]
66- }));
67- $cell.find('a')
68- .unbind('click')
69- .click(function () {
70- var cell = $(this);
71- self.group.view.do_action({
72- type: 'ir.actions.act_window',
73- res_model: cell.attr('data-model'),
74- res_id: parseInt(cell.attr('data-id')),
75- views: [[false, 'page'], [false, 'form']],
76- target: 'current'
77- });
78- return false;
79- });
80- }
81- }
82- });
83- this.pad_table_to(5);
84- }
85-});
86-
87-openerp.web.form.One2ManyList = openerp.web.ListView.List.extend({
88- render: function () {
89- var self = this;
90- if (this.$current) {
91- this.$current.remove();
92- }
93- this.$current = this.$_element.clone(true);
94- this.$current.empty().append(
95- QWeb.render('ListView.rows', _.extend({
96- render_cell: function () {
97- return self.render_cell.apply(self, arguments); }
98- }, this)));
99- // dodgy hack to get links on things
100- this.records.each(function(record){
101- var $row = self.$current.find('[data-id=' + record.get('id') + ']');
102- for(var i=0, length=self.columns.length; i<length; ++i) {
103- if(self.columns[i].type === 'many2one') {
104- var $cell = $row.find((_.str.sprintf('[data-field=%s]', self.columns[i].id)));
105- $cell.html(_.template('<a class="oe_form_uri" href="#" data-model="<%-model%>" data-id="<%-id%>"><%-text%></a>', {
106- text: openerp.web.format_value(record.get(self.columns[i].id), self.columns[i], ''),
107- model: self.columns[i].relation,
108- id: record.get(self.columns[i].id)[0]
109- }));
110- $cell.find('a')
111- .unbind('click')
112- .click(function () {
113- var cell = $(this);
114- self.group.view.do_action({
115- type: 'ir.actions.act_window',
116- res_model: cell.attr('data-model'),
117- res_id: parseInt(cell.attr('data-id')),
118- views: [[false, 'page'], [false, 'form']],
119- target: 'current'
120- });
121- return false;
122- });
123- }
124- }
125- });
126- this.pad_table_to(5);
127- }
128-});
129+function authorize(have_access) {
130+ var func = new openerp.web.Model("treeviewlinks.access").get_func("authorize");
131+ func(openerp.connection.uid).pipe(function(res) {
132+ have_access(res);
133+ });
134+}
135+
136+authorize(function(res){
137+ // if the current user is in the group "Right Panel Users"
138+ console.log(res, arguments);
139+ if ( res ) {
140+ openerp.web.ListView.List = openerp.web.ListView.List.extend({
141+ render: function () {
142+ var self = this;
143+ if (this.$current) {
144+ this.$current.remove();
145+ }
146+ this.$current = this.$_element.clone(true);
147+ this.$current.empty().append(
148+ QWeb.render('ListView.rows', _.extend({
149+ render_cell: function () {
150+ return self.render_cell.apply(self, arguments); }
151+ }, this)));
152+ // dodgy hack to get links on things
153+ this.records.each(function(record){
154+ var $row = self.$current.find('[data-id=' + record.get('id') + ']');
155+ for(var i=0, length=self.columns.length; i<length; ++i) {
156+ if(self.columns[i].type === 'many2one') {
157+ var $cell = $row.find((_.str.sprintf('[data-field=%s]', self.columns[i].id)));
158+ $cell.html(_.template('<a class="oe_form_uri" href="#" data-model="<%-model%>" data-id="<%-id%>"><%-text%></a>', {
159+ text: openerp.web.format_value(record.get(self.columns[i].id), self.columns[i], ''),
160+ model: self.columns[i].relation,
161+ id: record.get(self.columns[i].id)[0]
162+ }));
163+ $cell.find('a')
164+ .unbind('click')
165+ .click(function () {
166+ var cell = $(this);
167+ self.group.view.do_action({
168+ type: 'ir.actions.act_window',
169+ res_model: cell.attr('data-model'),
170+ res_id: parseInt(cell.attr('data-id')),
171+ views: [[false, 'page'], [false, 'form']],
172+ target: 'current'
173+ });
174+ return false;
175+ });
176+ }
177+ }
178+ });
179+ this.pad_table_to(5);
180+ }
181+ });
182+
183+ openerp.web.form.One2ManyList = openerp.web.ListView.List.extend({
184+ render: function () {
185+ var self = this;
186+ if (this.$current) {
187+ this.$current.remove();
188+ }
189+ this.$current = this.$_element.clone(true);
190+ this.$current.empty().append(
191+ QWeb.render('ListView.rows', _.extend({
192+ render_cell: function () {
193+ return self.render_cell.apply(self, arguments); }
194+ }, this)));
195+ // dodgy hack to get links on things
196+ this.records.each(function(record){
197+ var $row = self.$current.find('[data-id=' + record.get('id') + ']');
198+ for(var i=0, length=self.columns.length; i<length; ++i) {
199+ if(self.columns[i].type === 'many2one') {
200+ var $cell = $row.find((_.str.sprintf('[data-field=%s]', self.columns[i].id)));
201+ $cell.html(_.template('<a class="oe_form_uri" href="#" data-model="<%-model%>" data-id="<%-id%>"><%-text%></a>', {
202+ text: openerp.web.format_value(record.get(self.columns[i].id), self.columns[i], ''),
203+ model: self.columns[i].relation,
204+ id: record.get(self.columns[i].id)[0]
205+ }));
206+ $cell.find('a')
207+ .unbind('click')
208+ .click(function () {
209+ var cell = $(this);
210+ self.group.view.do_action({
211+ type: 'ir.actions.act_window',
212+ res_model: cell.attr('data-model'),
213+ res_id: parseInt(cell.attr('data-id')),
214+ views: [[false, 'page'], [false, 'form']],
215+ target: 'current'
216+ });
217+ return false;
218+ });
219+ }
220+ }
221+ });
222+ this.pad_table_to(5);
223+ }
224+ });
225+ }
226+});
227+
228+
229+
230
231 };
232
233=== added file 'web_treeviewlinks/treeviewlinks_access.py'
234--- web_treeviewlinks/treeviewlinks_access.py 1970-01-01 00:00:00 +0000
235+++ web_treeviewlinks/treeviewlinks_access.py 2014-02-28 12:01:59 +0000
236@@ -0,0 +1,22 @@
237+# -*- coding: utf-8 -*-
238+from osv import osv
239+
240+class treeviewlinks_access(osv.osv_memory):
241+ _name = 'treeviewlinks.access'
242+
243+ def has_group(self, cr, uid, module, group_xml_id, context=None):
244+ """Returns True if current user is a member of the group identified by the module, group_xml_id pair."""
245+ # if the group was deleted or does not exist, we say NO (better safe than sorry)
246+ try:
247+ model, group_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, module, group_xml_id)
248+ except ValueError:
249+ return False
250+ return group_id in self.pool.get('res.users').read(cr, uid, uid, ['groups_id'], context=context)['groups_id']
251+
252+ def authorize(self, cr, uid, context=None):
253+ if self.has_group(cr, uid, module='web_treeviewlinks', group_xml_id='group_treeviewlinks_users', context=context):
254+ return True
255+ else:
256+ return False
257+
258+treeviewlinks_access()

Subscribers

People subscribed via source and target branches