mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
@@ -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
|
||||
|
||||
27
support_branding/models/res_company.py
Normal file
27
support_branding/models/res_company.py
Normal 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
|
||||
@@ -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);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@@ -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);
|
||||
|
||||
4
support_branding/tests/__init__.py
Normal file
4
support_branding/tests/__init__.py
Normal 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
|
||||
66
support_branding/tests/test_support_branding.py
Normal file
66
support_branding/tests/test_support_branding.py
Normal 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
|
||||
)
|
||||
Reference in New Issue
Block a user