|
3 | 3 | # @author Florian Mounier <florian.mounier@akretion.com> |
4 | 4 | # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
5 | 5 |
|
6 | | -import sys |
7 | | - |
8 | | -if sys.version_info >= (3, 9): |
9 | | - from typing import Annotated |
10 | | -else: |
11 | | - from typing import Annotated |
12 | | - |
13 | 6 | from datetime import datetime, timedelta, timezone |
| 7 | +from typing import Annotated |
14 | 8 |
|
15 | 9 | from itsdangerous import URLSafeTimedSerializer |
16 | 10 |
|
17 | | -from odoo import _, fields, models, tools |
| 11 | +from odoo import fields, models, tools |
18 | 12 | from odoo.api import Environment |
19 | 13 | from odoo.exceptions import ValidationError |
20 | 14 |
|
@@ -157,23 +151,34 @@ class AuthService(models.AbstractModel): |
157 | 151 | directory_id = fields.Many2one("auth.directory") |
158 | 152 |
|
159 | 153 | def new(self, vals, **kwargs): |
| 154 | + # As we are in an abstract model, we need to bypass cache since it's |
| 155 | + # based on the record id (and there is none) |
| 156 | + endpoint = vals.pop("endpoint_id") |
| 157 | + |
160 | 158 | rec = super().new(vals, **kwargs) |
161 | 159 | # Can't have computed / related field in AbstractModel |
| 160 | + rec.endpoint_id = endpoint |
162 | 161 | rec.directory_id = rec.endpoint_id.directory_id |
163 | 162 | # Auto add endpoint context for mail context |
164 | | - return rec.with_context(_fastapi_endpoint_id=vals["endpoint_id"].id) |
| 163 | + return rec.with_context(_fastapi_endpoint_id=endpoint.id) |
165 | 164 |
|
166 | 165 | def _get_auth_from_partner(self, partner): |
167 | 166 | return partner._get_auth_partner_for_directory(self.directory_id) |
168 | 167 |
|
169 | 168 | def _signup(self, data): |
170 | 169 | auth_partner = ( |
171 | | - self.env["auth.partner"].sudo()._signup(self.directory_id, **data.dict()) |
| 170 | + self.env["auth.partner"] |
| 171 | + .sudo() |
| 172 | + ._signup(self.directory_id, **data.model_dump()) |
172 | 173 | ) |
173 | 174 | return auth_partner |
174 | 175 |
|
175 | 176 | def _login(self, data): |
176 | | - return self.env["auth.partner"].sudo()._login(self.directory_id, **data.dict()) |
| 177 | + return ( |
| 178 | + self.env["auth.partner"] |
| 179 | + .sudo() |
| 180 | + ._login(self.directory_id, **data.model_dump()) |
| 181 | + ) |
177 | 182 |
|
178 | 183 | def _impersonate(self, token): |
179 | 184 | return self.env["auth.partner"].sudo()._impersonating(self.directory_id, token) |
@@ -224,7 +229,7 @@ def _prepare_cookie_payload(self, partner): |
224 | 229 | def _prepare_cookie(self, partner): |
225 | 230 | secret = self.directory_id.cookie_secret_key or self.directory_id.secret_key |
226 | 231 | if not secret: |
227 | | - raise ValidationError(_("No cookie secret key defined")) |
| 232 | + raise ValidationError(self.env._("No cookie secret key defined")) |
228 | 233 | payload = self._prepare_cookie_payload(partner) |
229 | 234 | value = URLSafeTimedSerializer(secret).dumps(payload) |
230 | 235 | exp = ( |
|
0 commit comments