Commit Graph
7 Commits
Author SHA1 Message Date
Antoine (ande) cd1ddc7cad [FIX] auth_totp_mail_enforce: cannot save option
Current behaviour:
When checking "All users" then saving,
it unchecks it then checks "Employees only"

Steps to reproduce:
1. Install auth_totp_mail_enforce
2. Go to Settings
3. Check "Two-factor authentication enforcing policy"
4. Hit Save
5. ("Employees only" is selected)
6. Select "All users"
7. Hit Save
8. ("Employees only" is still selected)

Cause of the issue:
Because of onchange, _onchange_auth_totp_enforce is
called when refreshing the page, which causes
auth_totp_policy to default as 'employee_required'

opw-3523880

closes odoo/odoo#139535

X-original-commit: 1d8423e397e7646eec9eebab8a1fd40e39605404
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
Signed-off-by: Antoine Demany (ande) <ande@odoo.com>
2023-10-24 15:23:26 +00:00
Chong Wang (cwg) fc587dc61b [FIX] auth_totp_mail
1. sudo permission for _totp_check
env.user is still public user which doesn't have access rights for self.login
in Odoo 15 it was not a problem since self.login was in cache
but in Odoo 16 it is not and as a result, returns an access error

2. format_timedelta
the lang was used for `granularity` as the second argument not for `locale`

closes odoo/odoo#138532

X-original-commit: d439fae7a27874ceeaab99cc4db5d28fcbe587c2
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
Signed-off-by: Chong Wang (cwg) <cwg@odoo.com>
2023-10-16 07:58:42 +00:00
Julien Castiaux 3d1f486bcc [IMP] *: update modules to use the new geoip API
request.geoip is no more a dictionnary cached in the session. It is now
a full blown object with lazy and smart geolocalisation capabilities.

Among other things, the previous dictionnary API is now deprecated. The
changes are:

* `request.geoip['country_name']` -> `request.geoip.country_name`
* `request.geoip['country_code']` -> `request.geoip.country_code`
* `request.geoip['city']` -> `request.geoip.city.name`
* `request.geoip['latitude']` -> `request.geoip.location.latitude`
* `request.geoip['longitude']` -> `request.geoip.location.longitude`
* `request.geoip['region']` -> `(request.geoip.subdivisions[0].iso_code if request.geoip.subdivisions else None)`
* `request.geoip['time_zone']` -> `request.geoip.location.time_zone`

It is safe to access all the attributes. Doing `request.geoip.city.name`
when the geolocalization failed (missing db, invalid address, ...)
evaluates to None. It does not raise an AttributeError.

Task: 2848206
Part-of: odoo/odoo#91337
2023-01-03 13:16:02 +01:00
Florian Charlier dae28c4b46 [IMP] base: add _is_internal method to res.users
No method was readily available to know if a user is `internal` (has
group `base.group_user`), which was inconsistent with other base groups.

_is_internal is now used in the codebase where it is clear that
`.has_group('base.group_user')` is called on a single record.

Part-of: odoo/odoo#85703
2022-06-14 09:35:57 +02:00
Julien Castiaux c46f4b908a [IMP] *: request.session.geoip -> request.geoip
Commit "[IMP] core: don't save visitor default session" moved the geoip
from the session to the request with a deprecation warning. This commit
adapts the remaining modules to use `request.geoip` instead of
`request.session.geoip`.

Geoip is always set on the request but it can be an empty dictionnary in
case the geolocalization failed.

closes odoo/odoo#86015

Task: 2789035
Related: odoo/enterprise#25192
Signed-off-by: Julien Castiaux <juc@odoo.com>
2022-04-05 14:13:54 +02:00
Denis Ledoux aab3c3df06 [FIX] auth_totp_mail_enforce: browser falsy when using the Odoo app
When using the odoo app,
`request.httprequest.user_agent.browser` is `False`,
instead of a string expected.
Therefore, `capitalize` cannot be called

```
2022-03-02 09:44:01,267 1321846 ERROR dle-test1 odoo.addons.saas_trial.models.res_users: 2fa by email failed
Traceback (most recent call last):
  File "/home/odoo/src/custom/trial/saas_trial/models/res_users.py", line 267, in _send_totp_mail_code
    return super()._send_totp_mail_code()
  File "/home/odoo/src/odoo/saas-15.1/addons/auth_totp_mail_enforce/models/res_users.py", line 95, in _send_totp_mail_code
    'browser': request.httprequest.user_agent.browser.capitalize(),
AttributeError: 'NoneType' object has no attribute 'capitalize'
```

closes odoo/odoo#85684

X-original-commit: 5a87db453fcfd750934d1a1d62c00d93ad01c0e1
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
2022-03-02 22:16:52 +00:00
Denis Ledoux a08a0b6454 [ADD] auth_totp_mail: 2FA using code sent by email
Add the possibility to force the two-factor authentication for all users,
using a two-factor authentication by email
when the 2FA using an Authenticator app is not configured for the user.

Two possibilities:
 - Force the 2FA only for employee users using the system parameter `auth_totp.policy=employee_required`
 - Force the 2FA for all users, employees and portals, using the system parameter `auth_totp.policy=all_required`

closes odoo/odoo#83750

Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
2022-02-01 17:15:30 +00:00