Skip to content

Commit

Permalink
fastapi_auth_partner: migrate to pydantic 2
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienbeau committed Oct 29, 2023
1 parent 574380e commit e803926
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
8 changes: 4 additions & 4 deletions fastapi_auth_partner/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.from_orm(partner_auth)
return AuthPartnerResponse.model_validate(partner_auth)


@auth_router.post("/auth/login")
Expand All @@ -57,7 +57,7 @@ def login(
env["fastapi.auth.service"].sudo()._login(endpoint.directory_id, data)
)
partner_auth._set_auth_cookie(response)
return AuthPartnerResponse.from_orm(partner_auth)
return AuthPartnerResponse.model_validate(partner_auth)


@auth_router.post("/auth/logout", status_code=205)
Expand Down Expand Up @@ -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.from_orm(partner_auth)
return AuthPartnerResponse.model_validate(partner_auth)


@auth_router.get("/auth/profile")
Expand All @@ -103,7 +103,7 @@ def profile(
partner_auth = partner.auth_partner_ids.filtered(
lambda s: s.directory_id == endpoint.sudo().directory_id
)
return AuthPartnerResponse.from_orm(partner_auth)
return AuthPartnerResponse.model_validate(partner_auth)


class AuthService(models.AbstractModel):
Expand Down
21 changes: 8 additions & 13 deletions fastapi_auth_partner/schemas.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
# Copyright (c) Akretion 2020
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from extendable_pydantic import ExtendableModelMeta
from extendable_pydantic import StrictExtendableBaseModel

from odoo.addons.pydantic import utils
from pydantic import ConfigDict

from pydantic import BaseModel


class AuthLoginInput(BaseModel, metaclass=ExtendableModelMeta):
class AuthLoginInput(StrictExtendableBaseModel):
login: str
password: str


class AuthRegisterInput(BaseModel, metaclass=ExtendableModelMeta):
class AuthRegisterInput(StrictExtendableBaseModel):
name: str
login: str
password: str


class AuthForgetPasswordInput(BaseModel, metaclass=ExtendableModelMeta):
class AuthForgetPasswordInput(StrictExtendableBaseModel):
login: str


class AuthSetPasswordInput(BaseModel, metaclass=ExtendableModelMeta):
class AuthSetPasswordInput(StrictExtendableBaseModel):
token: str
password: str


class AuthPartnerResponse(BaseModel, metaclass=ExtendableModelMeta):
class AuthPartnerResponse(StrictExtendableBaseModel):
login: str

class Config:
orm_mode = True
getter_dict = utils.GenericOdooGetter
model_config = ConfigDict(from_attributes=True)

0 comments on commit e803926

Please sign in to comment.