mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[14.0][FIX] #3039 support_branding ACL bug
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
29
support_branding/models/res_company.py
Normal file
29
support_branding/models/res_company.py
Normal 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 ''
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
8
support_branding/tests/__init__.py
Normal file
8
support_branding/tests/__init__.py
Normal 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
|
||||
|
||||
|
||||
|
||||
|
||||
46
support_branding/tests/test_support_branding.py
Normal file
46
support_branding/tests/test_support_branding.py
Normal 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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user