-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
♻️ Add username in email #314
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -576,8 +576,15 @@ def perform_create(self, serializer): | |||||||||
"""Add a new access to the document and send an email to the new added user.""" | ||||||||||
access = serializer.save() | ||||||||||
language = self.request.headers.get("Content-Language", "en-us") | ||||||||||
|
||||||||||
username_sender = self.request.user.full_name | ||||||||||
email_sender = self.request.user.email | ||||||||||
if(not username_sender): | ||||||||||
username_sender = self.request.user.email | ||||||||||
email_sender = "" | ||||||||||
|
||||||||||
access.document.email_invitation( | ||||||||||
language, access.user.email, access.role, self.request.user.email | ||||||||||
language, access.user.email, access.role, username_sender, email_sender | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Semantically, shouldn't it be:
Suggested change
The term "username" is usually used with another meaning. |
||||||||||
) | ||||||||||
|
||||||||||
|
||||||||||
|
@@ -778,6 +785,13 @@ def perform_create(self, serializer): | |||||||||
invitation = serializer.save() | ||||||||||
|
||||||||||
language = self.request.headers.get("Content-Language", "en-us") | ||||||||||
|
||||||||||
username_sender = self.request.user.full_name | ||||||||||
email_sender = self.request.user.email | ||||||||||
Comment on lines
+789
to
+790
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
if(not username_sender): | ||||||||||
username_sender = self.request.user.email | ||||||||||
email_sender = "" | ||||||||||
|
||||||||||
invitation.document.email_invitation( | ||||||||||
language, invitation.email, invitation.role, self.request.user.email | ||||||||||
language, invitation.email, invitation.role, username_sender, email_sender | ||||||||||
) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -520,7 +520,7 @@ def get_abilities(self, user): | |||||
"versions_retrieve": can_get_versions, | ||||||
} | ||||||
|
||||||
def email_invitation(self, language, email, role, username_sender): | ||||||
def email_invitation(self, language, email, role, username_sender, email_sender): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
"""Send email invitation.""" | ||||||
|
||||||
domain = Site.objects.get_current().domain | ||||||
|
@@ -537,6 +537,7 @@ def email_invitation(self, language, email, role, username_sender): | |||||
"document": self, | ||||||
"link": f"{domain}/docs/{self.id}/", | ||||||
"username": username_sender, | ||||||
"email": email_sender, | ||||||
"role": RoleChoices(role).label.lower(), | ||||||
} | ||||||
msg_html = render_to_string("mail/html/invitation.html", template_vars) | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,7 +119,7 @@ def test_api_document_invitations__create__privileged_members( | |
assert email.to == ["[email protected]"] | ||
email_content = " ".join(email.body.split()) | ||
assert ( | ||
f"{user.email} shared a document with you: {document.title}" | ||
f"{user.full_name} shared a document with you: {document.title}" | ||
in email_content | ||
) | ||
else: | ||
|
@@ -201,8 +201,49 @@ def test_api_document_invitations__create__email_from_content_language_not_suppo | |
|
||
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="") | ||
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}/invitations/", | ||
invitation_values, | ||
format="json", | ||
headers={"Content-Language": "not-supported"}, | ||
) | ||
|
||
assert response.status_code == status.HTTP_201_CREATED | ||
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.email} shared a document with you: {document.title}" in email_content | ||
assert ( | ||
f"{user.email} invited you as an owner on the following document : {document.title}" | ||
in email_content | ||
) | ||
|
||
|
||
def test_api_document_invitations__create__issuer_and_document_override(): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -364,7 +364,7 @@ def test_models_documents__email_invitation__success(): | |
assert len(mail.outbox) == 0 | ||
|
||
document.email_invitation( | ||
"en", "[email protected]", models.RoleChoices.EDITOR, "[email protected]" | ||
"en", "[email protected]", models.RoleChoices.EDITOR, "Test Sender", "[email protected]" | ||
) | ||
|
||
# pylint: disable-next=no-member | ||
|
@@ -377,7 +377,7 @@ def test_models_documents__email_invitation__success(): | |
email_content = " ".join(email.body.split()) | ||
|
||
assert ( | ||
f"[email protected] invited you as an editor on the following document : {document.title}" | ||
f"Test Sender ([email protected]) invited you as an editor on the following document : {document.title}" | ||
in email_content | ||
) | ||
assert f"docs/{document.id}/" in email_content | ||
|
@@ -393,7 +393,7 @@ def test_models_documents__email_invitation__success_fr(): | |
assert len(mail.outbox) == 0 | ||
|
||
document.email_invitation( | ||
"fr-fr", "[email protected]", models.RoleChoices.OWNER, "[email protected]" | ||
"fr-fr", "[email protected]", models.RoleChoices.OWNER, "Test Sender2", "[email protected]" | ||
) | ||
|
||
# pylint: disable-next=no-member | ||
|
@@ -406,7 +406,7 @@ def test_models_documents__email_invitation__success_fr(): | |
email_content = " ".join(email.body.split()) | ||
|
||
assert ( | ||
f"[email protected] vous a invité en tant que propriétaire " | ||
f"Test Sender2 ([email protected]) vous a invité en tant que propriétaire " | ||
f"sur le document suivant : {document.title}" in email_content | ||
) | ||
assert f"docs/{document.id}/" in email_content | ||
|
@@ -425,7 +425,7 @@ def test_models_documents__email_invitation__failed(mock_logger, _mock_send_mail | |
assert len(mail.outbox) == 0 | ||
|
||
document.email_invitation( | ||
"en", "[email protected]", models.RoleChoices.ADMIN, "[email protected]" | ||
"en", "[email protected]", models.RoleChoices.ADMIN, "sender3", "sender3@example.com" | ||
) | ||
|
||
# No email has been sent | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.