Skip to content
Snippets Groups Projects
Commit a5c09ec4 authored by Tore.Brede's avatar Tore.Brede
Browse files

Deleting person when cancelling invite

parent 0706be63
No related branches found
No related tags found
1 merge request!136GREG-94: Resend invitation
......@@ -71,8 +71,8 @@ class InvitationView(CreateAPIView, DestroyAPIView):
person = serializer.save()
for invitationlink in InvitationLink.objects.filter(
invitation__role__person_id=person.id,
invitation__role__sponsor_id=sponsor_user.sponsor_id,
invitation__role__person_id=person.id,
invitation__role__sponsor_id=sponsor_user.sponsor_id,
):
send_invite_mail(invitationlink)
......@@ -80,9 +80,8 @@ class InvitationView(CreateAPIView, DestroyAPIView):
def delete(self, request, *args, **kwargs) -> Response:
person_id = int(request.query_params["person_id"])
# TODO Determine if person should be deleted as well
person = Person.objects.get(id=person_id)
if person.is_registered or person.is_verified:
# The guest has already gone through the registration step. The guest should
# not be verified, but including that check just in case here.
......@@ -93,18 +92,10 @@ class InvitationView(CreateAPIView, DestroyAPIView):
)
return Response(status.HTTP_400_BAD_REQUEST)
# Since the person is not registered, all roles attached to invitations for him should be removed
invitationlinks = InvitationLink.objects.filter(
invitation__role__person_id=person_id
)
roles = set(
[invitationlink.invitation.role for invitationlink in invitationlinks]
)
for role in roles:
# Delete the role, the cascading will cause all the invitation links connected
# to it to be removed as well
role.delete()
# Delete the person. The delete will cascade and all roles, identities and invitations will be removed.
# It is OK to do this here since the person has not gone through the registration, so it is not
# expected that there is any information that cannot be deleted without problems attached to him
person.delete()
return Response(status=status.HTTP_200_OK)
......@@ -286,7 +277,7 @@ class InvitedGuestView(GenericAPIView):
@staticmethod
def _get_identity_or_none(
person: Person, identity_type: Identity.IdentityType
person: Person, identity_type: Identity.IdentityType
) -> Optional[str]:
try:
return person.identities.get(type=identity_type).value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment