summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2018-10-09 13:38:29 +0000
committerAlexandre Kühn <aku@odoo.com>2018-10-09 14:26:21 +0000
commit5bbbd25edf129912ed7cdccd1005ab61bfaf2124 (patch)
tree305cd9447ab0d8cfef23144ee3f3a40c603cd35a
parent70e604a8fa159bcb6d6a06bc95c9779c7b746969 (diff)
[FIX] auth_password_policy: Cannot read property 'decorations' of undefined
Revision on https://github.com/odoo/odoo/commit/a47f6093f80cefa51c5a1bc1301db01007f97761 The commit above introduced a visual 'password strength' next to the password wizard in Settings > Users, when the module `auth_password_policy` is installed. However, there was an traceback when trying to access the 'General Settings' when some specific apps and modules were installed. This issue comes from the small design issue with the new PasswordField: it was designed as a field object that was instantiated and returned in the `init` function of an InputField with the password attribute set. This is not a solid design, because the documentation of the `init` function does not specify that it should return the newly instantiated object. As a result, the implementation was very fragile and only worked on FieldChar but not FieldText. This commit fixes the issue by turning the FieldPassword a field widget. As a result, the enabling of the password meter next to a password input has changed: Before this commit: ``` <field name="new_passwd" password="True" options="{'password_meter': True}"/> ``` With this commit: ``` <field name="new_passwd" password="True" widget="password_meter"/> ``` Closes #27440 closes odoo/odoo#27586
-rw-r--r--addons/auth_password_policy/static/src/js/password_field.js21
-rw-r--r--addons/auth_password_policy/views/res_users.xml2
2 files changed, 5 insertions, 18 deletions
diff --git a/addons/auth_password_policy/static/src/js/password_field.js b/addons/auth_password_policy/static/src/js/password_field.js
index 93a623acc1c..fa8cfd20ff2 100644
--- a/addons/auth_password_policy/static/src/js/password_field.js
+++ b/addons/auth_password_policy/static/src/js/password_field.js
@@ -7,6 +7,7 @@
odoo.define('auth_password_policy.PasswordField', function (require) {
"use strict";
var fields = require('web.basic_fields');
+var registry = require('web.field_registry');
var policy = require('auth_password_policy');
var Meter = require('auth_password_policy.Meter');
var _formatValue = require('web.AbstractField').prototype._formatValue;
@@ -21,12 +22,12 @@ var PasswordField = fields.InputField.extend({
},
willStart: function () {
var _this = this;
- var getPolicy = this.nodeOptions['password_meter'] ? this._rpc({
+ var getPolicy = this._rpc({
model: 'res.users',
method: 'get_password_policy',
}).then(function (p) {
_this._meter = new Meter(_this, new policy.Policy(p), policy.recommendations);
- }) : undefined;
+ });
return $.when(
this._super.apply(this, arguments),
getPolicy
@@ -46,9 +47,6 @@ var PasswordField = fields.InputField.extend({
// insertAfter doesn't work and appendTo means the meter is
// ignored (as this.$el is an input[type=password])
_this.$el = t.add(meter.$el);
- if (!_this.nodeOptions['password_meter']) {
- meter.$el.hide();
- }
}, _this.$el);
}).then(function () {
// initial meter update when re-editing
@@ -84,17 +82,6 @@ var PasswordField = fields.InputField.extend({
}
});
-fields.InputField.include({
- init: function (parent, name, record, options) {
- var fieldsInfo = record.fieldsInfo[options.viewType];
- var attrs = options.attrs || (fieldsInfo && fieldsInfo[name]) || {};
- if ('password' in attrs
- && Object.getPrototypeOf(this) !== PasswordField.prototype) {
- return new PasswordField(parent, name, record, options);
- }
- this._super.apply(this, arguments);
- }
-});
-
+registry.add("password_meter", PasswordField);
return PasswordField;
});
diff --git a/addons/auth_password_policy/views/res_users.xml b/addons/auth_password_policy/views/res_users.xml
index 7bc4dc91103..e0a2ffc3acc 100644
--- a/addons/auth_password_policy/views/res_users.xml
+++ b/addons/auth_password_policy/views/res_users.xml
@@ -5,7 +5,7 @@
<field name="model">change.password.user</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='new_passwd']" position="attributes">
- <attribute name="options">{'password_meter': True}</attribute>
+ <attribute name="widget">password_meter</attribute>
</xpath>
</field>
</record>