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
=== modified file 'web_treeviewlinks/__init__.py'
--- web_treeviewlinks/__init__.py 2012-08-02 15:21:19 +0000
+++ web_treeviewlinks/__init__.py 2014-02-28 12:01:59 +0000
@@ -0,0 +1,1 @@
1import treeviewlinks_access
0\ No newline at end of file2\ No newline at end of file
13
=== modified file 'web_treeviewlinks/__openerp__.py'
--- web_treeviewlinks/__openerp__.py 2012-08-02 15:21:19 +0000
+++ web_treeviewlinks/__openerp__.py 2014-02-28 12:01:59 +0000
@@ -29,6 +29,9 @@
29 "website" : "http://credativ.co.uk",29 "website" : "http://credativ.co.uk",
30 "category" : "Tools",30 "category" : "Tools",
31 "depends" : ["web"],31 "depends" : ["web"],
32 'update_xml' : [
33 "security/web_treeviewlinks_security.xml",
34 ],
32 "js": [35 "js": [
33 "static/src/js/view_list.js",36 "static/src/js/view_list.js",
34 ],37 ],
3538
=== added directory 'web_treeviewlinks/security'
=== added file 'web_treeviewlinks/security/web_treeviewlinks_security.xml'
--- web_treeviewlinks/security/web_treeviewlinks_security.xml 1970-01-01 00:00:00 +0000
+++ web_treeviewlinks/security/web_treeviewlinks_security.xml 2014-02-28 12:01:59 +0000
@@ -0,0 +1,9 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3<data>
4 <record id="group_treeviewlinks_users" model="res.groups">
5 <field name="name">Tree view links Users</field>
6 </record>
7
8</data>
9</openerp>
010
=== modified file 'web_treeviewlinks/static/src/js/view_list.js'
--- web_treeviewlinks/static/src/js/view_list.js 2012-08-16 10:57:41 +0000
+++ web_treeviewlinks/static/src/js/view_list.js 2014-02-28 12:01:59 +0000
@@ -3,90 +3,106 @@
3 _lt = openerp.web._lt;3 _lt = openerp.web._lt;
4 var QWeb = openerp.web.qweb;4 var QWeb = openerp.web.qweb;
55
6openerp.web.ListView.List = openerp.web.ListView.List.extend({6function authorize(have_access) {
7 render: function () {7 var func = new openerp.web.Model("treeviewlinks.access").get_func("authorize");
8 var self = this;8 func(openerp.connection.uid).pipe(function(res) {
9 if (this.$current) {9 have_access(res);
10 this.$current.remove();10 });
11 }11}
12 this.$current = this.$_element.clone(true);12
13 this.$current.empty().append(13authorize(function(res){
14 QWeb.render('ListView.rows', _.extend({14 // if the current user is in the group "Right Panel Users"
15 render_cell: function () {15 console.log(res, arguments);
16 return self.render_cell.apply(self, arguments); }16 if ( res ) {
17 }, this)));17 openerp.web.ListView.List = openerp.web.ListView.List.extend({
18 // dodgy hack to get links on things18 render: function () {
19 this.records.each(function(record){19 var self = this;
20 var $row = self.$current.find('[data-id=' + record.get('id') + ']');20 if (this.$current) {
21 for(var i=0, length=self.columns.length; i<length; ++i) {21 this.$current.remove();
22 if(self.columns[i].type === 'many2one') {22 }
23 var $cell = $row.find((_.str.sprintf('[data-field=%s]', self.columns[i].id)));23 this.$current = this.$_element.clone(true);
24 $cell.html(_.template('<a class="oe_form_uri" href="#" data-model="<%-model%>" data-id="<%-id%>"><%-text%></a>', {24 this.$current.empty().append(
25 text: openerp.web.format_value(record.get(self.columns[i].id), self.columns[i], ''),25 QWeb.render('ListView.rows', _.extend({
26 model: self.columns[i].relation,26 render_cell: function () {
27 id: record.get(self.columns[i].id)[0]27 return self.render_cell.apply(self, arguments); }
28 }));28 }, this)));
29 $cell.find('a')29 // dodgy hack to get links on things
30 .unbind('click')30 this.records.each(function(record){
31 .click(function () {31 var $row = self.$current.find('[data-id=' + record.get('id') + ']');
32 var cell = $(this);32 for(var i=0, length=self.columns.length; i<length; ++i) {
33 self.group.view.do_action({33 if(self.columns[i].type === 'many2one') {
34 type: 'ir.actions.act_window',34 var $cell = $row.find((_.str.sprintf('[data-field=%s]', self.columns[i].id)));
35 res_model: cell.attr('data-model'),35 $cell.html(_.template('<a class="oe_form_uri" href="#" data-model="<%-model%>" data-id="<%-id%>"><%-text%></a>', {
36 res_id: parseInt(cell.attr('data-id')),36 text: openerp.web.format_value(record.get(self.columns[i].id), self.columns[i], ''),
37 views: [[false, 'page'], [false, 'form']],37 model: self.columns[i].relation,
38 target: 'current'38 id: record.get(self.columns[i].id)[0]
39 });39 }));
40 return false;40 $cell.find('a')
41 });41 .unbind('click')
42 }42 .click(function () {
43 }43 var cell = $(this);
44 });44 self.group.view.do_action({
45 this.pad_table_to(5);45 type: 'ir.actions.act_window',
46 }46 res_model: cell.attr('data-model'),
47});47 res_id: parseInt(cell.attr('data-id')),
4848 views: [[false, 'page'], [false, 'form']],
49openerp.web.form.One2ManyList = openerp.web.ListView.List.extend({49 target: 'current'
50 render: function () {50 });
51 var self = this;51 return false;
52 if (this.$current) {52 });
53 this.$current.remove();53 }
54 }54 }
55 this.$current = this.$_element.clone(true);55 });
56 this.$current.empty().append(56 this.pad_table_to(5);
57 QWeb.render('ListView.rows', _.extend({57 }
58 render_cell: function () {58 });
59 return self.render_cell.apply(self, arguments); }59
60 }, this)));60 openerp.web.form.One2ManyList = openerp.web.ListView.List.extend({
61 // dodgy hack to get links on things61 render: function () {
62 this.records.each(function(record){62 var self = this;
63 var $row = self.$current.find('[data-id=' + record.get('id') + ']');63 if (this.$current) {
64 for(var i=0, length=self.columns.length; i<length; ++i) {64 this.$current.remove();
65 if(self.columns[i].type === 'many2one') {65 }
66 var $cell = $row.find((_.str.sprintf('[data-field=%s]', self.columns[i].id)));66 this.$current = this.$_element.clone(true);
67 $cell.html(_.template('<a class="oe_form_uri" href="#" data-model="<%-model%>" data-id="<%-id%>"><%-text%></a>', {67 this.$current.empty().append(
68 text: openerp.web.format_value(record.get(self.columns[i].id), self.columns[i], ''),68 QWeb.render('ListView.rows', _.extend({
69 model: self.columns[i].relation,69 render_cell: function () {
70 id: record.get(self.columns[i].id)[0]70 return self.render_cell.apply(self, arguments); }
71 }));71 }, this)));
72 $cell.find('a')72 // dodgy hack to get links on things
73 .unbind('click')73 this.records.each(function(record){
74 .click(function () {74 var $row = self.$current.find('[data-id=' + record.get('id') + ']');
75 var cell = $(this);75 for(var i=0, length=self.columns.length; i<length; ++i) {
76 self.group.view.do_action({76 if(self.columns[i].type === 'many2one') {
77 type: 'ir.actions.act_window',77 var $cell = $row.find((_.str.sprintf('[data-field=%s]', self.columns[i].id)));
78 res_model: cell.attr('data-model'),78 $cell.html(_.template('<a class="oe_form_uri" href="#" data-model="<%-model%>" data-id="<%-id%>"><%-text%></a>', {
79 res_id: parseInt(cell.attr('data-id')),79 text: openerp.web.format_value(record.get(self.columns[i].id), self.columns[i], ''),
80 views: [[false, 'page'], [false, 'form']],80 model: self.columns[i].relation,
81 target: 'current'81 id: record.get(self.columns[i].id)[0]
82 });82 }));
83 return false;83 $cell.find('a')
84 });84 .unbind('click')
85 }85 .click(function () {
86 }86 var cell = $(this);
87 });87 self.group.view.do_action({
88 this.pad_table_to(5);88 type: 'ir.actions.act_window',
89 }89 res_model: cell.attr('data-model'),
90});90 res_id: parseInt(cell.attr('data-id')),
91 views: [[false, 'page'], [false, 'form']],
92 target: 'current'
93 });
94 return false;
95 });
96 }
97 }
98 });
99 this.pad_table_to(5);
100 }
101 });
102 }
103});
104
105
106
91107
92};108};
93109
=== added file 'web_treeviewlinks/treeviewlinks_access.py'
--- web_treeviewlinks/treeviewlinks_access.py 1970-01-01 00:00:00 +0000
+++ web_treeviewlinks/treeviewlinks_access.py 2014-02-28 12:01:59 +0000
@@ -0,0 +1,22 @@
1# -*- coding: utf-8 -*-
2from osv import osv
3
4class treeviewlinks_access(osv.osv_memory):
5 _name = 'treeviewlinks.access'
6
7 def has_group(self, cr, uid, module, group_xml_id, context=None):
8 """Returns True if current user is a member of the group identified by the module, group_xml_id pair."""
9 # if the group was deleted or does not exist, we say NO (better safe than sorry)
10 try:
11 model, group_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, module, group_xml_id)
12 except ValueError:
13 return False
14 return group_id in self.pool.get('res.users').read(cr, uid, uid, ['groups_id'], context=context)['groups_id']
15
16 def authorize(self, cr, uid, context=None):
17 if self.has_group(cr, uid, module='web_treeviewlinks', group_xml_id='group_treeviewlinks_users', context=context):
18 return True
19 else:
20 return False
21
22treeviewlinks_access()

Subscribers

People subscribed via source and target branches