Skip to content

Commit ea020fc

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 19be1fc commit ea020fc

18 files changed

+244
-156
lines changed

password_security/__init__.py

+1
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

+2-1
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
}

password_security/controllers/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def web_login(self, *args, **kw):
4242

4343
@http.route()
4444
def web_auth_signup(self, *args, **kw):
45-
"""Try to catch all the possible exceptions not already handled in the parent method"""
45+
"""Try to catch all the possible exceptions not already handled
46+
in the parent method"""
4647

4748
try:
4849
qcontext = self.get_auth_signup_qcontext()
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 <[email protected]>
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])
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 <[email protected]>
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+
)

password_security/models/__init__.py

-1
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

-46
This file was deleted.

password_security/models/res_config_settings.py

+46-7
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,59 @@
66
class ResConfigSettings(models.TransientModel):
77
_inherit = "res.config.settings"
88

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

0 commit comments

Comments
 (0)