🐛(mailbox) fix mailbox creation email language
Don't forget to translate mail content before sending.
This commit is contained in:
@@ -14,6 +14,10 @@ and this project adheres to
|
|||||||
- ✨(frontend) feature modal add new access role to domain
|
- ✨(frontend) feature modal add new access role to domain
|
||||||
- ✨(api) allow invitations for domain management #708
|
- ✨(api) allow invitations for domain management #708
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- 🐛(mailbox) fix mailbox creation email language
|
||||||
|
|
||||||
## [1.13.1] - 2025-03-04
|
## [1.13.1] - 2025-03-04
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -55,7 +55,9 @@ class MailboxSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
# send confirmation email
|
# send confirmation email
|
||||||
client.notify_mailbox_creation(
|
client.notify_mailbox_creation(
|
||||||
recipient=mailbox.secondary_email, mailbox_data=response.json()
|
recipient=mailbox.secondary_email,
|
||||||
|
mailbox_data=response.json(),
|
||||||
|
issuer=self.context["request"].user,
|
||||||
)
|
)
|
||||||
|
|
||||||
# actually save mailbox on our database
|
# actually save mailbox on our database
|
||||||
|
|||||||
@@ -790,10 +790,14 @@ def test_api_mailboxes__sends_new_mailbox_notification(mock_info):
|
|||||||
Creating a new mailbox should send confirmation email
|
Creating a new mailbox should send confirmation email
|
||||||
to secondary email.
|
to secondary email.
|
||||||
"""
|
"""
|
||||||
access = factories.MailDomainAccessFactory(role=enums.MailDomainRoleChoices.OWNER)
|
user = core_factories.UserFactory(language="fr-fr")
|
||||||
|
access = factories.MailDomainAccessFactory(
|
||||||
|
user=user,
|
||||||
|
role=enums.MailDomainRoleChoices.OWNER,
|
||||||
|
)
|
||||||
|
|
||||||
client = APIClient()
|
client = APIClient()
|
||||||
client.force_login(access.user)
|
client.force_login(user)
|
||||||
mailbox_data = serializers.MailboxSerializer(
|
mailbox_data = serializers.MailboxSerializer(
|
||||||
factories.MailboxFactory.build(domain=access.domain)
|
factories.MailboxFactory.build(domain=access.domain)
|
||||||
).data
|
).data
|
||||||
@@ -824,7 +828,10 @@ def test_api_mailboxes__sends_new_mailbox_notification(mock_info):
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert mock_send.call_count == 1
|
assert mock_send.call_count == 1
|
||||||
assert mock_send.mock_calls[0][1][0] == "Your new mailbox information"
|
assert (
|
||||||
|
"Informations sur votre nouvelle boîte mail"
|
||||||
|
in mock_send.mock_calls[0][1][1]
|
||||||
|
)
|
||||||
assert mock_send.mock_calls[0][1][3][0] == mailbox_data["secondary_email"]
|
assert mock_send.mock_calls[0][1][3][0] == mailbox_data["secondary_email"]
|
||||||
|
|
||||||
expected_messages = {
|
expected_messages = {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from django.contrib.sites.models import Site
|
|||||||
from django.core import exceptions, mail
|
from django.core import exceptions, mail
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.utils.translation import override
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
@@ -258,31 +259,29 @@ class DimailAPIClient:
|
|||||||
f"{error_content.get('detail') or error_content}"
|
f"{error_content.get('detail') or error_content}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def notify_mailbox_creation(self, recipient, mailbox_data):
|
def notify_mailbox_creation(self, recipient, mailbox_data, issuer=None):
|
||||||
"""
|
"""
|
||||||
Send email to confirm mailbox creation
|
Send email to confirm mailbox creation
|
||||||
and send new mailbox information.
|
and send new mailbox information.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
template_vars = {
|
|
||||||
"title": _("Your new mailbox information"),
|
|
||||||
"site": Site.objects.get_current(),
|
|
||||||
"webmail_url": settings.WEBMAIL_URL,
|
|
||||||
"mailbox_data": mailbox_data,
|
|
||||||
}
|
|
||||||
|
|
||||||
msg_html = render_to_string("mail/html/new_mailbox.html", template_vars)
|
|
||||||
msg_plain = render_to_string("mail/text/new_mailbox.txt", template_vars)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mail.send_mail(
|
with override(issuer.language if issuer else settings.LANGUAGE_CODE):
|
||||||
template_vars["title"],
|
template_vars = {
|
||||||
msg_plain,
|
"title": _("Your new mailbox information"),
|
||||||
settings.EMAIL_FROM,
|
"site": Site.objects.get_current(),
|
||||||
[recipient],
|
"webmail_url": settings.WEBMAIL_URL,
|
||||||
html_message=msg_html,
|
"mailbox_data": mailbox_data,
|
||||||
fail_silently=False,
|
}
|
||||||
)
|
msg_html = render_to_string("mail/html/new_mailbox.html", template_vars)
|
||||||
|
msg_plain = render_to_string("mail/text/new_mailbox.txt", template_vars)
|
||||||
|
mail.send_mail(
|
||||||
|
template_vars["title"],
|
||||||
|
msg_plain,
|
||||||
|
settings.EMAIL_FROM,
|
||||||
|
[recipient],
|
||||||
|
html_message=msg_html,
|
||||||
|
fail_silently=False,
|
||||||
|
)
|
||||||
logger.info(
|
logger.info(
|
||||||
"Information for mailbox %s sent to %s.",
|
"Information for mailbox %s sent to %s.",
|
||||||
mailbox_data["email"],
|
mailbox_data["email"],
|
||||||
|
|||||||
@@ -136,7 +136,11 @@ class Base(Configuration):
|
|||||||
# https://docs.djangoproject.com/en/3.1/topics/i18n/
|
# https://docs.djangoproject.com/en/3.1/topics/i18n/
|
||||||
|
|
||||||
# Languages
|
# Languages
|
||||||
LANGUAGE_CODE = values.Value("en-us")
|
LANGUAGE_CODE = values.Value(
|
||||||
|
default="en-us",
|
||||||
|
environ_name="LANGUAGE_CODE",
|
||||||
|
environ_prefix=None,
|
||||||
|
)
|
||||||
|
|
||||||
DRF_NESTED_MULTIPART_PARSER = {
|
DRF_NESTED_MULTIPART_PARSER = {
|
||||||
# output of parser is converted to querydict
|
# output of parser is converted to querydict
|
||||||
|
|||||||
Reference in New Issue
Block a user