-
-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[17.0][MIG] password_security + use ir.config_parameters #731
base: 17.0
Are you sure you want to change the base?
Changes from 1 commit
7da1e89
dda2403
71ec569
607720a
9f262d3
4ff8f5a
a642ffe
99750f8
c36d672
5583abc
88188de
f6f8554
28f3f3d
a06e409
b253dd6
096c20b
2f657de
4d2705b
50e6707
ff30b4d
089f28f
459cbb9
fd855d8
81a5636
eb7f5a1
443ee31
3b0f4c8
0c411de
04cbae2
bec6383
ce79a25
7f8832d
ee883dc
c46b35f
e69bcca
67d0299
4f5f44d
0b30a97
6e7fc2b
2d5e98b
f17eff4
026a1a9
1d53ce1
5e7b77a
c5306ff
52f0c9a
62e4b49
7d3090e
07a9586
b6c5e70
28d1a44
5ceb424
2e44a01
ac6fc8e
4ebc52c
65e7c4f
ec47741
7c8534a
6e2e903
8dd7bac
5844a57
648fed5
1d97f74
3bd3bb1
1250281
b61140f
4f0a82d
ef691ca
eaccf76
83b80a7
9566360
a9239b2
a858641
19be1fc
ea020fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Copyright 2015 LasLabs Inc. | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). | ||
|
||
from .post_install import init_config_parameters | ||
from . import controllers, models |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2024 Akretion France (http://www.akretion.com/) | ||
# @author: Alexis de Lattre <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openupgradelib import openupgrade | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
env.cr.execute( | ||
f"SELECT {openupgrade.get_legacy_name('password_expiration')}, " | ||
f"{openupgrade.get_legacy_name('password_minimum')}, " | ||
f"{openupgrade.get_legacy_name('password_history')}, " | ||
f"{openupgrade.get_legacy_name('password_lower')}, " | ||
f"{openupgrade.get_legacy_name('password_upper')}, " | ||
f"{openupgrade.get_legacy_name('password_numeric')}, " | ||
f"{openupgrade.get_legacy_name('password_special')} " | ||
"FROM res_company ORDER BY id LIMIT 1" | ||
) | ||
res = env.cr.fetchone() | ||
env["ir.config_parameter"].set_param("password_security.expiration_days", res[0]) | ||
env["ir.config_parameter"].set_param("password_security.minimum_hours", res[1]) | ||
env["ir.config_parameter"].set_param("password_security.history", res[2]) | ||
env["ir.config_parameter"].set_param("password_security.lower", res[3]) | ||
env["ir.config_parameter"].set_param("password_security.upper", res[4]) | ||
env["ir.config_parameter"].set_param("password_security.numeric", res[5]) | ||
env["ir.config_parameter"].set_param("password_security.special", res[6]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright 2024 Akretion France (http://www.akretion.com/) | ||
# @author: Alexis de Lattre <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
|
||
from openupgradelib import openupgrade | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
openupgrade.rename_fields( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are company fields being renamed if |
||
env, | ||
[ | ||
( | ||
"res.company", | ||
"res_company", | ||
"password_expiration", | ||
openupgrade.get_legacy_name("password_expiration"), | ||
), | ||
( | ||
"res.company", | ||
"res_company", | ||
"password_lower", | ||
openupgrade.get_legacy_name("password_lower"), | ||
), | ||
( | ||
"res.company", | ||
"res_company", | ||
"password_upper", | ||
openupgrade.get_legacy_name("password_upper"), | ||
), | ||
( | ||
"res.company", | ||
"res_company", | ||
"password_numeric", | ||
openupgrade.get_legacy_name("password_numeric"), | ||
), | ||
( | ||
"res.company", | ||
"res_company", | ||
"password_special", | ||
openupgrade.get_legacy_name("password_special"), | ||
), | ||
( | ||
"res.company", | ||
"res_company", | ||
"password_history", | ||
openupgrade.get_legacy_name("password_history"), | ||
), | ||
( | ||
"res.company", | ||
"res_company", | ||
"password_minimum", | ||
openupgrade.get_legacy_name("password_minimum"), | ||
), | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
# Copyright 2015 LasLabs Inc. | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). | ||
|
||
from . import res_company | ||
from . import res_config_settings | ||
from . import res_users | ||
from . import res_users_pass_history |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,20 +6,59 @@ | |
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
# Imagine that the ir.config_parameter password_security.numeric has | ||
# a default value of 1. If the user sets the value to 0 on the config page, | ||
# the ir.config_parameter is deleted... but when the ir.config_parameter is not | ||
# present in the database, Odoo displays the default value | ||
# on the config page => Odoo displays 1 ! | ||
# So, when the users sets the value of 0 on the config page, he will see 1 | ||
# after saving the page !!! | ||
# If the default value is 0 (like auth_password_policy.minlength in the | ||
# module auth_password_policy of the official addons), there is no problem. | ||
# So the solution to avoid this problem and have a non-null default value: | ||
# 1) define the ir.config_parameter fields on res.config.settings with default=0 | ||
# 2) initialize the ir.config_parameter with a default value in the init script | ||
# So the default value of the fields below are written in post_install.py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This explanation is unnecessary if all defaults are returned to zero. |
||
password_expiration = fields.Integer( | ||
related="company_id.password_expiration", readonly=False | ||
string="Days", | ||
default=0, | ||
config_parameter="password_security.expiration_days", | ||
help="How many days until passwords expire", | ||
) | ||
password_minimum = fields.Integer( | ||
related="company_id.password_minimum", readonly=False | ||
string="Minimum Hours", | ||
default=0, | ||
config_parameter="password_security.minimum_hours", | ||
help="Number of hours until a user may change password again", | ||
) | ||
password_history = fields.Integer( | ||
related="company_id.password_history", readonly=False | ||
string="History", | ||
default=0, | ||
config_parameter="password_security.history", | ||
help="Disallow reuse of this many previous passwords - use negative " | ||
"number for infinite, or 0 to disable", | ||
) | ||
password_lower = fields.Integer( | ||
string="Lowercase", | ||
default=0, | ||
config_parameter="password_security.lower", | ||
help="Require number of lowercase letters", | ||
) | ||
password_upper = fields.Integer( | ||
string="Uppercase", | ||
default=0, | ||
config_parameter="password_security.upper", | ||
help="Require number of uppercase letters", | ||
) | ||
password_lower = fields.Integer(related="company_id.password_lower", readonly=False) | ||
password_upper = fields.Integer(related="company_id.password_upper", readonly=False) | ||
password_numeric = fields.Integer( | ||
related="company_id.password_numeric", readonly=False | ||
string="Numeric", | ||
default=0, | ||
config_parameter="password_security.numeric", | ||
help="Require number of numeric digits", | ||
) | ||
password_special = fields.Integer( | ||
related="company_id.password_special", readonly=False | ||
string="Special", | ||
default=0, | ||
config_parameter="password_security.special", | ||
help="Require number of unique special characters", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could degrade security for installations with more than one company. Perhaps remove
LIMIT 1
and useMAX(field)
orMIN(field)
as appropriate?