diff --git a/fastapi_auth_partner/models/fastapi_auth_partner.py b/fastapi_auth_partner/models/fastapi_auth_partner.py index 0f1bfe3e..40e023d2 100644 --- a/fastapi_auth_partner/models/fastapi_auth_partner.py +++ b/fastapi_auth_partner/models/fastapi_auth_partner.py @@ -185,15 +185,16 @@ def send_reset_password(self, template, force_expiration=None): self.nbr_pending_reset_sent += 1 return "Instruction sent by email" - def request_reset_password(self, directory, login): + def request_reset_password(self, directory_id, login): # request_reset_password is called from a job so we return the result as a string auth = self.search( [ - ("directory_id", "=", directory.id), + ("directory_id", "=", directory_id), ("login", "=", login), ] ) if auth: + directory = self.env["fastapi.auth.directory"].browse(directory_id) template = self._get_template_request_reset_password(directory) if not template: raise UserError( diff --git a/fastapi_auth_partner/routers/auth.py b/fastapi_auth_partner/routers/auth.py index d17ed995..74a0601b 100644 --- a/fastapi_auth_partner/routers/auth.py +++ b/fastapi_auth_partner/routers/auth.py @@ -10,7 +10,7 @@ else: from typing_extensions import Annotated -from odoo import _, fields, models +from odoo import SUPERUSER_ID, _, fields, models from odoo.api import Environment from odoo.addons.base.models.res_partner import Partner @@ -76,8 +76,9 @@ def request_reset_password( endpoint: Annotated[FastapiEndpoint, Depends(fastapi_endpoint)], ): env["fastapi.auth.service"].sudo()._request_reset_password( - endpoint.directory_id, data + endpoint.directory_id.id, data ) + return {} @auth_router.post("/auth/set_password") @@ -157,6 +158,6 @@ def _set_password(self, directory, data): return partner_auth def _request_reset_password(self, directory, data): - self.env["fastapi.auth.partner"].sudo().with_delay().request_reset_password( - directory, data.login - ) + self.env["fastapi.auth.partner"].with_user( + SUPERUSER_ID + ).with_delay().request_reset_password(directory, data.login)