mirror of https://github.com/OCA/web.git
[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).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import _, api, models
|
from odoo import _, api, models
|
||||||
from odoo.exceptions import AccessError, UserError
|
from odoo.exceptions import UserError, AccessError
|
||||||
|
|
||||||
|
|
||||||
class ResCompany(models.Model):
|
class ResCompany(models.Model):
|
||||||
_inherit = "res.company"
|
_inherit = "res.company"
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def get_ir_config_param_data(self, key):
|
def get_support_branding_config_param_data(self):
|
||||||
if not self.env.user.has_group("base.group_user"):
|
if not self.env.user.has_group('base.group_user'):
|
||||||
raise AccessError(
|
raise AccessError(_('You are not allowed to access this '
|
||||||
_(
|
'functionality, please contact Admin for '
|
||||||
"You are not allowed to access this "
|
'more support'))
|
||||||
"functionality, please contact Admin for "
|
|
||||||
"more support"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
self.env.cr.execute(
|
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()
|
res = self.env.cr.dictfetchall()
|
||||||
except Exception as e:
|
if any(res):
|
||||||
raise UserError(_("Error: %s" % e))
|
support_vals = {x['key']: x['value'] for x in res}
|
||||||
else:
|
return support_vals
|
||||||
if res:
|
|
||||||
return "%s" % res
|
|
||||||
return ""
|
|
||||||
|
|
|
@ -8,26 +8,23 @@ odoo.define("support_branding.ResConfigEdition", function (require) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var def_1 = this._rpc({
|
var def_1 = this._rpc({
|
||||||
model: "res.company",
|
model: "res.company",
|
||||||
method: "get_ir_config_param_data",
|
method: "get_support_branding_config_param_data",
|
||||||
args: ["support_company"],
|
args: [],
|
||||||
}).then(function (name) {
|
}).then(function (result) {
|
||||||
self.support_cp_name = name;
|
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",
|
return $.when(this._super.apply(this, arguments), def_1);
|
||||||
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);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,42 +20,20 @@ odoo.define("support_branding.CrashManager", function (require) {
|
||||||
$.when(this._super.apply(this, arguments)).then(function () {
|
$.when(this._super.apply(this, arguments)).then(function () {
|
||||||
self._rpc({
|
self._rpc({
|
||||||
model: "res.company",
|
model: "res.company",
|
||||||
method: "get_ir_config_param_data",
|
method: "get_support_branding_config_param_data",
|
||||||
args: ["support_company"],
|
args: [],
|
||||||
}).then(function (name) {
|
}).then(function (result) {
|
||||||
self.support_cp_name = name;
|
if (result && 'support_company' in result)
|
||||||
});
|
self.support_cp_name = result['support_company'];
|
||||||
|
if (result && 'support_company_url' in result)
|
||||||
self._rpc({
|
self.support_cp_url = result['support_company_url'];
|
||||||
model: "res.company",
|
if (result && 'support_email' in result)
|
||||||
method: "get_ir_config_param_data",
|
self.support_cp_email = result['support_email'];
|
||||||
args: ["support_company_url"],
|
if (result && 'support_release' in result)
|
||||||
}).then(function (url) {
|
self.support_cp_release = result['support_release'];
|
||||||
self.support_cp_url = url;
|
if (result && 'support_branding_color' in result)
|
||||||
});
|
self.support_branding_color = result[
|
||||||
|
'support_branding_color'];
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,12 +13,13 @@ odoo.define("support_branding.UserMenu", function (require) {
|
||||||
var def = self
|
var def = self
|
||||||
._rpc({
|
._rpc({
|
||||||
model: "res.company",
|
model: "res.company",
|
||||||
method: "get_ir_config_param_data",
|
method: "get_support_branding_config_param_data",
|
||||||
args: ["support_company_url"],
|
args: [],
|
||||||
})
|
})
|
||||||
.then(function (site) {
|
.then(function (result) {
|
||||||
if (site && site !== "") {
|
if (result && 'support_company_url' in result &&
|
||||||
self.support_url = site;
|
result['support_company_url'] !== "") {
|
||||||
|
self.support_url = result['support_company_url'];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return $.when(this._super.apply(this, arguments), def);
|
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
|
# Check if user has the right access rights e.g. portal user not allowed
|
||||||
with self.assertRaises(AccessError):
|
with self.assertRaises(AccessError):
|
||||||
self.ir_config_obj.with_user(self.portal_user).get_param(
|
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.
|
# Check if demo user is able to access.
|
||||||
# NB: ir.config_parameter model requires admin access rights.
|
# NB: ir.config_parameter model requires admin access rights.
|
||||||
with self.assertRaises(AccessError):
|
with self.assertRaises(AccessError):
|
||||||
self.ir_config_obj.with_user(self.demo_user).get_param(
|
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(
|
vals = self.company_obj.with_user(
|
||||||
self.demo_support_company_branding_url.key
|
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
|
# Check if admin user is able to access
|
||||||
# admin has access all through
|
# admin has access all through
|
||||||
value_1 = self.company_obj.with_user(self.admin_user).get_ir_config_param_data(
|
vals_1 = self.company_obj.with_user(
|
||||||
self.demo_support_company_branding_url.key
|
self.admin_user).get_support_branding_config_param_data()
|
||||||
)
|
vals_2 = self.company_obj.with_user(
|
||||||
value_2 = self.company_obj.with_user(self.admin_user).get_ir_config_param_data(
|
self.admin_user).get_support_branding_config_param_data()
|
||||||
self.demo_support_company_branding_url.key
|
self.assertEquals(vals_1, vals_2)
|
||||||
)
|
self.assertEquals(vals_1['support_company_url'],
|
||||||
self.assertEquals(value_1, value_2)
|
self.demo_support_company_branding_url.value)
|
||||||
self.assertEquals(value_1, self.demo_support_company_branding_url.value)
|
self.assertEquals(vals_2['support_company_url'],
|
||||||
self.assertEquals(value_2, self.demo_support_company_branding_url.value)
|
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