mirror of
https://github.com/suitenumerique/docs.git
synced 2026-09-29 04:55:11 +02:00
✨(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:
@@ -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
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user