From dc61c92f9019e7fac761842890fee1b9000a40ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Fri, 3 Nov 2023 00:33:15 +0100 Subject: [PATCH] fastapi_auth_partner: update AuthPartnerResponse --- fastapi_auth_partner/routers/auth.py | 8 ++++---- fastapi_auth_partner/schemas.py | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/fastapi_auth_partner/routers/auth.py b/fastapi_auth_partner/routers/auth.py index 6be7fb41..d17ed995 100644 --- a/fastapi_auth_partner/routers/auth.py +++ b/fastapi_auth_partner/routers/auth.py @@ -43,7 +43,7 @@ def register( env["fastapi.auth.service"].sudo()._register_auth(endpoint.directory_id, data) ) partner_auth._set_auth_cookie(response) - return AuthPartnerResponse.model_validate(partner_auth) + return AuthPartnerResponse.from_auth_partner(partner_auth) @auth_router.post("/auth/login") @@ -57,7 +57,7 @@ def login( env["fastapi.auth.service"].sudo()._login(endpoint.directory_id, data) ) partner_auth._set_auth_cookie(response) - return AuthPartnerResponse.model_validate(partner_auth) + return AuthPartnerResponse.from_auth_partner(partner_auth) @auth_router.post("/auth/logout", status_code=205) @@ -91,7 +91,7 @@ def set_password( env["fastapi.auth.service"].sudo()._set_password(endpoint.directory_id, data) ) partner_auth._set_auth_cookie(response) - return AuthPartnerResponse.model_validate(partner_auth) + return AuthPartnerResponse.from_auth_partner(partner_auth) @auth_router.get("/auth/profile") @@ -103,7 +103,7 @@ def profile( partner_auth = partner.auth_partner_ids.filtered( lambda s: s.directory_id == endpoint.sudo().directory_id ) - return AuthPartnerResponse.model_validate(partner_auth) + return AuthPartnerResponse.from_auth_partner(partner_auth) class AuthService(models.AbstractModel): diff --git a/fastapi_auth_partner/schemas.py b/fastapi_auth_partner/schemas.py index 5a2cd3fd..de44c04e 100644 --- a/fastapi_auth_partner/schemas.py +++ b/fastapi_auth_partner/schemas.py @@ -3,8 +3,6 @@ from extendable_pydantic import StrictExtendableBaseModel -from pydantic import ConfigDict - class AuthLoginInput(StrictExtendableBaseModel): login: str @@ -28,4 +26,7 @@ class AuthSetPasswordInput(StrictExtendableBaseModel): class AuthPartnerResponse(StrictExtendableBaseModel): login: str - model_config = ConfigDict(from_attributes=True) + + @classmethod + def from_auth_partner(cls, odoo_rec): + return cls.model_construct(login=odoo_rec.login)