Skip to content
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

[IMP] password_security: Set password update date for already existin… #691

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions password_security/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

from . import controllers, models
from .hooks import post_init_hook
3 changes: 2 additions & 1 deletion password_security/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Password Security",
"summary": "Allow admin to set password security requirements.",
"version": "16.0.1.0.1",
"version": "16.0.1.0.2",
"author": "LasLabs, "
"Onestein, "
"Kaushal Prajapati, "
Expand All @@ -29,4 +29,5 @@
"demo/res_users.xml",
],
"installable": True,
"post_init_hook": "post_init_hook",
}
16 changes: 16 additions & 0 deletions password_security/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Vauxoo
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


def post_init_hook(cr, registry):
# Set password date for already existing users
cr.execute(
"""
UPDATE
res_users
SET
password_write_date = NOW() at time zone 'UTC'
WHERE
password_write_date IS NULL;
"""
)
12 changes: 12 additions & 0 deletions password_security/migrations/16.0.1.0.2/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def migrate(cr, version):
# Set password date for already existing users
cr.execute(
"""
UPDATE
res_users
SET
password_write_date = NOW() at time zone 'UTC'
WHERE
password_write_date IS NULL;
"""
)
5 changes: 1 addition & 4 deletions password_security/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ def _validate_pass_reset(self):
if pass_min <= 0:
continue
write_date = user.password_write_date
if not write_date:
continue
delta = timedelta(hours=pass_min)
if write_date + delta > datetime.now():
if write_date and write_date + timedelta(hours=pass_min) > datetime.now():
raise UserError(
_(
"Passwords can only be reset every %d hour(s). "
Expand Down
Loading