♻️(backend) refacto email invitation

Remove email invitation from Invitation model
to be able to use it in other context.
We add it in utils.py instead, and it will be called
from the viewset.
We add the document_id to link to the document from
the mail.
This commit is contained in:
Anthony LC
2024-08-15 15:38:38 +02:00
committed by Anthony LC
parent 2391098aba
commit 2f8c5637f4
8 changed files with 143 additions and 123 deletions

View File

@@ -1,4 +1,5 @@
"""API endpoints"""
from core.utils import email_invitation
from django.contrib.postgres.aggregates import ArrayAgg
from django.db.models import (
OuterRef,
@@ -598,3 +599,10 @@ class InvitationViewset(
.distinct()
)
return queryset
def perform_create(self, serializer):
"""Save invitation to a document then send an email to the invited user."""
invitation = serializer.save()
language = self.request.headers.get("Content-Language", "en-us")
email_invitation(language, invitation.email, invitation.document.id)