Skip to content

Commit

Permalink
Fix rebase over modular-memberships
Browse files Browse the repository at this point in the history
  • Loading branch information
armanddidierjean committed Mar 3, 2025
1 parent a2b4f79 commit 62ab98b
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 40 deletions.
14 changes: 7 additions & 7 deletions app/core/myeclpay/cruds_myeclpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -15,6 +14,7 @@
WalletDeviceStatus,
WalletType,
)
from app.core.users import schemas_users


async def create_structure(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
15 changes: 7 additions & 8 deletions app/core/myeclpay/endpoints_myeclpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 10 additions & 6 deletions app/core/myeclpay/models_myeclpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -13,6 +13,7 @@
WalletDeviceStatus,
WalletType,
)
from app.core.users import models_users
from app.types.sqlalchemy import Base, PrimaryKey


Expand All @@ -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",
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions app/core/myeclpay/schemas_myeclpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -13,6 +12,7 @@
WalletDeviceStatus,
WalletType,
)
from app.core.users import schemas_users


class StructureBase(BaseModel):
Expand All @@ -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


Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 9 additions & 0 deletions app/core/users/models_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 1 addition & 5 deletions app/utils/auth/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
21 changes: 11 additions & 10 deletions tests/test_myeclpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -23,19 +23,20 @@
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,
create_api_access_token,
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 62ab98b

Please sign in to comment.