← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~acsone-openerp/web-addons/bug-1303944-sbi into lp:web-addons

 

Stéphane Bidoul (Acsone) has proposed merging lp:~acsone-openerp/web-addons/bug-1303944-sbi into lp:web-addons with lp:~acsone-openerp/web-addons/web_easy_switch_company-userform-fix-sbi as a prerequisite.

Requested reviews:
  Sylvain LE GAL (GRAP) (sylvain-legal)
  Web-Addons Core Editors (webaddons-core-editors)
Related bugs:
  Bug #1303944 in Web addons for OpenERP: "[web_easy_switch_company] ACL / Permissions insufficient for non-admin users"
  https://bugs.launchpad.net/web-addons/+bug/1303944

For more details, see:
https://code.launchpad.net/~acsone-openerp/web-addons/bug-1303944-sbi/+merge/216422

[FIX] web_easy_switch_company: propose the correct companies to non-admin users

Emulate the exact behaviour of the stock user preferences form.
-- 
https://code.launchpad.net/~acsone-openerp/web-addons/bug-1303944-sbi/+merge/216422
Your team Web-Addons Core Editors is requested to review the proposed merge of lp:~acsone-openerp/web-addons/bug-1303944-sbi into lp:web-addons.
=== modified file 'web_easy_switch_company/static/src/js/switch_company.js'
--- web_easy_switch_company/static/src/js/switch_company.js	2014-04-02 09:17:53 +0000
+++ web_easy_switch_company/static/src/js/switch_company.js	2014-04-18 09:38:28 +0000
@@ -92,25 +92,38 @@
         _load_data: function(){
             var self = this;
             // Request for current users information
-            this._fetch('res.users',['company_id','company_ids'],[['id','=',this.session.uid]]).then(function(res_users){
+            this._fetch('res.users',['company_id'],[['id','=',this.session.uid]]).then(function(res_users){
                 self.current_company_id = res_users[0].company_id[0];
                 self.current_company_name = res_users[0].company_id[1];
                 // Request for other companies
-                self._fetch('res.company',['name',],[['id','in', res_users[0].company_ids]]).then(function(res_company){
+                // We have to go through fields_view_get to emulate the
+                // exact (exotic) behavior of the user preferences form in 
+                // fetching the allowed companies wrt record rules.
+                // Note: calling res.company.name_search with 
+                //       user_preference=True in the context does 
+                //       not work either.
+                new instance.web.Model('res.users').call('fields_view_get',{context:{'form_view_ref':'base.view_users_form_simple_modif'}}).then(function(res){
+                    var res_company = res.fields.company_id.selection;
                     for ( var i=0 ; i < res_company.length; i++) {
-                        res_company[i]['logo_topbar'] = self.session.url(
+                        var logo_topbar, logo_state;
+                        logo_topbar = self.session.url(
                             '/web/binary/image', {
                                 model:'res.company', 
                                 field: 'logo_topbar', 
-                                id: res_company[i].id
+                                id: res_company[i][0]
                             });
-                        if (res_company[i].id == self.current_company_id){
-                            res_company[i]['logo_state'] = '/web_easy_switch_company/static/src/img/selection-on.png';
+                        if (res_company[i][0] == self.current_company_id){
+                            logo_state = '/web_easy_switch_company/static/src/img/selection-on.png';
                         }
                         else{
-                            res_company[i]['logo_state'] = '/web_easy_switch_company/static/src/img/selection-off.png';
+                            logo_state = '/web_easy_switch_company/static/src/img/selection-off.png';
                         }
-                        self.companies.push(res_company[i]);
+                        self.companies.push({
+                            id: res_company[i][0],
+                            name: res_company[i][1],
+                            logo_topbar: logo_topbar,
+                            logo_state: logo_state
+                        });
                     }
                     // Update rendering
                     self.renderElement();