Only return pending invitations from incomming

This commit is contained in:
Peter Vacho 2024-12-29 14:59:29 +01:00
parent b6052eceb9
commit fcf5a5d64d
Signed by: school
GPG key ID: 8CFC3837052871B4

View file

@ -150,6 +150,7 @@ async def get_user_incomming_invitatinos(user_id: PydanticObjectId, user: Curren
"""Get all incoming invitations for a given user. """Get all incoming invitations for a given user.
Note that this endpoint only allows you to access the invitations you received. Note that this endpoint only allows you to access the invitations you received.
Only invitations with status "pending" are returned.
""" """
if user.id is None: if user.id is None:
raise MissingIdError(user) raise MissingIdError(user)
@ -157,7 +158,11 @@ async def get_user_incomming_invitatinos(user_id: PydanticObjectId, user: Curren
if user.id != user_id: if user.id != user_id:
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="You can only access your own invitations.") raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="You can only access your own invitations.")
invitations = await Invitation.find(expr(Invitation.invitee).id == user_id, fetch_links=True).to_list() invitations = await Invitation.find(
expr(Invitation.invitee).id == user_id,
Invitation.status == "pending",
fetch_links=True,
).to_list()
return [InvitationData.from_invitation(invitation) for invitation in invitations] return [InvitationData.from_invitation(invitation) for invitation in invitations]