Skip to content

Commit cb4e148

Browse files
committed
♻️(email) adapt email when no title
Default title is not set when we create a document anymore. We need to adapt the email to handle this case.
1 parent 2d24825 commit cb4e148

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/backend/core/models.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ def send_email(self, subject, emails, context=None, language=None):
697697
"document": self,
698698
"domain": domain,
699699
"link": f"{domain}/docs/{self.id}/",
700+
"document_title": self.title or str(_("Untitled Document")),
700701
"logo_img": settings.EMAIL_LOGO_IMG,
701702
}
702703
)
@@ -738,8 +739,12 @@ def send_invitation_email(self, email, role, sender, language=None):
738739
'{name} invited you with the role "{role}" on the following document:'
739740
).format(name=sender_name_email, role=role.lower()),
740741
}
741-
subject = _("{name} shared a document with you: {title}").format(
742-
name=sender_name, title=self.title
742+
subject = (
743+
context["title"]
744+
if not self.title
745+
else _("{name} shared a document with you: {title}").format(
746+
name=sender_name, title=self.title
747+
)
743748
)
744749

745750
self.send_email(subject, [email], context, language)

src/backend/core/tests/test_models_documents.py

+31
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,37 @@ def test_models_documents__email_invitation__success():
636636
assert f"docs/{document.id}/" in email_content
637637

638638

639+
def test_models_documents__email_invitation__success_empty_title():
640+
"""
641+
The email invitation is sent successfully.
642+
"""
643+
document = factories.DocumentFactory(title=None)
644+
645+
# pylint: disable-next=no-member
646+
assert len(mail.outbox) == 0
647+
648+
sender = factories.UserFactory(full_name="Test Sender", email="[email protected]")
649+
document.send_invitation_email(
650+
"[email protected]", models.RoleChoices.EDITOR, sender, "en"
651+
)
652+
653+
# pylint: disable-next=no-member
654+
assert len(mail.outbox) == 1
655+
656+
# pylint: disable-next=no-member
657+
email = mail.outbox[0]
658+
659+
assert email.to == ["[email protected]"]
660+
email_content = " ".join(email.body.split())
661+
662+
assert "Test sender shared a document with you!" in email.subject
663+
assert (
664+
"Test Sender ([email protected]) invited you with the role "editor" "
665+
"on the following document: Untitled Document" in email_content
666+
)
667+
assert f"docs/{document.id}/" in email_content
668+
669+
639670
def test_models_documents__email_invitation__success_fr():
640671
"""
641672
The email invitation is sent successfully in french.

src/mail/mjml/invitation.mjml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<!-- Main Message -->
2323
<mj-text>
2424
{{message|capfirst}}
25-
<a href="{{link}}">{{document.title}}</a>
25+
<a href="{{link}}">{{document_title}}</a>
2626
</mj-text>
2727
<mj-button
2828
href="{{link}}"

0 commit comments

Comments
 (0)