Skip to content

Commit

Permalink
[MIG] password_security: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyas caluwe committed Jan 31, 2024
1 parent 588d315 commit ce6c04d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 95 deletions.
2 changes: 1 addition & 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.0",
"version": "17.0.1.0.0",
"author": "LasLabs, "
"Onestein, "
"Kaushal Prajapati, "
Expand Down
6 changes: 3 additions & 3 deletions password_security/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def do_signup(self, qcontext):
password = qcontext.get("password")
user = request.env.user
user._check_password(password)
return super(PasswordSecurityHome, self).do_signup(qcontext)
return super().do_signup(qcontext)

@http.route()
def web_login(self, *args, **kw):
ensure_db()
response = super(PasswordSecurityHome, self).web_login(*args, **kw)
response = super().web_login(*args, **kw)
if not request.params.get("login_success"):
return response
if not request.env.user:
Expand All @@ -50,7 +50,7 @@ def web_auth_signup(self, *args, **kw):
raise BadRequest from None # HTTPError: 400 Client Error: BAD REQUEST

try:
return super(PasswordSecurityHome, self).web_auth_signup(*args, **kw)
return super().web_auth_signup(*args, **kw)
except Exception as e:
# Here we catch any generic exception since UserError is already
# handled in parent method web_auth_signup()
Expand Down
24 changes: 0 additions & 24 deletions password_security/migrations/16.0.1.0.0/pre-migration.py

This file was deleted.

10 changes: 5 additions & 5 deletions password_security/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class ResUsers(models.Model):
def write(self, vals):
if vals.get("password"):
vals["password_write_date"] = fields.Datetime.now()
return super(ResUsers, self).write(vals)
return super().write(vals)

@api.model
def get_password_policy(self):
data = super(ResUsers, self).get_password_policy()
data = super().get_password_policy()
company_id = self.env.user.company_id
data.update(
{
Expand All @@ -47,7 +47,7 @@ def get_password_policy(self):
return data

def _check_password_policy(self, passwords):
result = super(ResUsers, self)._check_password_policy(passwords)
result = super()._check_password_policy(passwords)

for password in passwords:
if not password:
Expand Down Expand Up @@ -178,7 +178,7 @@ def _check_password_history(self, password):

def _set_encrypted_password(self, uid, pw):
"""It saves password crypt history for history rules"""
res = super(ResUsers, self)._set_encrypted_password(uid, pw)
res = super()._set_encrypted_password(uid, pw)

self.env["res.users.pass.history"].create(
{
Expand All @@ -196,4 +196,4 @@ def action_reset_password(self):
if not self.env.user._is_admin():
users = self.filtered(lambda user: user.active)
users._validate_pass_reset()
return super(ResUsers, self).action_reset_password()
return super().action_reset_password()
2 changes: 1 addition & 1 deletion password_security/tests/test_res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class TestResUsers(TransactionCase):
def setUp(self):
super(TestResUsers, self).setUp()
super().setUp()
self.login = "foslabs@example.com"
self.partner_vals = {
"name": "Partner",
Expand Down
97 changes: 36 additions & 61 deletions password_security/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,27 @@
ref="auth_password_policy.res_config_settings_view_form"
/>
<field name="arch" type="xml">
<!-- Hide label for uniform styling -->
<xpath expr="//label[@for='minlength']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>

<!-- Add an id for easier lookup -->
<xpath
expr="//field[@name='minlength']/ancestor::div[hasclass('o_setting_box')]"
position="attributes"
>
<attribute name="id">password_policy</attribute>
</xpath>

<!-- Move the settings box to desired location -->
<xpath expr="//div[@id='enable_password_reset']" position="after">
<xpath expr="//div[@id='password_policy']" position="move" />
</xpath>

<!-- Ensure our settings will come after any former customization -->
<xpath
expr="//div[@id='password_policy']//div[hasclass('o_setting_right_pane')]/*"
position="after"
>
<label string="Password Policy" for="password_expiration" />
<div class="content-group">
<div class="mt16">
<xpath expr="//block[@id='user_default_rights']" position="after">
<block title="Password Policy" id="password_policy">
<setting>
<span>
Password expires in
<field name="password_expiration" class="oe_inline" />
days.
Password expires in <field
name="password_expiration"
class="oe_inline"
/> days.
</span>
</div>
<div class="mt16">
</setting>
<setting>
<span>
User can change password in
<field name="password_minimum" class="oe_inline" />
hours again.
User can change password in <field
name="password_minimum"
class="oe_inline"
/> hours again.
</span>
</div>
<div class="mt16">
</setting>

<setting>
<span>
Disallow reuse of
<field name="password_history" class="oe_inline" />
Expand All @@ -60,47 +41,41 @@
<div class="text-muted">
Use negative number for infinite, or 0 to disable
</div>
</div>
<div class="mt16">
</setting>
<setting>
<span>
Minimum number of lowercase characters
<field name="password_lower" class="oe_inline" />
<field name="password_lower" />
</span>
</div>
<div class="mt16">
</setting>
<setting>
<span>
Minimum number of uppercase characters
<field name="password_upper" class="oe_inline" />
<field name="password_upper" />
</span>
</div>
<div class="mt16">
</setting>
<setting>
<span>
Minimum number of numeric characters
<field name="password_numeric" class="oe_inline" />
<field name="password_numeric" />
</span>
</div>
<div class="mt16">
</setting>
<setting>
<span>
Minimum number of special characters
<field name="password_special" class="oe_inline" />
<field name="password_special" />
</span>
</div>
<div class="mt16">
<span id="minlength">
Minimum number of characters
</span>
</div>
</div>
</xpath>

<!-- Add oe_inline attribute to minlength -->
<xpath expr="//field[@name='minlength']" position="attributes">
<attribute name="class">oe_inline</attribute>
</setting>
</block>
</xpath>

<!-- Move the minlength field to desired location -->
<xpath expr="//span[@id='minlength']" position="inside">
<xpath expr="//field[@name='minlength']" position="move" />
<xpath expr="//block[@id='password_policy']" position="inside">
<xpath expr="//field[@name='minlength']/.." position="move" />
<xpath
expr="//field[@name='auth_signup_reset_password']/.."
position="move"
/>
</xpath>
</field>
</record>
Expand Down

0 comments on commit ce6c04d

Please sign in to comment.