From 246710faa4cbabe5618598e55e6e0e5da9aba335 Mon Sep 17 00:00:00 2001 From: KKamaa Date: Tue, 31 Jan 2023 05:05:30 +0300 Subject: [PATCH 1/9] [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) + + From 44c66fecb54aaca63467830e0973412bdd8ac391 Mon Sep 17 00:00:00 2001 From: KKamaa Date: Tue, 31 Jan 2023 05:22:24 +0300 Subject: [PATCH 2/9] [UPD] black,isort,prettier --- support_branding/models/__init__.py | 1 - support_branding/models/res_company.py | 20 +++++----- support_branding/tests/__init__.py | 4 -- .../tests/test_support_branding.py | 39 ++++++++++--------- 4 files changed, 29 insertions(+), 35 deletions(-) diff --git a/support_branding/models/__init__.py b/support_branding/models/__init__.py index 97359ec5c..c873322e0 100644 --- a/support_branding/models/__init__.py +++ b/support_branding/models/__init__.py @@ -3,4 +3,3 @@ 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 index bc315e381..6fac976df 100644 --- a/support_branding/models/res_company.py +++ b/support_branding/models/res_company.py @@ -3,27 +3,25 @@ import logging -from odoo import models, api +from odoo import api, models _logger = logging.getLogger(__name__) class ResCompany(models.Model): - _inherit = 'res.company' + _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) + 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 '' + _logger.error("\n\n ERROR: %s \n\n", e) + return "" else: if res: - return '%s' % res - return '' - - - + return "%s" % res + return "" diff --git a/support_branding/tests/__init__.py b/support_branding/tests/__init__.py index 115114ba9..1a36f0c42 100644 --- a/support_branding/tests/__init__.py +++ b/support_branding/tests/__init__.py @@ -2,7 +2,3 @@ # 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 index 506bc206c..048f76f85 100644 --- a/support_branding/tests/test_support_branding.py +++ b/support_branding/tests/test_support_branding.py @@ -1,21 +1,23 @@ # 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 +from odoo.tests.common import TransactionCase 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.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') + "support_branding.demo_config_parameter_company_name" + ) self.demo_support_company_branding_url = self.env.ref( - 'support_branding.demo_config_parameter_company_url') + "support_branding.demo_config_parameter_company_url" + ) def test_fetch_support_branding_vals_from_res_company(self): @@ -23,24 +25,23 @@ class TestSupportBranding(TransactionCase): # 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) + 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) + 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) + 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) - - From fcaf19d858eb6419ca103a6c8d94b4ac2657cb00 Mon Sep 17 00:00:00 2001 From: KKamaa Date: Tue, 31 Jan 2023 05:55:00 +0300 Subject: [PATCH 3/9] [FIX] check for invalid key --- support_branding/models/res_company.py | 10 +++------- support_branding/tests/test_support_branding.py | 14 +++++++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/support_branding/models/res_company.py b/support_branding/models/res_company.py index 6fac976df..d7d2dccc2 100644 --- a/support_branding/models/res_company.py +++ b/support_branding/models/res_company.py @@ -1,11 +1,8 @@ # Copyright 2023 Sunflower IT # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -import logging - -from odoo import api, models - -_logger = logging.getLogger(__name__) +from odoo import _, api, models +from odoo.exceptions import UserError class ResCompany(models.Model): @@ -19,8 +16,7 @@ class ResCompany(models.Model): ) res = self.env.cr.fetchone() except Exception as e: - _logger.error("\n\n ERROR: %s \n\n", e) - return "" + raise UserError(_("Error: %s" % e)) else: if res: return "%s" % res diff --git a/support_branding/tests/test_support_branding.py b/support_branding/tests/test_support_branding.py index 048f76f85..2eccc5847 100644 --- a/support_branding/tests/test_support_branding.py +++ b/support_branding/tests/test_support_branding.py @@ -1,7 +1,7 @@ # Copyright 2023 Sunflower IT # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo.exceptions import AccessError +from odoo.exceptions import AccessError, UserError from odoo.tests.common import TransactionCase @@ -45,3 +45,15 @@ class TestSupportBranding(TransactionCase): 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) + + # check if return if key is invalid + empty_val = self.company_obj.with_user( + self.admin_user + ).get_ir_config_param_data("testing") + self.assertEquals(empty_val, "") + + # check if return of key if invalid + with self.assertRaises(UserError): + empty_val = self.company_obj.with_user( + self.admin_user + ).get_ir_config_param_data(True) From 7553f530aac1b67c1434c3ae58e2110138710f11 Mon Sep 17 00:00:00 2001 From: KKamaa Date: Mon, 6 Feb 2023 18:56:27 +0300 Subject: [PATCH 4/9] [FIX] allow group users --- support_branding/models/res_company.py | 10 +++++++++- support_branding/static/src/js/res_config_edition.js | 6 +++--- support_branding/tests/test_support_branding.py | 7 +++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/support_branding/models/res_company.py b/support_branding/models/res_company.py index d7d2dccc2..670598e4c 100644 --- a/support_branding/models/res_company.py +++ b/support_branding/models/res_company.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo import _, api, models -from odoo.exceptions import UserError +from odoo.exceptions import AccessError, UserError class ResCompany(models.Model): @@ -10,6 +10,14 @@ class ResCompany(models.Model): @api.model def get_ir_config_param_data(self, key): + if not self.env.user.has_group("base.group_user"): + raise AccessError( + _( + "You are not allowed to access this " + "functionality, please contact Admin for " + "more support" + ) + ) try: self.env.cr.execute( "select value from ir_config_parameter where " "key=(%s);", (key,) diff --git a/support_branding/static/src/js/res_config_edition.js b/support_branding/static/src/js/res_config_edition.js index 716576804..0db5961cb 100644 --- a/support_branding/static/src/js/res_config_edition.js +++ b/support_branding/static/src/js/res_config_edition.js @@ -8,21 +8,21 @@ odoo.define("support_branding.ResConfigEdition", function (require) { var self = this; var def_1 = this._rpc({ model: "res.company", - method: "_get_support_branding_vals", + method: "get_ir_config_param_data", args: ["support_company"], }).then(function (name) { self.support_cp_name = name; }); var def_2 = this._rpc({ model: "res.company", - method: "_get_support_branding_vals", + method: "get_ir_config_param_data", args: ["support_company_url"], }).then(function (url) { self.support_cp_url = url; }); var def_3 = this._rpc({ model: "res.company", - method: "_get_support_branding_vals", + method: "get_ir_config_param_data", args: ["support_email"], }).then(function (email) { self.support_cp_email = email; diff --git a/support_branding/tests/test_support_branding.py b/support_branding/tests/test_support_branding.py index 2eccc5847..c836d596c 100644 --- a/support_branding/tests/test_support_branding.py +++ b/support_branding/tests/test_support_branding.py @@ -12,6 +12,7 @@ class TestSupportBranding(TransactionCase): 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.portal_user = self.env.ref("base.demo_user0") self.demo_support_branding_company_name = self.env.ref( "support_branding.demo_config_parameter_company_name" ) @@ -21,6 +22,12 @@ class TestSupportBranding(TransactionCase): def test_fetch_support_branding_vals_from_res_company(self): + # Check if user has the right access rights e.g. portal user not allowed + with self.assertRaises(AccessError): + self.ir_config_obj.with_user(self.portal_user).get_param( + self.demo_support_company_branding_url.key + ) + # Check if demo user is able to access. # NB: ir.config_parameter model requires admin access rights. with self.assertRaises(AccessError): From ac624eb7fc9641aa12dea3a2ee953835ab9e4fac Mon Sep 17 00:00:00 2001 From: KKamaa Date: Thu, 9 Feb 2023 01:26:44 +0300 Subject: [PATCH 5/9] [FIX] use key/value pair for support branding --- support_branding/models/res_company.py | 35 ++++++------- .../static/src/js/res_config_edition.js | 35 ++++++------- .../static/src/js/support_branding.js | 50 ++++++------------- support_branding/static/src/js/user_menu.js | 11 ++-- .../tests/test_support_branding.py | 41 ++++++--------- 5 files changed, 65 insertions(+), 107 deletions(-) diff --git a/support_branding/models/res_company.py b/support_branding/models/res_company.py index 670598e4c..ab7ecee42 100644 --- a/support_branding/models/res_company.py +++ b/support_branding/models/res_company.py @@ -2,30 +2,23 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo import _, api, models -from odoo.exceptions import AccessError, UserError +from odoo.exceptions import UserError, AccessError class ResCompany(models.Model): _inherit = "res.company" @api.model - def get_ir_config_param_data(self, key): - if not self.env.user.has_group("base.group_user"): - raise AccessError( - _( - "You are not allowed to access this " - "functionality, please contact Admin for " - "more support" - ) - ) - try: - self.env.cr.execute( - "select value from ir_config_parameter where " "key=(%s);", (key,) - ) - res = self.env.cr.fetchone() - except Exception as e: - raise UserError(_("Error: %s" % e)) - else: - if res: - return "%s" % res - return "" + def get_support_branding_config_param_data(self): + if not self.env.user.has_group('base.group_user'): + raise AccessError(_('You are not allowed to access this ' + 'functionality, please contact Admin for ' + 'more support')) + self.env.cr.execute( + "select key, value from ir_config_parameter where key ilike " + "'%support_%';" + ) + res = self.env.cr.dictfetchall() + if any(res): + support_vals = {x['key']: x['value'] for x in res} + return support_vals diff --git a/support_branding/static/src/js/res_config_edition.js b/support_branding/static/src/js/res_config_edition.js index 0db5961cb..cabe19aa7 100644 --- a/support_branding/static/src/js/res_config_edition.js +++ b/support_branding/static/src/js/res_config_edition.js @@ -8,26 +8,23 @@ odoo.define("support_branding.ResConfigEdition", function (require) { var self = this; var def_1 = this._rpc({ model: "res.company", - method: "get_ir_config_param_data", - args: ["support_company"], - }).then(function (name) { - self.support_cp_name = name; + method: "get_support_branding_config_param_data", + args: [], + }).then(function (result) { + if (result && 'support_company' in result) + self.support_cp_name = result['support_company']; + if (result && 'support_company_url' in result) + self.support_cp_url = result['support_company_url']; + if (result && 'support_email' in result) + self.support_cp_email = result['support_email']; + if (result && 'support_release' in result) + self.support_cp_release = result['support_release']; + if (result && 'support_branding_color' in result) + self.support_branding_color = result[ + 'support_branding_color']; }); - var def_2 = this._rpc({ - model: "res.company", - method: "get_ir_config_param_data", - args: ["support_company_url"], - }).then(function (url) { - self.support_cp_url = url; - }); - var def_3 = this._rpc({ - model: "res.company", - method: "get_ir_config_param_data", - args: ["support_email"], - }).then(function (email) { - self.support_cp_email = email; - }); - return $.when(this._super.apply(this, arguments), def_1, def_2, def_3); + + return $.when(this._super.apply(this, arguments), def_1); }, }); }); diff --git a/support_branding/static/src/js/support_branding.js b/support_branding/static/src/js/support_branding.js index e86e5a572..702c73820 100644 --- a/support_branding/static/src/js/support_branding.js +++ b/support_branding/static/src/js/support_branding.js @@ -20,42 +20,20 @@ odoo.define("support_branding.CrashManager", function (require) { $.when(this._super.apply(this, arguments)).then(function () { self._rpc({ model: "res.company", - method: "get_ir_config_param_data", - args: ["support_company"], - }).then(function (name) { - self.support_cp_name = name; - }); - - self._rpc({ - model: "res.company", - method: "get_ir_config_param_data", - args: ["support_company_url"], - }).then(function (url) { - self.support_cp_url = url; - }); - - self._rpc({ - model: "res.company", - method: "get_ir_config_param_data", - args: ["support_email"], - }).then(function (email) { - self.support_cp_email = email; - }); - - self._rpc({ - model: "res.company", - method: "get_ir_config_param_data", - args: ["support_release"], - }).then(function (release) { - self.support_cp_release = release; - }); - - self._rpc({ - model: "res.company", - method: "get_ir_config_param_data", - args: ["support_branding_color"], - }).then(function (color) { - self.support_cp_color = color; + method: "get_support_branding_config_param_data", + args: [], + }).then(function (result) { + if (result && 'support_company' in result) + self.support_cp_name = result['support_company']; + if (result && 'support_company_url' in result) + self.support_cp_url = result['support_company_url']; + if (result && 'support_email' in result) + self.support_cp_email = result['support_email']; + if (result && 'support_release' in result) + self.support_cp_release = result['support_release']; + if (result && 'support_branding_color' in result) + self.support_branding_color = result[ + 'support_branding_color']; }); }); }, diff --git a/support_branding/static/src/js/user_menu.js b/support_branding/static/src/js/user_menu.js index bee36e532..118d3834c 100644 --- a/support_branding/static/src/js/user_menu.js +++ b/support_branding/static/src/js/user_menu.js @@ -13,12 +13,13 @@ odoo.define("support_branding.UserMenu", function (require) { var def = self ._rpc({ model: "res.company", - method: "get_ir_config_param_data", - args: ["support_company_url"], + method: "get_support_branding_config_param_data", + args: [], }) - .then(function (site) { - if (site && site !== "") { - self.support_url = site; + .then(function (result) { + if (result && 'support_company_url' in result && + result['support_company_url'] !== "") { + self.support_url = result['support_company_url']; } }); return $.when(this._super.apply(this, arguments), def); diff --git a/support_branding/tests/test_support_branding.py b/support_branding/tests/test_support_branding.py index c836d596c..1cbd0ea7c 100644 --- a/support_branding/tests/test_support_branding.py +++ b/support_branding/tests/test_support_branding.py @@ -25,42 +25,31 @@ class TestSupportBranding(TransactionCase): # Check if user has the right access rights e.g. portal user not allowed with self.assertRaises(AccessError): self.ir_config_obj.with_user(self.portal_user).get_param( - self.demo_support_company_branding_url.key + self.demo_support_branding_company_name.key ) # 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 + self.demo_support_branding_company_name.key ) - value = self.company_obj.with_user(self.demo_user).get_ir_config_param_data( - self.demo_support_company_branding_url.key - ) + vals = self.company_obj.with_user( + self.demo_user).get_support_branding_config_param_data() - self.assertEquals(value, self.demo_support_company_branding_url.value) + self.assertEquals(vals['support_company'], + self.demo_support_branding_company_name.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) + vals_1 = self.company_obj.with_user( + self.admin_user).get_support_branding_config_param_data() + vals_2 = self.company_obj.with_user( + self.admin_user).get_support_branding_config_param_data() + self.assertEquals(vals_1, vals_2) + self.assertEquals(vals_1['support_company_url'], + self.demo_support_company_branding_url.value) + self.assertEquals(vals_2['support_company_url'], + self.demo_support_company_branding_url.value) - # check if return if key is invalid - empty_val = self.company_obj.with_user( - self.admin_user - ).get_ir_config_param_data("testing") - self.assertEquals(empty_val, "") - - # check if return of key if invalid - with self.assertRaises(UserError): - empty_val = self.company_obj.with_user( - self.admin_user - ).get_ir_config_param_data(True) From 956d67fca8c5fca850544f19394e5b12ec44212f Mon Sep 17 00:00:00 2001 From: KKamaa Date: Thu, 9 Feb 2023 01:29:54 +0300 Subject: [PATCH 6/9] [UPD] isort,prettier,black --- support_branding/models/res_company.py | 20 ++++++++------ .../static/src/js/res_config_edition.js | 21 +++++++-------- .../static/src/js/support_branding.js | 21 +++++++-------- support_branding/static/src/js/user_menu.js | 9 ++++--- .../tests/test_support_branding.py | 27 +++++++++++-------- 5 files changed, 54 insertions(+), 44 deletions(-) diff --git a/support_branding/models/res_company.py b/support_branding/models/res_company.py index ab7ecee42..34d94bd5a 100644 --- a/support_branding/models/res_company.py +++ b/support_branding/models/res_company.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo import _, api, models -from odoo.exceptions import UserError, AccessError +from odoo.exceptions import AccessError class ResCompany(models.Model): @@ -10,15 +10,19 @@ class ResCompany(models.Model): @api.model def get_support_branding_config_param_data(self): - if not self.env.user.has_group('base.group_user'): - raise AccessError(_('You are not allowed to access this ' - 'functionality, please contact Admin for ' - 'more support')) + if not self.env.user.has_group("base.group_user"): + raise AccessError( + _( + "You are not allowed to access this " + "functionality, please contact Admin for " + "more support" + ) + ) self.env.cr.execute( - "select key, value from ir_config_parameter where key ilike " - "'%support_%';" + "select key, value from ir_config_parameter where key ilike " + "'%support_%';" ) res = self.env.cr.dictfetchall() if any(res): - support_vals = {x['key']: x['value'] for x in res} + support_vals = {x["key"]: x["value"] for x in res} return support_vals diff --git a/support_branding/static/src/js/res_config_edition.js b/support_branding/static/src/js/res_config_edition.js index cabe19aa7..ce0fc970a 100644 --- a/support_branding/static/src/js/res_config_edition.js +++ b/support_branding/static/src/js/res_config_edition.js @@ -11,17 +11,16 @@ odoo.define("support_branding.ResConfigEdition", function (require) { method: "get_support_branding_config_param_data", args: [], }).then(function (result) { - if (result && 'support_company' in result) - self.support_cp_name = result['support_company']; - if (result && 'support_company_url' in result) - self.support_cp_url = result['support_company_url']; - if (result && 'support_email' in result) - self.support_cp_email = result['support_email']; - if (result && 'support_release' in result) - self.support_cp_release = result['support_release']; - if (result && 'support_branding_color' in result) - self.support_branding_color = result[ - 'support_branding_color']; + if (result && "support_company" in result) + self.support_cp_name = result.support_company; + if (result && "support_company_url" in result) + self.support_cp_url = result.support_company_url; + if (result && "support_email" in result) + self.support_cp_email = result.support_email; + if (result && "support_release" in result) + self.support_cp_release = result.support_release; + if (result && "support_branding_color" in result) + self.support_branding_color = result.support_branding_color; }); return $.when(this._super.apply(this, arguments), def_1); diff --git a/support_branding/static/src/js/support_branding.js b/support_branding/static/src/js/support_branding.js index 702c73820..4963a79e1 100644 --- a/support_branding/static/src/js/support_branding.js +++ b/support_branding/static/src/js/support_branding.js @@ -23,17 +23,16 @@ odoo.define("support_branding.CrashManager", function (require) { method: "get_support_branding_config_param_data", args: [], }).then(function (result) { - if (result && 'support_company' in result) - self.support_cp_name = result['support_company']; - if (result && 'support_company_url' in result) - self.support_cp_url = result['support_company_url']; - if (result && 'support_email' in result) - self.support_cp_email = result['support_email']; - if (result && 'support_release' in result) - self.support_cp_release = result['support_release']; - if (result && 'support_branding_color' in result) - self.support_branding_color = result[ - 'support_branding_color']; + if (result && "support_company" in result) + self.support_cp_name = result.support_company; + if (result && "support_company_url" in result) + self.support_cp_url = result.support_company_url; + if (result && "support_email" in result) + self.support_cp_email = result.support_email; + if (result && "support_release" in result) + self.support_cp_release = result.support_release; + if (result && "support_branding_color" in result) + self.support_branding_color = result.support_branding_color; }); }); }, diff --git a/support_branding/static/src/js/user_menu.js b/support_branding/static/src/js/user_menu.js index 118d3834c..2ee54a4f8 100644 --- a/support_branding/static/src/js/user_menu.js +++ b/support_branding/static/src/js/user_menu.js @@ -17,9 +17,12 @@ odoo.define("support_branding.UserMenu", function (require) { args: [], }) .then(function (result) { - if (result && 'support_company_url' in result && - result['support_company_url'] !== "") { - self.support_url = result['support_company_url']; + if ( + result && + "support_company_url" in result && + result.support_company_url !== "" + ) { + self.support_url = result.support_company_url; } }); return $.when(this._super.apply(this, arguments), def); diff --git a/support_branding/tests/test_support_branding.py b/support_branding/tests/test_support_branding.py index 1cbd0ea7c..44d33275f 100644 --- a/support_branding/tests/test_support_branding.py +++ b/support_branding/tests/test_support_branding.py @@ -1,7 +1,7 @@ # Copyright 2023 Sunflower IT # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo.exceptions import AccessError, UserError +from odoo.exceptions import AccessError from odoo.tests.common import TransactionCase @@ -36,20 +36,25 @@ class TestSupportBranding(TransactionCase): ) vals = self.company_obj.with_user( - self.demo_user).get_support_branding_config_param_data() + self.demo_user + ).get_support_branding_config_param_data() - self.assertEquals(vals['support_company'], - self.demo_support_branding_company_name.value) + self.assertEquals( + vals["support_company"], self.demo_support_branding_company_name.value + ) # Check if admin user is able to access # admin has access all through vals_1 = self.company_obj.with_user( - self.admin_user).get_support_branding_config_param_data() + self.admin_user + ).get_support_branding_config_param_data() vals_2 = self.company_obj.with_user( - self.admin_user).get_support_branding_config_param_data() + self.admin_user + ).get_support_branding_config_param_data() self.assertEquals(vals_1, vals_2) - self.assertEquals(vals_1['support_company_url'], - self.demo_support_company_branding_url.value) - self.assertEquals(vals_2['support_company_url'], - self.demo_support_company_branding_url.value) - + self.assertEquals( + vals_1["support_company_url"], self.demo_support_company_branding_url.value + ) + self.assertEquals( + vals_2["support_company_url"], self.demo_support_company_branding_url.value + ) From 179a190e09f35f4702a37b0ff84346fc51113774 Mon Sep 17 00:00:00 2001 From: KKamaa Date: Thu, 9 Feb 2023 01:40:14 +0300 Subject: [PATCH 7/9] [FIX] tests --- support_branding/tests/test_support_branding.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/support_branding/tests/test_support_branding.py b/support_branding/tests/test_support_branding.py index 44d33275f..d6a3b8f48 100644 --- a/support_branding/tests/test_support_branding.py +++ b/support_branding/tests/test_support_branding.py @@ -21,7 +21,6 @@ class TestSupportBranding(TransactionCase): ) def test_fetch_support_branding_vals_from_res_company(self): - # Check if user has the right access rights e.g. portal user not allowed with self.assertRaises(AccessError): self.ir_config_obj.with_user(self.portal_user).get_param( @@ -35,6 +34,13 @@ class TestSupportBranding(TransactionCase): self.demo_support_branding_company_name.key ) + # Check if user has the right access rights e.g. portal user not allowed + # by calling 'get_support_branding_config_param_data' + with self.assertRaises(AccessError): + self.company_obj.with_user( + self.portal_user + ).get_support_branding_config_param_data() + vals = self.company_obj.with_user( self.demo_user ).get_support_branding_config_param_data() From c33c017c8564cdafe8d7ba5268d516e6507c48b9 Mon Sep 17 00:00:00 2001 From: KKamaa Date: Mon, 6 Mar 2023 14:23:10 +0300 Subject: [PATCH 8/9] [FIX] js, python string --- support_branding/models/res_company.py | 2 +- support_branding/static/src/js/res_config_edition.js | 2 +- support_branding/static/src/js/support_branding.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/support_branding/models/res_company.py b/support_branding/models/res_company.py index 34d94bd5a..f23e4c5dd 100644 --- a/support_branding/models/res_company.py +++ b/support_branding/models/res_company.py @@ -20,7 +20,7 @@ class ResCompany(models.Model): ) self.env.cr.execute( "select key, value from ir_config_parameter where key ilike " - "'%support_%';" + "'support_%';" ) res = self.env.cr.dictfetchall() if any(res): diff --git a/support_branding/static/src/js/res_config_edition.js b/support_branding/static/src/js/res_config_edition.js index ce0fc970a..3bf72448d 100644 --- a/support_branding/static/src/js/res_config_edition.js +++ b/support_branding/static/src/js/res_config_edition.js @@ -20,7 +20,7 @@ odoo.define("support_branding.ResConfigEdition", function (require) { if (result && "support_release" in result) self.support_cp_release = result.support_release; if (result && "support_branding_color" in result) - self.support_branding_color = result.support_branding_color; + self.support_cp_color = result.support_branding_color; }); return $.when(this._super.apply(this, arguments), def_1); diff --git a/support_branding/static/src/js/support_branding.js b/support_branding/static/src/js/support_branding.js index 4963a79e1..7f8ea9a80 100644 --- a/support_branding/static/src/js/support_branding.js +++ b/support_branding/static/src/js/support_branding.js @@ -32,7 +32,7 @@ odoo.define("support_branding.CrashManager", function (require) { if (result && "support_release" in result) self.support_cp_release = result.support_release; if (result && "support_branding_color" in result) - self.support_branding_color = result.support_branding_color; + self.support_cp_color = result.support_branding_color; }); }); }, From dfbf0bfccfc009128513924a88540b8f76bfac21 Mon Sep 17 00:00:00 2001 From: KKamaa Date: Mon, 6 Mar 2023 14:27:10 +0300 Subject: [PATCH 9/9] [FIX] black,isort,prettier --- support_branding/models/res_company.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/support_branding/models/res_company.py b/support_branding/models/res_company.py index f23e4c5dd..875fc5b1e 100644 --- a/support_branding/models/res_company.py +++ b/support_branding/models/res_company.py @@ -19,8 +19,7 @@ class ResCompany(models.Model): ) ) self.env.cr.execute( - "select key, value from ir_config_parameter where key ilike " - "'support_%';" + "select key, value from ir_config_parameter where key ilike " "'support_%';" ) res = self.env.cr.dictfetchall() if any(res):