Skip to content

Commit

Permalink
fastapi_auth_partner: fix access right
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienbeau committed Dec 15, 2023
1 parent 947569f commit 4a88a04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions fastapi_auth_partner/models/fastapi_auth_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 6 additions & 5 deletions fastapi_auth_partner/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)

0 comments on commit 4a88a04

Please sign in to comment.