Skip to content

Commit

Permalink
Fix: rename CGU as TOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Rotheem committed Jan 10, 2025
1 parent d63a2d2 commit 1c0b7f6
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 56 deletions.
16 changes: 8 additions & 8 deletions app/core/myeclpay/cruds_myeclpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,31 +392,31 @@ async def increment_wallet_balance(
async def create_user_payment(
user_id: str,
wallet_id: UUID,
accepted_cgu_signature: datetime,
accepted_cgu_version: int,
accepted_tos_signature: datetime,
accepted_tos_version: int,
db: AsyncSession,
) -> None:
user_payment = models_myeclpay.UserPayment(
user_id=user_id,
wallet_id=wallet_id,
accepted_cgu_signature=accepted_cgu_signature,
accepted_cgu_version=accepted_cgu_version,
accepted_tos_signature=accepted_tos_signature,
accepted_tos_version=accepted_tos_version,
)
db.add(user_payment)


async def update_user_payment(
user_id: str,
accepted_cgu_signature: datetime,
accepted_cgu_version: int,
accepted_tos_signature: datetime,
accepted_tos_version: int,
db: AsyncSession,
) -> None:
await db.execute(
update(models_myeclpay.UserPayment)
.where(models_myeclpay.UserPayment.user_id == user_id)
.values(
accepted_cgu_signature=accepted_cgu_signature,
accepted_cgu_version=accepted_cgu_version,
accepted_tos_signature=accepted_tos_signature,
accepted_tos_version=accepted_tos_version,
),
)

Expand Down
68 changes: 33 additions & 35 deletions app/core/myeclpay/endpoints_myeclpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
WalletType,
)
from app.core.myeclpay.utils_myeclpay import (
CGU_CONTENT,
LATEST_CGU,
LATEST_TOS,
MAX_TRANSACTION_TOTAL,
QRCODE_EXPIRATION,
TOS_CONTENT,
compute_signable_data,
is_user_latest_cgu_signed,
is_user_latest_tos_signed,
verify_signature,
)
from app.core.notification.schemas_notification import Message
Expand Down Expand Up @@ -67,8 +67,6 @@ async def get_structures(
):
"""
Get all structures.
**The user must be an admin to use this endpoint**
"""
structures = await cruds_myeclpay.get_structures(
db=db,
Expand Down Expand Up @@ -635,16 +633,16 @@ async def update_store(


@router.get(
"/myeclpay/users/me/cgu",
"/myeclpay/users/me/tos",
status_code=200,
response_model=schemas_myeclpay.CGUSignatureResponse,
response_model=schemas_myeclpay.TOSSignatureResponse,
)
async def get_cgu(
async def get_tos(
db: AsyncSession = Depends(get_db),
user: CoreUser = Depends(is_user()),
):
"""
Get the latest CGU version and the user signed CGU version.
Get the latest TOS version and the user signed TOS version.
**The user must be authenticated to use this endpoint**
"""
Expand All @@ -659,10 +657,10 @@ async def get_cgu(
detail="User is not registered for MyECL Pay",
)

return schemas_myeclpay.CGUSignatureResponse(
accepted_cgu_version=existing_user_payment.accepted_cgu_version,
latest_cgu_version=LATEST_CGU,
cgu_content=CGU_CONTENT,
return schemas_myeclpay.TOSSignatureResponse(
accepted_tos_version=existing_user_payment.accepted_tos_version,
latest_tos_version=LATEST_TOS,
tos_content=TOS_CONTENT,
)


Expand All @@ -675,9 +673,9 @@ async def register_user(
user: CoreUser = Depends(is_user()),
):
"""
Sign MyECL Pay CGU for the given user.
Sign MyECL Pay TOS for the given user.
The user will need to accept the latest CGU version to be able to use MyECL Pay.
The user will need to accept the latest TOS version to be able to use MyECL Pay.
**The user must be authenticated to use this endpoint**
"""
Expand Down Expand Up @@ -708,36 +706,36 @@ async def register_user(
await cruds_myeclpay.create_user_payment(
user_id=user.id,
wallet_id=wallet_id,
accepted_cgu_signature=datetime.now(UTC),
accepted_cgu_version=0,
accepted_tos_signature=datetime.now(UTC),
accepted_tos_version=0,
db=db,
)

await db.commit()


@router.post(
"/myeclpay/users/me/cgu",
"/myeclpay/users/me/tos",
status_code=204,
)
async def sign_cgu(
signature: schemas_myeclpay.CGUSignature,
async def sign_tos(
signature: schemas_myeclpay.TOSSignature,
background_tasks: BackgroundTasks,
db: AsyncSession = Depends(get_db),
user: CoreUser = Depends(is_user()),
settings: Settings = Depends(get_settings),
):
"""
Sign MyECL Pay CGU for the given user.
Sign MyECL Pay TOS for the given user.
If the user is already registered in the MyECLPay system, this will update the CGU version.
If the user is already registered in the MyECLPay system, this will update the TOS version.
**The user must be authenticated to use this endpoint**
"""
if signature.accepted_cgu_version != LATEST_CGU:
if signature.accepted_tos_version != LATEST_TOS:
raise HTTPException(
status_code=400,
detail=f"Only the latest CGU version {LATEST_CGU} is accepted",
detail=f"Only the latest TOS version {LATEST_TOS} is accepted",
)

# Check if user is already registered
Expand All @@ -754,8 +752,8 @@ async def sign_cgu(
# Update existing user payment
await cruds_myeclpay.update_user_payment(
user_id=user.id,
accepted_cgu_signature=datetime.now(UTC),
accepted_cgu_version=signature.accepted_cgu_version,
accepted_tos_signature=datetime.now(UTC),
accepted_tos_version=signature.accepted_tos_version,
db=db,
)

Expand All @@ -773,7 +771,7 @@ async def sign_cgu(
background_tasks.add_task(
send_email,
recipient=user.email,
subject="MyECL - you have signed CGU",
subject="MyECL - you have signed TOS",
content=account_exists_content,
settings=settings,
)
Expand All @@ -798,7 +796,7 @@ async def get_user_devices(
user_id=user.id,
db=db,
)
if user_payment is None or not is_user_latest_cgu_signed(user_payment):
if user_payment is None or not is_user_latest_tos_signed(user_payment):
raise HTTPException(
status_code=400,
detail="User is not registered for MyECL Pay",
Expand Down Expand Up @@ -832,7 +830,7 @@ async def get_user_device(
user_id=user.id,
db=db,
)
if user_payment is None or not is_user_latest_cgu_signed(user_payment):
if user_payment is None or not is_user_latest_tos_signed(user_payment):
raise HTTPException(
status_code=400,
detail="User is not registered for MyECL Pay",
Expand Down Expand Up @@ -877,7 +875,7 @@ async def get_user_wallet(
user_id=user.id,
db=db,
)
if user_payment is None or not is_user_latest_cgu_signed(user_payment):
if user_payment is None or not is_user_latest_tos_signed(user_payment):
raise HTTPException(
status_code=400,
detail="User is not registered for MyECL Pay",
Expand Down Expand Up @@ -920,7 +918,7 @@ async def create_user_devices(
user_id=user.id,
db=db,
)
if user_payment is None or not is_user_latest_cgu_signed(user_payment):
if user_payment is None or not is_user_latest_tos_signed(user_payment):
raise HTTPException(
status_code=400,
detail="User is not registered for MyECL Pay",
Expand Down Expand Up @@ -1027,7 +1025,7 @@ async def revoke_user_devices(
user_id=user.id,
db=db,
)
if user_payment is None or not is_user_latest_cgu_signed(user_payment):
if user_payment is None or not is_user_latest_tos_signed(user_payment):
raise HTTPException(
status_code=400,
detail="User is not registered for MyECL Pay",
Expand Down Expand Up @@ -1083,7 +1081,7 @@ async def get_user_wallet_history(
detail="User is not registered for MyECL Pay",
)

is_user_latest_cgu_signed(user_payment)
is_user_latest_tos_signed(user_payment)

history: list[schemas_myeclpay.History] = []

Expand Down Expand Up @@ -1307,12 +1305,12 @@ async def store_scan_qrcode(
debited_wallet.user.id,
db=db,
)
if debited_user_payment is None or not is_user_latest_cgu_signed(
if debited_user_payment is None or not is_user_latest_tos_signed(
debited_user_payment,
):
raise HTTPException(
status_code=400,
detail="Debited user has not signed the latest CGU",
detail="Debited user has not signed the latest TOS",
)

if debited_wallet.balance < qr_code_content.total:
Expand Down
4 changes: 2 additions & 2 deletions app/core/myeclpay/models_myeclpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ class UserPayment(Base):
ForeignKey("myeclpay_wallet.id"),
unique=True,
)
accepted_cgu_signature: Mapped[datetime]
accepted_cgu_version: Mapped[int]
accepted_tos_signature: Mapped[datetime]
accepted_tos_version: Mapped[int]


class UsedQRCode(Base):
Expand Down
12 changes: 6 additions & 6 deletions app/core/myeclpay/schemas_myeclpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ class Seller(BaseModel):
user: schemas_core.CoreUserSimple


class CGUSignature(BaseModel):
accepted_cgu_version: int
class TOSSignature(BaseModel):
accepted_tos_version: int


class CGUSignatureResponse(BaseModel):
accepted_cgu_version: int
latest_cgu_version: int
cgu_content: str
class TOSSignatureResponse(BaseModel):
accepted_tos_version: int
latest_tos_version: int
tos_content: str


class History(BaseModel):
Expand Down
10 changes: 5 additions & 5 deletions app/core/myeclpay/utils_myeclpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
hyperion_security_logger = logging.getLogger("hyperion.security")


LATEST_CGU = 1
CGU_CONTENT = "CGU Content"
LATEST_TOS = 1
TOS_CONTENT = "TOS Content"
MAX_TRANSACTION_TOTAL = 2000
QRCODE_EXPIRATION = 5 # minutes

Expand Down Expand Up @@ -57,11 +57,11 @@ def verify_signature(
return True


def is_user_latest_cgu_signed(
def is_user_latest_tos_signed(
user_payment: UserPayment,
) -> bool:
"""
Check if the user has signed the latest CGU version.
Check if the user has signed the latest TOS version.
"""

return user_payment.accepted_cgu_version == LATEST_CGU
return user_payment.accepted_tos_version == LATEST_TOS

0 comments on commit 1c0b7f6

Please sign in to comment.