forked from Techsystech/web
[FIX] use key/value pair for support branding
parent
7553f530aa
commit
ac624eb7fc
|
@ -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:
|
||||
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 value from ir_config_parameter where " "key=(%s);", (key,)
|
||||
"select key, value from ir_config_parameter where key ilike "
|
||||
"'%support_%';"
|
||||
)
|
||||
res = self.env.cr.fetchone()
|
||||
except Exception as e:
|
||||
raise UserError(_("Error: %s" % e))
|
||||
else:
|
||||
if res:
|
||||
return "%s" % res
|
||||
return ""
|
||||
res = self.env.cr.dictfetchall()
|
||||
if any(res):
|
||||
support_vals = {x['key']: x['value'] for x in res}
|
||||
return support_vals
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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'];
|
||||
});
|
||||
});
|
||||
},
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue