Merge PR #2399 into 14.0

Signed-off-by hbrunn
This commit is contained in:
OCA-git-bot
2023-03-17 19:51:34 +00:00
7 changed files with 138 additions and 63 deletions

View File

@@ -2,3 +2,4 @@
# 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,27 @@
# Copyright 2023 Sunflower IT
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, api, models
from odoo.exceptions import AccessError
class ResCompany(models.Model):
_inherit = "res.company"
@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"
)
)
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

View File

@@ -7,27 +7,23 @@ odoo.define("support_branding.ResConfigEdition", function (require) {
willStart: function () {
var self = this;
var def_1 = this._rpc({
model: "ir.config_parameter",
method: "get_param",
args: ["support_company"],
}).then(function (name) {
self.support_cp_name = name;
model: "res.company",
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_cp_color = result.support_branding_color;
});
var def_2 = this._rpc({
model: "ir.config_parameter",
method: "get_param",
args: ["support_company_url"],
}).then(function (url) {
self.support_cp_url = url;
});
var def_3 = this._rpc({
model: "ir.config_parameter",
method: "get_param",
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);
},
});
});

View File

@@ -19,43 +19,20 @@ 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",
args: ["support_company"],
}).then(function (name) {
self.support_cp_name = name;
});
self._rpc({
model: "ir.config_parameter",
method: "get_param",
args: ["support_company_url"],
}).then(function (url) {
self.support_cp_url = url;
});
self._rpc({
model: "ir.config_parameter",
method: "get_param",
args: ["support_email"],
}).then(function (email) {
self.support_cp_email = email;
});
self._rpc({
model: "ir.config_parameter",
method: "get_param",
args: ["support_release"],
}).then(function (release) {
self.support_cp_release = release;
});
self._rpc({
model: "ir.config_parameter",
method: "get_param",
args: ["support_branding_color"],
}).then(function (color) {
self.support_cp_color = color;
model: "res.company",
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_cp_color = result.support_branding_color;
});
});
},

View File

@@ -12,13 +12,17 @@ odoo.define("support_branding.UserMenu", function (require) {
var self = this;
var def = self
._rpc({
model: "ir.config_parameter",
method: "get_param",
args: ["support_company_url"],
model: "res.company",
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);

View File

@@ -0,0 +1,4 @@
# 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,66 @@
# Copyright 2023 Sunflower IT
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
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.portal_user = self.env.ref("base.demo_user0")
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 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_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_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()
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()
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
)