From 246710faa4cbabe5618598e55e6e0e5da9aba335 Mon Sep 17 00:00:00 2001 From: KKamaa Date: Tue, 31 Jan 2023 05:05:30 +0300 Subject: [PATCH] [14.0][FIX] #3039 support_branding ACL bug --- support_branding/models/__init__.py | 2 + support_branding/models/res_company.py | 29 ++++++++++++ .../static/src/js/res_config_edition.js | 12 ++--- .../static/src/js/support_branding.js | 20 ++++---- support_branding/static/src/js/user_menu.js | 4 +- support_branding/tests/__init__.py | 8 ++++ .../tests/test_support_branding.py | 46 +++++++++++++++++++ 7 files changed, 103 insertions(+), 18 deletions(-) create mode 100644 support_branding/models/res_company.py create mode 100644 support_branding/tests/__init__.py create mode 100644 support_branding/tests/test_support_branding.py diff --git a/support_branding/models/__init__.py b/support_branding/models/__init__.py index 4124bd743..97359ec5c 100644 --- a/support_branding/models/__init__.py +++ b/support_branding/models/__init__.py @@ -2,3 +2,5 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import res_config_settings +from . import res_company + diff --git a/support_branding/models/res_company.py b/support_branding/models/res_company.py new file mode 100644 index 000000000..bc315e381 --- /dev/null +++ b/support_branding/models/res_company.py @@ -0,0 +1,29 @@ +# Copyright 2023 Sunflower IT +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import logging + +from odoo import models, api + +_logger = logging.getLogger(__name__) + + +class ResCompany(models.Model): + _inherit = 'res.company' + + @api.model + def get_ir_config_param_data(self, key): + try: + self.env.cr.execute("select value from ir_config_parameter where " + "key='%s';" % key) + res = self.env.cr.fetchone() + except Exception as e: + _logger.error('\n\n ERROR: %s \n\n', e) + return '' + else: + if res: + return '%s' % res + return '' + + + diff --git a/support_branding/static/src/js/res_config_edition.js b/support_branding/static/src/js/res_config_edition.js index 48ac99cc3..716576804 100644 --- a/support_branding/static/src/js/res_config_edition.js +++ b/support_branding/static/src/js/res_config_edition.js @@ -7,22 +7,22 @@ odoo.define("support_branding.ResConfigEdition", function (require) { willStart: function () { var self = this; var def_1 = this._rpc({ - model: "ir.config_parameter", - method: "get_param", + model: "res.company", + method: "_get_support_branding_vals", args: ["support_company"], }).then(function (name) { self.support_cp_name = name; }); var def_2 = this._rpc({ - model: "ir.config_parameter", - method: "get_param", + model: "res.company", + method: "_get_support_branding_vals", args: ["support_company_url"], }).then(function (url) { self.support_cp_url = url; }); var def_3 = this._rpc({ - model: "ir.config_parameter", - method: "get_param", + model: "res.company", + method: "_get_support_branding_vals", args: ["support_email"], }).then(function (email) { self.support_cp_email = email; diff --git a/support_branding/static/src/js/support_branding.js b/support_branding/static/src/js/support_branding.js index 95db62a55..e86e5a572 100644 --- a/support_branding/static/src/js/support_branding.js +++ b/support_branding/static/src/js/support_branding.js @@ -19,40 +19,40 @@ odoo.define("support_branding.CrashManager", function (require) { var self = this; $.when(this._super.apply(this, arguments)).then(function () { self._rpc({ - model: "ir.config_parameter", - method: "get_param", + model: "res.company", + method: "get_ir_config_param_data", args: ["support_company"], }).then(function (name) { self.support_cp_name = name; }); self._rpc({ - model: "ir.config_parameter", - method: "get_param", + model: "res.company", + method: "get_ir_config_param_data", args: ["support_company_url"], }).then(function (url) { self.support_cp_url = url; }); self._rpc({ - model: "ir.config_parameter", - method: "get_param", + model: "res.company", + method: "get_ir_config_param_data", args: ["support_email"], }).then(function (email) { self.support_cp_email = email; }); self._rpc({ - model: "ir.config_parameter", - method: "get_param", + model: "res.company", + method: "get_ir_config_param_data", args: ["support_release"], }).then(function (release) { self.support_cp_release = release; }); self._rpc({ - model: "ir.config_parameter", - method: "get_param", + model: "res.company", + method: "get_ir_config_param_data", args: ["support_branding_color"], }).then(function (color) { self.support_cp_color = color; diff --git a/support_branding/static/src/js/user_menu.js b/support_branding/static/src/js/user_menu.js index f0c76ba45..bee36e532 100644 --- a/support_branding/static/src/js/user_menu.js +++ b/support_branding/static/src/js/user_menu.js @@ -12,8 +12,8 @@ odoo.define("support_branding.UserMenu", function (require) { var self = this; var def = self ._rpc({ - model: "ir.config_parameter", - method: "get_param", + model: "res.company", + method: "get_ir_config_param_data", args: ["support_company_url"], }) .then(function (site) { diff --git a/support_branding/tests/__init__.py b/support_branding/tests/__init__.py new file mode 100644 index 000000000..115114ba9 --- /dev/null +++ b/support_branding/tests/__init__.py @@ -0,0 +1,8 @@ +# Copyright 2023 Sunflower IT +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_support_branding + + + + diff --git a/support_branding/tests/test_support_branding.py b/support_branding/tests/test_support_branding.py new file mode 100644 index 000000000..506bc206c --- /dev/null +++ b/support_branding/tests/test_support_branding.py @@ -0,0 +1,46 @@ +# Copyright 2023 Sunflower IT +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase +from odoo.exceptions import AccessError + + +class TestSupportBranding(TransactionCase): + def setUp(self): + super(TestSupportBranding, self).setUp() + self.company_obj = self.env['res.company'] + self.ir_config_obj = self.env['ir.config_parameter'].sudo() + self.demo_user = self.env.ref('base.user_demo') + self.admin_user = self.env.ref('base.user_admin') + self.demo_support_branding_company_name = self.env.ref( + 'support_branding.demo_config_parameter_company_name') + self.demo_support_company_branding_url = self.env.ref( + 'support_branding.demo_config_parameter_company_url') + + def test_fetch_support_branding_vals_from_res_company(self): + + # Check if demo user is able to access. + # NB: ir.config_parameter model requires admin access rights. + with self.assertRaises(AccessError): + self.ir_config_obj.with_user(self.demo_user).get_param( + self.demo_support_company_branding_url.key) + + value = self.company_obj.with_user(self.demo_user) \ + .get_ir_config_param_data( + self.demo_support_company_branding_url.key) + + self.assertEquals(value, self.demo_support_company_branding_url.value) + + # Check if admin user is able to access + # admin has access all through + value_1 = self.company_obj.with_user(self.admin_user) \ + .get_ir_config_param_data( + self.demo_support_company_branding_url.key) + value_2 = self.company_obj.with_user(self.admin_user) \ + .get_ir_config_param_data( + self.demo_support_company_branding_url.key) + self.assertEquals(value_1, value_2) + self.assertEquals(value_1, self.demo_support_company_branding_url.value) + self.assertEquals(value_2, self.demo_support_company_branding_url.value) + +