✨(backend) conditional email notification in server to server api

Add send_notification_email flag (defaults to True) on
the ServerCreateDocumentSerializer so that we can bypass
sending the email notification when creating a document
with the server to server API.

Signed-off-by: Florent Chehab <flo@nextmile.fr>
This commit is contained in:
Florent Chehab
2026-08-03 10:54:31 +02:00
parent eed828d8c7
commit edf26d6321
3 changed files with 31 additions and 1 deletions
+1
View File
@@ -10,6 +10,7 @@ and this project adheres to
- ♿️(frontend) restore skip to content link after header redesign #2510
- 🌐(i18n) rename cn_CN to zh_CN, add eo_PL and zh_TW locales #2486
- ✨(backend) conditional email notification in server to server api #2554
### Fixed
+3 -1
View File
@@ -453,6 +453,7 @@ class ServerCreateDocumentSerializer(serializers.Serializer):
language = serializers.ChoiceField(
required=False, choices=lazy(lambda: settings.LANGUAGES, tuple)()
)
send_notification_email = serializers.BooleanField(required=False, default=True)
# Invitation
message = serializers.CharField(required=False)
subject = serializers.CharField(required=False)
@@ -520,7 +521,8 @@ class ServerCreateDocumentSerializer(serializers.Serializer):
document.content = document_content
document.save()
self._send_email_notification(document, validated_data, email, language)
if validated_data.get("send_notification_email", True):
self._send_email_notification(document, validated_data, email, language)
return document
def _send_email_notification(self, document, validated_data, email, language):
@@ -312,6 +312,33 @@ def test_api_documents_create_for_owner_new_user(mock_convert_md):
assert document.creator == user
@override_settings(SERVER_TO_SERVER_API_TOKENS=["DummyToken"])
def test_api_documents_create_for_owner_without_notification_email(mock_convert_md):
"""The caller can disable the notification email when creating the document."""
data = {
"title": "My Document",
"content": "Document content",
"sub": "123",
"email": "john.doe@example.com",
"send_notification_email": False,
}
response = APIClient().post(
"/api/v1.0/documents/create-for-owner/",
data,
format="json",
HTTP_AUTHORIZATION="Bearer DummyToken",
)
assert response.status_code == 201
assert mock_convert_md.called is True
assert Document.objects.exists()
assert Invitation.objects.filter(
email="john.doe@example.com", role="owner"
).exists()
assert len(mail.outbox) == 0
@override_settings(
SERVER_TO_SERVER_API_TOKENS=["DummyToken"],
OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION=True,