Skip to content

Commit

Permalink
fix: prohibit sending or accepting an invite when already left
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaRedHand committed Jun 16, 2024
1 parent 5032ca5 commit 2f1361d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,13 @@ def send_invite(
if user_id_in_group(db, receiver.id, target_group):
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST,
detail=f"El usuario ya es miembro del equipo {target_group.name}",
detail=f"El usuario ya es miembro del grupo {target_group.name}",
)

if receiver.id in list(m.id for m in target_group.members):
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST,
detail=f"El usuario abandonó el grupo {target_group.name}",
)

token = uuid4()
Expand Down Expand Up @@ -672,6 +678,12 @@ def accept_invite(db: DbDependency, user: UserDependency, invite_token: str):
detail=f"El usuario ya es miembro del grupo {target_group.name}",
)

if user.id in list(m.id for m in target_group.members):
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST,
detail=f"El usuario abandonó el grupo {target_group.name}",
)

crud.add_user_to_group(db, user, target_group)
return crud.update_invite_status(db, target_invite, schemas.InviteStatus.ACCEPTED)

Expand Down

0 comments on commit 2f1361d

Please sign in to comment.