Skip to content

Commit f9cf363

Browse files
committed
[IMP] password_security: use ir.config_parameter
Replace fields on res.company by ir.config_parameter Remove dead test for v16 migration script
1 parent ce6c04d commit f9cf363

16 files changed

Lines changed: 240 additions & 154 deletions

password_security/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright 2015 LasLabs Inc.
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
33

4+
from .post_install import init_config_parameters
45
from . import controllers, models

password_security/__manifest__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"name": "Password Security",
77
"summary": "Allow admin to set password security requirements.",
8-
"version": "17.0.1.0.0",
8+
"version": "17.0.2.0.0",
99
"author": "LasLabs, "
1010
"Onestein, "
1111
"Kaushal Prajapati, "
@@ -28,5 +28,6 @@
2828
"demo": [
2929
"demo/res_users.xml",
3030
],
31+
"post_init_hook": "init_config_parameters",
3132
"installable": True,
3233
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2024 Akretion France (http://www.akretion.com/)
2+
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
5+
from openupgradelib import openupgrade
6+
7+
8+
@openupgrade.migrate()
9+
def migrate(env, version):
10+
env.cr.execute(
11+
f"SELECT {openupgrade.get_legacy_name('password_expiration')}, "
12+
f"{openupgrade.get_legacy_name('password_minimum')}, "
13+
f"{openupgrade.get_legacy_name('password_history')}, "
14+
f"{openupgrade.get_legacy_name('password_lower')}, "
15+
f"{openupgrade.get_legacy_name('password_upper')}, "
16+
f"{openupgrade.get_legacy_name('password_numeric')}, "
17+
f"{openupgrade.get_legacy_name('password_special')} "
18+
"FROM res_company ORDER BY id LIMIT 1"
19+
)
20+
res = env.cr.fetchone()
21+
env["ir.config_parameter"].set_param("password_security.expiration_days", res[0])
22+
env["ir.config_parameter"].set_param("password_security.minimum_hours", res[1])
23+
env["ir.config_parameter"].set_param("password_security.history", res[2])
24+
env["ir.config_parameter"].set_param("password_security.lower", res[3])
25+
env["ir.config_parameter"].set_param("password_security.upper", res[4])
26+
env["ir.config_parameter"].set_param("password_security.numeric", res[5])
27+
env["ir.config_parameter"].set_param("password_security.special", res[6])
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright 2024 Akretion France (http://www.akretion.com/)
2+
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
5+
6+
from openupgradelib import openupgrade
7+
8+
9+
@openupgrade.migrate()
10+
def migrate(env, version):
11+
openupgrade.rename_fields(
12+
env,
13+
[
14+
(
15+
"res.company",
16+
"res_company",
17+
"password_expiration",
18+
openupgrade.get_legacy_name("password_expiration"),
19+
),
20+
(
21+
"res.company",
22+
"res_company",
23+
"password_lower",
24+
openupgrade.get_legacy_name("password_lower"),
25+
),
26+
(
27+
"res.company",
28+
"res_company",
29+
"password_upper",
30+
openupgrade.get_legacy_name("password_upper"),
31+
),
32+
(
33+
"res.company",
34+
"res_company",
35+
"password_numeric",
36+
openupgrade.get_legacy_name("password_numeric"),
37+
),
38+
(
39+
"res.company",
40+
"res_company",
41+
"password_special",
42+
openupgrade.get_legacy_name("password_special"),
43+
),
44+
(
45+
"res.company",
46+
"res_company",
47+
"password_history",
48+
openupgrade.get_legacy_name("password_history"),
49+
),
50+
(
51+
"res.company",
52+
"res_company",
53+
"password_minimum",
54+
openupgrade.get_legacy_name("password_minimum"),
55+
),
56+
],
57+
)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright 2015 LasLabs Inc.
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
33

4-
from . import res_company
54
from . import res_config_settings
65
from . import res_users
76
from . import res_users_pass_history

password_security/models/res_company.py

Lines changed: 0 additions & 46 deletions
This file was deleted.

password_security/models/res_config_settings.py

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,58 @@
66
class ResConfigSettings(models.TransientModel):
77
_inherit = "res.config.settings"
88

9+
# Imagine that the ir.config_parameter password_security.numeric has a default value of 1.
10+
# If the user sets the value to 0 on the config page, the ir.config_parameter is deleted... but
11+
# when the ir.config_parameter is not present in the database, Odoo displays the default value
12+
# on the config page => Odoo displays 1 !
13+
# So, when the users sets the value of 0 on the config page, he will see 1
14+
# after saving the page !!!
15+
# If the default value is 0 (like auth_password_policy.minlength in the
16+
# module auth_password_policy of the official addons), there is no problem.
17+
# So the solution to avoid this problem and have a non-null default value:
18+
# 1) define the ir.config_parameter fields on res.config.settings with default=0
19+
# 2) initialize the ir.config_parameter with a default value in the init script
20+
# So the default value of the fields below are written in post_install.py
921
password_expiration = fields.Integer(
10-
related="company_id.password_expiration", readonly=False
22+
string="Days",
23+
default=0,
24+
config_parameter="password_security.expiration_days",
25+
help="How many days until passwords expire",
1126
)
1227
password_minimum = fields.Integer(
13-
related="company_id.password_minimum", readonly=False
28+
string="Minimum Hours",
29+
default=0,
30+
config_parameter="password_security.minimum_hours",
31+
help="Number of hours until a user may change password again",
1432
)
1533
password_history = fields.Integer(
16-
related="company_id.password_history", readonly=False
34+
string="History",
35+
default=0,
36+
config_parameter="password_security.history",
37+
help="Disallow reuse of this many previous passwords - use negative "
38+
"number for infinite, or 0 to disable",
39+
)
40+
password_lower = fields.Integer(
41+
string="Lowercase",
42+
default=0,
43+
config_parameter="password_security.lower",
44+
help="Require number of lowercase letters",
45+
)
46+
password_upper = fields.Integer(
47+
string="Uppercase",
48+
default=0,
49+
config_parameter="password_security.upper",
50+
help="Require number of uppercase letters",
1751
)
18-
password_lower = fields.Integer(related="company_id.password_lower", readonly=False)
19-
password_upper = fields.Integer(related="company_id.password_upper", readonly=False)
2052
password_numeric = fields.Integer(
21-
related="company_id.password_numeric", readonly=False
53+
string="Numeric",
54+
default=0,
55+
config_parameter="password_security.numeric",
56+
help="Require number of numeric digits",
2257
)
2358
password_special = fields.Integer(
24-
related="company_id.password_special", readonly=False
59+
string="Special",
60+
default=0,
61+
config_parameter="password_security.special",
62+
help="Require number of unique special characters",
2563
)

0 commit comments

Comments
 (0)