-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛(backend) email invite in receivers language
E-mails sent for granting access are sent in the receiving users language. Falling back to system default language.
- Loading branch information
Showing
11 changed files
with
93 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,7 +368,7 @@ def test_api_document_invitations_create_privileged_members( | |
Only owners and administrators should be able to invite new users. | ||
Only owners can invite owners. | ||
""" | ||
user = factories.UserFactory() | ||
user = factories.UserFactory(language="en-us") | ||
document = factories.DocumentFactory() | ||
if via == USER: | ||
factories.UserDocumentAccessFactory(document=document, user=user, role=inviting) | ||
|
@@ -417,94 +417,11 @@ def test_api_document_invitations_create_privileged_members( | |
} | ||
|
||
|
||
def test_api_document_invitations_create_email_from_content_language(): | ||
""" | ||
The email generated is from the language set in the Content-Language header | ||
""" | ||
user = factories.UserFactory() | ||
document = factories.DocumentFactory() | ||
factories.UserDocumentAccessFactory(document=document, user=user, role="owner") | ||
|
||
invitation_values = { | ||
"email": "[email protected]", | ||
"role": "reader", | ||
} | ||
|
||
assert len(mail.outbox) == 0 | ||
|
||
client = APIClient() | ||
client.force_login(user) | ||
|
||
response = client.post( | ||
f"/api/v1.0/documents/{document.id!s}/invitations/", | ||
invitation_values, | ||
format="json", | ||
headers={"Content-Language": "fr-fr"}, | ||
) | ||
|
||
assert response.status_code == 201 | ||
assert response.json()["email"] == "[email protected]" | ||
assert models.Invitation.objects.count() == 1 | ||
assert len(mail.outbox) == 1 | ||
|
||
email = mail.outbox[0] | ||
|
||
assert email.to == ["[email protected]"] | ||
|
||
email_content = " ".join(email.body.split()) | ||
assert ( | ||
f"{user.full_name} a partagé un document avec vous: {document.title}" | ||
in email_content | ||
) | ||
|
||
|
||
def test_api_document_invitations_create_email_from_content_language_not_supported(): | ||
""" | ||
If the language from the Content-Language is not supported | ||
it will display the default language, English. | ||
""" | ||
user = factories.UserFactory() | ||
document = factories.DocumentFactory() | ||
factories.UserDocumentAccessFactory(document=document, user=user, role="owner") | ||
|
||
invitation_values = { | ||
"email": "[email protected]", | ||
"role": "reader", | ||
} | ||
|
||
assert len(mail.outbox) == 0 | ||
|
||
client = APIClient() | ||
client.force_login(user) | ||
|
||
response = client.post( | ||
f"/api/v1.0/documents/{document.id!s}/invitations/", | ||
invitation_values, | ||
format="json", | ||
headers={"Content-Language": "not-supported"}, | ||
) | ||
|
||
assert response.status_code == 201 | ||
assert response.json()["email"] == "[email protected]" | ||
assert models.Invitation.objects.count() == 1 | ||
assert len(mail.outbox) == 1 | ||
|
||
email = mail.outbox[0] | ||
|
||
assert email.to == ["[email protected]"] | ||
|
||
email_content = " ".join(email.body.split()) | ||
assert ( | ||
f"{user.full_name} shared a document with you: {document.title}" | ||
in email_content | ||
) | ||
|
||
|
||
def test_api_document_invitations_create_email_full_name_empty(): | ||
""" | ||
If the full name of the user is empty, it will display the email address. | ||
""" | ||
user = factories.UserFactory(full_name="") | ||
user = factories.UserFactory(full_name="", language="en-us") | ||
document = factories.DocumentFactory() | ||
factories.UserDocumentAccessFactory(document=document, user=user, role="owner") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// See: https://github.com/numerique-gouv/impress/blob/ac58341984c99c10ebfac7f8bbe1e8756c48e4d4/src/backend/impress/settings.py#L156-L161 | ||
export type ContentLanguage = 'en-us' | 'fr-fr'; | ||
export type UserLanguage = 'en-us' | 'fr-fr'; |