|
8 | 8 |
|
9 | 9 | from odoo import _, api, fields, models
|
10 | 10 | from odoo.exceptions import UserError, ValidationError
|
| 11 | +from odoo.tools import groupby |
11 | 12 |
|
12 | 13 |
|
13 | 14 | def delta_now(**kwargs):
|
@@ -97,22 +98,21 @@ def _check_password(self, password):
|
97 | 98 | return True
|
98 | 99 |
|
99 | 100 | def _check_password_rules(self, password):
|
100 |
| - self.ensure_one() |
101 | 101 | if not password:
|
102 | 102 | return True
|
103 |
| - company_id = self.company_id |
104 | 103 | params = self.env["ir.config_parameter"].sudo()
|
105 | 104 | minlength = params.get_param("auth_password_policy.minlength", default=0)
|
106 |
| - password_regex = [ |
107 |
| - "^", |
108 |
| - "(?=.*?[a-z]){" + str(company_id.password_lower) + ",}", |
109 |
| - "(?=.*?[A-Z]){" + str(company_id.password_upper) + ",}", |
110 |
| - "(?=.*?\\d){" + str(company_id.password_numeric) + ",}", |
111 |
| - r"(?=.*?[\W_]){" + str(company_id.password_special) + ",}", |
112 |
| - ".{%d,}$" % int(minlength), |
113 |
| - ] |
114 |
| - if not re.search("".join(password_regex), password): |
115 |
| - raise ValidationError(self.password_match_message()) |
| 105 | + for company_id, users in groupby(self, lambda u: u.company_id): |
| 106 | + password_regex = [ |
| 107 | + "^", |
| 108 | + "(?=.*?[a-z]){" + str(company_id.password_lower) + ",}", |
| 109 | + "(?=.*?[A-Z]){" + str(company_id.password_upper) + ",}", |
| 110 | + "(?=.*?\\d){" + str(company_id.password_numeric) + ",}", |
| 111 | + r"(?=.*?[\W_]){" + str(company_id.password_special) + ",}", |
| 112 | + ".{%d,}$" % int(minlength), |
| 113 | + ] |
| 114 | + if not re.search("".join(password_regex), password): |
| 115 | + raise ValidationError(users[0].password_match_message()) |
116 | 116 |
|
117 | 117 | return True
|
118 | 118 |
|
|
0 commit comments