[14.0][FIX] #3039 support_branding ACL bug

This commit is contained in:
KKamaa
2023-01-31 05:05:30 +03:00
parent 88147d9261
commit 246710faa4
7 changed files with 103 additions and 18 deletions

View File

@@ -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

View File

@@ -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 ''

View File

@@ -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;

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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

View File

@@ -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)