credativ team mailing list archive
-
credativ team
-
Mailing list archive
-
Message #05781
[Merge] lp:~matthieuchoplin/credativ-openerp/ERP-701-enable-group-on-treeviewlinks into lp:credativ-openerp
Matthieu Choplin has proposed merging lp:~matthieuchoplin/credativ-openerp/ERP-701-enable-group-on-treeviewlinks into lp:credativ-openerp.
Requested reviews:
credativ (credativ)
For more details, see:
https://code.launchpad.net/~matthieuchoplin/credativ-openerp/ERP-701-enable-group-on-treeviewlinks/+merge/208781
Hello,
this development enables to choose for which group of users we want to enable the treeviewlinks.
--
https://code.launchpad.net/~matthieuchoplin/credativ-openerp/ERP-701-enable-group-on-treeviewlinks/+merge/208781
Your team credativ is requested to review the proposed merge of lp:~matthieuchoplin/credativ-openerp/ERP-701-enable-group-on-treeviewlinks into lp:credativ-openerp.
=== 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 @@
+import treeviewlinks_access
\ No newline at end of file
=== 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 @@
"website" : "http://credativ.co.uk",
"category" : "Tools",
"depends" : ["web"],
+ 'update_xml' : [
+ "security/web_treeviewlinks_security.xml",
+ ],
"js": [
"static/src/js/view_list.js",
],
=== 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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+<data>
+ <record id="group_treeviewlinks_users" model="res.groups">
+ <field name="name">Tree view links Users</field>
+ </record>
+
+</data>
+</openerp>
=== 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 @@
_lt = openerp.web._lt;
var QWeb = openerp.web.qweb;
-openerp.web.ListView.List = openerp.web.ListView.List.extend({
- render: function () {
- var self = this;
- if (this.$current) {
- this.$current.remove();
- }
- this.$current = this.$_element.clone(true);
- this.$current.empty().append(
- QWeb.render('ListView.rows', _.extend({
- render_cell: function () {
- return self.render_cell.apply(self, arguments); }
- }, this)));
- // dodgy hack to get links on things
- this.records.each(function(record){
- var $row = self.$current.find('[data-id=' + record.get('id') + ']');
- for(var i=0, length=self.columns.length; i<length; ++i) {
- if(self.columns[i].type === 'many2one') {
- var $cell = $row.find((_.str.sprintf('[data-field=%s]', self.columns[i].id)));
- $cell.html(_.template('<a class="oe_form_uri" href="#" data-model="<%-model%>" data-id="<%-id%>"><%-text%></a>', {
- text: openerp.web.format_value(record.get(self.columns[i].id), self.columns[i], ''),
- model: self.columns[i].relation,
- id: record.get(self.columns[i].id)[0]
- }));
- $cell.find('a')
- .unbind('click')
- .click(function () {
- var cell = $(this);
- self.group.view.do_action({
- type: 'ir.actions.act_window',
- res_model: cell.attr('data-model'),
- res_id: parseInt(cell.attr('data-id')),
- views: [[false, 'page'], [false, 'form']],
- target: 'current'
- });
- return false;
- });
- }
- }
- });
- this.pad_table_to(5);
- }
-});
-
-openerp.web.form.One2ManyList = openerp.web.ListView.List.extend({
- render: function () {
- var self = this;
- if (this.$current) {
- this.$current.remove();
- }
- this.$current = this.$_element.clone(true);
- this.$current.empty().append(
- QWeb.render('ListView.rows', _.extend({
- render_cell: function () {
- return self.render_cell.apply(self, arguments); }
- }, this)));
- // dodgy hack to get links on things
- this.records.each(function(record){
- var $row = self.$current.find('[data-id=' + record.get('id') + ']');
- for(var i=0, length=self.columns.length; i<length; ++i) {
- if(self.columns[i].type === 'many2one') {
- var $cell = $row.find((_.str.sprintf('[data-field=%s]', self.columns[i].id)));
- $cell.html(_.template('<a class="oe_form_uri" href="#" data-model="<%-model%>" data-id="<%-id%>"><%-text%></a>', {
- text: openerp.web.format_value(record.get(self.columns[i].id), self.columns[i], ''),
- model: self.columns[i].relation,
- id: record.get(self.columns[i].id)[0]
- }));
- $cell.find('a')
- .unbind('click')
- .click(function () {
- var cell = $(this);
- self.group.view.do_action({
- type: 'ir.actions.act_window',
- res_model: cell.attr('data-model'),
- res_id: parseInt(cell.attr('data-id')),
- views: [[false, 'page'], [false, 'form']],
- target: 'current'
- });
- return false;
- });
- }
- }
- });
- this.pad_table_to(5);
- }
-});
+function authorize(have_access) {
+ var func = new openerp.web.Model("treeviewlinks.access").get_func("authorize");
+ func(openerp.connection.uid).pipe(function(res) {
+ have_access(res);
+ });
+}
+
+authorize(function(res){
+ // if the current user is in the group "Right Panel Users"
+ console.log(res, arguments);
+ if ( res ) {
+ openerp.web.ListView.List = openerp.web.ListView.List.extend({
+ render: function () {
+ var self = this;
+ if (this.$current) {
+ this.$current.remove();
+ }
+ this.$current = this.$_element.clone(true);
+ this.$current.empty().append(
+ QWeb.render('ListView.rows', _.extend({
+ render_cell: function () {
+ return self.render_cell.apply(self, arguments); }
+ }, this)));
+ // dodgy hack to get links on things
+ this.records.each(function(record){
+ var $row = self.$current.find('[data-id=' + record.get('id') + ']');
+ for(var i=0, length=self.columns.length; i<length; ++i) {
+ if(self.columns[i].type === 'many2one') {
+ var $cell = $row.find((_.str.sprintf('[data-field=%s]', self.columns[i].id)));
+ $cell.html(_.template('<a class="oe_form_uri" href="#" data-model="<%-model%>" data-id="<%-id%>"><%-text%></a>', {
+ text: openerp.web.format_value(record.get(self.columns[i].id), self.columns[i], ''),
+ model: self.columns[i].relation,
+ id: record.get(self.columns[i].id)[0]
+ }));
+ $cell.find('a')
+ .unbind('click')
+ .click(function () {
+ var cell = $(this);
+ self.group.view.do_action({
+ type: 'ir.actions.act_window',
+ res_model: cell.attr('data-model'),
+ res_id: parseInt(cell.attr('data-id')),
+ views: [[false, 'page'], [false, 'form']],
+ target: 'current'
+ });
+ return false;
+ });
+ }
+ }
+ });
+ this.pad_table_to(5);
+ }
+ });
+
+ openerp.web.form.One2ManyList = openerp.web.ListView.List.extend({
+ render: function () {
+ var self = this;
+ if (this.$current) {
+ this.$current.remove();
+ }
+ this.$current = this.$_element.clone(true);
+ this.$current.empty().append(
+ QWeb.render('ListView.rows', _.extend({
+ render_cell: function () {
+ return self.render_cell.apply(self, arguments); }
+ }, this)));
+ // dodgy hack to get links on things
+ this.records.each(function(record){
+ var $row = self.$current.find('[data-id=' + record.get('id') + ']');
+ for(var i=0, length=self.columns.length; i<length; ++i) {
+ if(self.columns[i].type === 'many2one') {
+ var $cell = $row.find((_.str.sprintf('[data-field=%s]', self.columns[i].id)));
+ $cell.html(_.template('<a class="oe_form_uri" href="#" data-model="<%-model%>" data-id="<%-id%>"><%-text%></a>', {
+ text: openerp.web.format_value(record.get(self.columns[i].id), self.columns[i], ''),
+ model: self.columns[i].relation,
+ id: record.get(self.columns[i].id)[0]
+ }));
+ $cell.find('a')
+ .unbind('click')
+ .click(function () {
+ var cell = $(this);
+ self.group.view.do_action({
+ type: 'ir.actions.act_window',
+ res_model: cell.attr('data-model'),
+ res_id: parseInt(cell.attr('data-id')),
+ views: [[false, 'page'], [false, 'form']],
+ target: 'current'
+ });
+ return false;
+ });
+ }
+ }
+ });
+ this.pad_table_to(5);
+ }
+ });
+ }
+});
+
+
+
};
=== 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 @@
+# -*- coding: utf-8 -*-
+from osv import osv
+
+class treeviewlinks_access(osv.osv_memory):
+ _name = 'treeviewlinks.access'
+
+ def has_group(self, cr, uid, module, group_xml_id, context=None):
+ """Returns True if current user is a member of the group identified by the module, group_xml_id pair."""
+ # if the group was deleted or does not exist, we say NO (better safe than sorry)
+ try:
+ model, group_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, module, group_xml_id)
+ except ValueError:
+ return False
+ return group_id in self.pool.get('res.users').read(cr, uid, uid, ['groups_id'], context=context)['groups_id']
+
+ def authorize(self, cr, uid, context=None):
+ if self.has_group(cr, uid, module='web_treeviewlinks', group_xml_id='group_treeviewlinks_users', context=context):
+ return True
+ else:
+ return False
+
+treeviewlinks_access()