From 62ab98bc53be4c244bfda905b7ec2c8052298e05 Mon Sep 17 00:00:00 2001 From: armanddidierjean <95971503+armanddidierjean@users.noreply.github.com> Date: Mon, 3 Mar 2025 15:05:28 +0100 Subject: [PATCH] Fix rebase over modular-memberships --- app/core/myeclpay/cruds_myeclpay.py | 14 +++++++------- app/core/myeclpay/endpoints_myeclpay.py | 15 +++++++-------- app/core/myeclpay/models_myeclpay.py | 16 ++++++++++------ app/core/myeclpay/schemas_myeclpay.py | 8 ++++---- app/core/users/models_users.py | 9 +++++++++ app/utils/auth/providers.py | 6 +----- tests/test_myeclpay.py | 21 +++++++++++---------- 7 files changed, 49 insertions(+), 40 deletions(-) diff --git a/app/core/myeclpay/cruds_myeclpay.py b/app/core/myeclpay/cruds_myeclpay.py index 5b359c6a60..0c302765ae 100644 --- a/app/core/myeclpay/cruds_myeclpay.py +++ b/app/core/myeclpay/cruds_myeclpay.py @@ -6,7 +6,6 @@ from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.orm import selectinload -from app.core.core_endpoints import schemas_core from app.core.memberships import schemas_memberships from app.core.myeclpay import models_myeclpay, schemas_myeclpay from app.core.myeclpay.types_myeclpay import ( @@ -15,6 +14,7 @@ WalletDeviceStatus, WalletType, ) +from app.core.users import schemas_users async def create_structure( @@ -125,7 +125,7 @@ async def get_structures( else None, manager_user_id=structure.manager_user_id, id=structure.id, - manager_user=schemas_core.CoreUserSimple( + manager_user=schemas_users.CoreUserSimple( id=structure.manager_user.id, firstname=structure.manager_user.firstname, name=structure.manager_user.name, @@ -166,7 +166,7 @@ async def get_structure_by_id( else None, manager_user_id=structure.manager_user_id, id=structure.id, - manager_user=schemas_core.CoreUserSimple( + manager_user=schemas_users.CoreUserSimple( id=structure.manager_user.id, firstname=structure.manager_user.firstname, name=structure.manager_user.name, @@ -273,7 +273,7 @@ async def get_seller( can_see_history=result.can_see_history, can_cancel=result.can_cancel, can_manage_sellers=result.can_manage_sellers, - user=schemas_core.CoreUserSimple( + user=schemas_users.CoreUserSimple( id=result.user.id, firstname=result.user.firstname, name=result.user.name, @@ -304,7 +304,7 @@ async def get_sellers_by_store_id( can_see_history=seller.can_see_history, can_cancel=seller.can_cancel, can_manage_sellers=seller.can_manage_sellers, - user=schemas_core.CoreUserSimple( + user=schemas_users.CoreUserSimple( id=seller.user.id, firstname=seller.user.firstname, name=seller.user.name, @@ -405,7 +405,7 @@ async def get_wallets( if wallet.store.structure.association_membership else None, manager_user_id=wallet.store.structure.manager_user_id, - manager_user=schemas_core.CoreUserSimple( + manager_user=schemas_users.CoreUserSimple( id=wallet.store.structure.manager_user.id, firstname=wallet.store.structure.manager_user.firstname, name=wallet.store.structure.manager_user.name, @@ -418,7 +418,7 @@ async def get_wallets( ) if wallet.store else None, - user=schemas_core.CoreUser( + user=schemas_users.CoreUser( id=wallet.user.id, firstname=wallet.user.firstname, name=wallet.user.name, diff --git a/app/core/myeclpay/endpoints_myeclpay.py b/app/core/myeclpay/endpoints_myeclpay.py index 9a858097cb..8de2f6c631 100644 --- a/app/core/myeclpay/endpoints_myeclpay.py +++ b/app/core/myeclpay/endpoints_myeclpay.py @@ -8,10 +8,6 @@ from sqlalchemy.exc import IntegrityError from sqlalchemy.ext.asyncio import AsyncSession -from app.core import security -from app.core.config import Settings -from app.core.core_endpoints import schemas_core -from app.core.core_endpoints.models_core import CoreUser from app.core.groups.groups_type import GroupType from app.core.memberships import cruds_memberships, schemas_memberships from app.core.myeclpay import cruds_myeclpay, schemas_myeclpay @@ -38,7 +34,10 @@ from app.core.notification.schemas_notification import Message from app.core.payment import cruds_payment, schemas_payment from app.core.payment.payment_tool import PaymentTool -from app.core.users import cruds_users +from app.core.users import cruds_users, schemas_users +from app.core.users.models_users import CoreUser +from app.core.utils import security +from app.core.utils.config import Settings from app.dependencies import ( get_db, get_notification_tool, @@ -119,7 +118,7 @@ async def create_structure( association_membership_id=structure.association_membership_id, association_membership=None, manager_user_id=structure.manager_user_id, - manager_user=schemas_core.CoreUserSimple( + manager_user=schemas_users.CoreUserSimple( id=db_user.id, name=db_user.name, firstname=db_user.firstname, @@ -547,7 +546,7 @@ async def get_user_stores( if store.structure.association_membership is not None else None, manager_user_id=store.structure.manager_user_id, - manager_user=schemas_core.CoreUserSimple( + manager_user=schemas_users.CoreUserSimple( id=store.structure.manager_user.id, name=store.structure.manager_user.name, firstname=store.structure.manager_user.firstname, @@ -1713,7 +1712,7 @@ async def init_ha_transfer( detail="Wallet balance would exceed the maximum allowed balance", ) - user_schema = schemas_core.CoreUser( + user_schema = schemas_users.CoreUser( account_type=user.account_type, school_id=user.school_id, email=user.email, diff --git a/app/core/myeclpay/models_myeclpay.py b/app/core/myeclpay/models_myeclpay.py index 9f8d998988..47fab576c0 100644 --- a/app/core/myeclpay/models_myeclpay.py +++ b/app/core/myeclpay/models_myeclpay.py @@ -4,7 +4,7 @@ from sqlalchemy import ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship -from app.core.core_endpoints import models_core +from app.core.memberships import models_memberships from app.core.myeclpay.types_myeclpay import ( RequestStatus, TransactionStatus, @@ -13,6 +13,7 @@ WalletDeviceStatus, WalletType, ) +from app.core.users import models_users from app.types.sqlalchemy import Base, PrimaryKey @@ -24,7 +25,7 @@ class Wallet(Base): balance: Mapped[int] # Stored in cents store: Mapped["Store | None"] = relationship(init=False, lazy="joined") - user: Mapped[models_core.CoreUser | None] = relationship( + user: Mapped[models_users.CoreUser | None] = relationship( init=False, secondary="myeclpay_user_payment", lazy="joined", @@ -108,10 +109,13 @@ class Structure(Base): default=None, ) - manager_user: Mapped[models_core.CoreUser] = relationship(init=False, lazy="joined") - association_membership: Mapped[models_core.CoreAssociationMembership | None] = ( - relationship(init=False, lazy="joined") + manager_user: Mapped[models_users.CoreUser] = relationship( + init=False, + lazy="joined", ) + association_membership: Mapped[ + models_memberships.CoreAssociationMembership | None + ] = relationship(init=False, lazy="joined") class StructureManagerTransfert(Base): @@ -190,7 +194,7 @@ class Seller(Base): can_cancel: Mapped[bool] can_manage_sellers: Mapped[bool] - user: Mapped[models_core.CoreUser] = relationship(init=False, lazy="joined") + user: Mapped[models_users.CoreUser] = relationship(init=False, lazy="joined") class UserPayment(Base): diff --git a/app/core/myeclpay/schemas_myeclpay.py b/app/core/myeclpay/schemas_myeclpay.py index 9d7a0b971b..6a9b903b62 100644 --- a/app/core/myeclpay/schemas_myeclpay.py +++ b/app/core/myeclpay/schemas_myeclpay.py @@ -3,7 +3,6 @@ from pydantic import Base64Bytes, BaseModel, HttpUrl -from app.core.core_endpoints import schemas_core from app.core.memberships import schemas_memberships from app.core.myeclpay.types_myeclpay import ( HistoryType, @@ -13,6 +12,7 @@ WalletDeviceStatus, WalletType, ) +from app.core.users import schemas_users class StructureBase(BaseModel): @@ -23,7 +23,7 @@ class StructureBase(BaseModel): class Structure(StructureBase): id: UUID - manager_user: schemas_core.CoreUserSimple + manager_user: schemas_users.CoreUserSimple association_membership: schemas_memberships.MembershipSimple | None @@ -81,7 +81,7 @@ class Seller(BaseModel): can_cancel: bool can_manage_sellers: bool - user: schemas_core.CoreUserSimple + user: schemas_users.CoreUserSimple class TOSSignature(BaseModel): @@ -160,7 +160,7 @@ class Wallet(BaseModel): type: WalletType balance: int store: Store | None - user: schemas_core.CoreUser | None + user: schemas_users.CoreUser | None class WalletInfo(BaseModel): diff --git a/app/core/users/models_users.py b/app/core/users/models_users.py index 41695bbfb4..b3b4682323 100644 --- a/app/core/users/models_users.py +++ b/app/core/users/models_users.py @@ -54,6 +54,15 @@ class CoreUser(Base): init=False, ) + @property + def full_name(self) -> str: + """ + Return the full name of the user, including first name, name and nickname if it exists. + """ + if self.nickname: + return f"{self.firstname} {self.name} ({self.nickname})" + return f"{self.firstname} {self.name}" + class CoreUserUnconfirmed(Base): __tablename__ = "core_user_unconfirmed" diff --git a/app/utils/auth/providers.py b/app/utils/auth/providers.py index 1adefd533a..1037fec945 100644 --- a/app/utils/auth/providers.py +++ b/app/utils/auth/providers.py @@ -413,10 +413,6 @@ def get_userinfo(self, user: models_users.CoreUser) -> dict[str, Any]: # WARNING: The sub (subject) Claim MUST always be returned in the UserInfo Response. return { "sub": user.id, - "name": get_display_name( - firstname=user.firstname, - name=user.name, - nickname=user.nickname, - ), + "name": user.full_name, "email": user.email, } diff --git a/tests/test_myeclpay.py b/tests/test_myeclpay.py index 417af53d76..602f445846 100644 --- a/tests/test_myeclpay.py +++ b/tests/test_myeclpay.py @@ -11,8 +11,8 @@ from fastapi.testclient import TestClient from pytest_mock import MockerFixture -from app.core.core_endpoints import models_core from app.core.groups.groups_type import GroupType +from app.core.memberships import models_memberships from app.core.myeclpay import cruds_myeclpay, models_myeclpay from app.core.myeclpay.schemas_myeclpay import QRCodeContentBase from app.core.myeclpay.types_myeclpay import ( @@ -23,6 +23,7 @@ WalletType, ) from app.core.myeclpay.utils_myeclpay import LATEST_TOS, compute_signable_data +from app.core.users import models_users from tests.commons import ( TestingSessionLocal, add_object_to_db, @@ -30,12 +31,12 @@ create_user_with_groups, ) -admin_user: models_core.CoreUser +admin_user: models_users.CoreUser admin_user_token: str -structure_manager_user: models_core.CoreUser +structure_manager_user: models_users.CoreUser structure_manager_user_token: str -ecl_user: models_core.CoreUser +ecl_user: models_users.CoreUser ecl_user_access_token: str ecl_user_wallet: models_myeclpay.Wallet ecl_user_wallet_device_private_key: Ed25519PrivateKey @@ -45,14 +46,14 @@ ecl_user_payment: models_myeclpay.UserPayment ecl_user_transfer: models_myeclpay.Transfer -ecl_user2: models_core.CoreUser +ecl_user2: models_users.CoreUser ecl_user2_access_token: str ecl_user2_wallet: models_myeclpay.Wallet ecl_user2_wallet_device: models_myeclpay.WalletDevice ecl_user2_payment: models_myeclpay.UserPayment -association_membership: models_core.CoreAssociationMembership -association_membership_user: models_core.CoreAssociationUserMembership +association_membership: models_memberships.CoreAssociationMembership +association_membership_user: models_memberships.CoreAssociationUserMembership structure: models_myeclpay.Structure store_wallet: models_myeclpay.Wallet store: models_myeclpay.Store @@ -68,7 +69,7 @@ used_qr_code: models_myeclpay.UsedQRCode -store_seller_can_bank_user: models_core.CoreUser +store_seller_can_bank_user: models_users.CoreUser store_seller_no_permission_user_access_token: str store_seller_can_bank_user_access_token: str store_seller_can_cancel_user_access_token: str @@ -86,7 +87,7 @@ async def init_objects() -> None: admin_user_token = create_api_access_token(admin_user) global association_membership - association_membership = models_core.CoreAssociationMembership( + association_membership = models_memberships.CoreAssociationMembership( id=uuid4(), name="Test Association Membership", group_id=GroupType.BDE, @@ -115,7 +116,7 @@ async def init_objects() -> None: ) ecl_user_access_token = create_api_access_token(ecl_user) - association_membership_user = models_core.CoreAssociationUserMembership( + association_membership_user = models_memberships.CoreAssociationUserMembership( id=uuid4(), user_id=ecl_user.id, association_membership_id=association_membership.id,