emails: Translate from_name of account security emails.

This commit is contained in:
Vishnu KS
2020-02-14 18:28:58 +05:30
committed by Tim Abbott
parent 7990ef2d52
commit e1a7716578
6 changed files with 28 additions and 11 deletions

View File

@@ -284,7 +284,7 @@ class ZulipPasswordResetForm(PasswordResetForm):
context['active_account_in_realm'] = True
context['reset_url'] = generate_password_reset_url(user, token_generator)
send_email('zerver/emails/password_reset', to_user_ids=[user.id],
from_name="Zulip Account Security",
from_name=FromAddress.security_email_from_name(user_profile=user),
from_address=FromAddress.tokenized_no_reply_address(),
context=context)
else:
@@ -293,11 +293,11 @@ class ZulipPasswordResetForm(PasswordResetForm):
delivery_email__iexact=email, is_active=True)
if active_accounts_in_other_realms:
context['active_accounts_in_other_realms'] = active_accounts_in_other_realms
language = request.LANGUAGE_CODE
send_email('zerver/emails/password_reset', to_emails=[email],
from_name="Zulip Account Security",
from_name=FromAddress.security_email_from_name(language=language),
from_address=FromAddress.tokenized_no_reply_address(),
language=request.LANGUAGE_CODE,
context=context)
language=language, context=context)
class RateLimitedPasswordResetByEmail(RateLimitedObject):
def __init__(self, email: str) -> None:

View File

@@ -901,9 +901,11 @@ def do_start_email_change_process(user_profile: UserProfile, new_email: str) ->
'new_email': new_email,
'activate_url': activation_url
})
language = user_profile.default_language
send_email('zerver/emails/confirm_new_email', to_emails=[new_email],
from_name='Zulip Account Security', from_address=FromAddress.tokenized_no_reply_address(),
language=user_profile.default_language, context=context)
from_name=FromAddress.security_email_from_name(language=language),
from_address=FromAddress.tokenized_no_reply_address(),
language=language, context=context)
def compute_irc_user_fullname(email: str) -> str:
return email.split("@")[0] + " (IRC)"

View File

@@ -3,9 +3,11 @@ from django.core.mail import EmailMultiAlternatives
from django.template import loader
from django.utils.timezone import now as timezone_now
from django.utils.translation import override as override_language
from django.utils.translation import ugettext as _
from django.template.exceptions import TemplateDoesNotExist
from zerver.models import ScheduledEmail, get_user_profile_by_id, \
EMAIL_TYPES, Realm
EMAIL_TYPES, Realm, UserProfile
import datetime
from email.utils import parseaddr, formataddr
@@ -34,6 +36,16 @@ class FromAddress:
return parseaddr(settings.TOKENIZED_NOREPLY_EMAIL_ADDRESS)[1].format(token=generate_key())
return FromAddress.NOREPLY
@staticmethod
def security_email_from_name(language: Optional[str]=None,
user_profile: Optional[UserProfile]=None) -> str:
if language is None:
assert user_profile is not None
language = user_profile.default_language
with override_language(language):
return _("Zulip Account Security")
def build_email(template_prefix: str, to_user_ids: Optional[List[int]]=None,
to_emails: Optional[List[str]]=None, from_name: Optional[str]=None,
from_address: Optional[str]=None, reply_to_email: Optional[str]=None,

View File

@@ -49,4 +49,5 @@ class Command(ZulipBaseCommand):
}
send_email('zerver/emails/password_reset', to_user_ids=[user_profile.id],
from_address=FromAddress.tokenized_no_reply_address(),
from_name="Zulip Account Security", context=context)
from_name=FromAddress.security_email_from_name(user_profile=user_profile),
context=context)

View File

@@ -95,7 +95,7 @@ def email_on_new_login(sender: Any, user: UserProfile, request: Any, **kwargs: A
email_dict = {
'template_prefix': 'zerver/emails/notify_new_login',
'to_user_ids': [user.id],
'from_name': 'Zulip Account Security',
'from_name': FromAddress.security_email_from_name(user_profile=user),
'from_address': FromAddress.NOREPLY,
'context': context}
queue_json_publish("email_senders", email_dict)

View File

@@ -45,9 +45,11 @@ def confirm_email_change(request: HttpRequest, confirmation_key: str) -> HttpRes
do_change_user_delivery_email(user_profile, new_email)
context = {'realm_name': user_profile.realm.name, 'new_email': new_email}
language = user_profile.default_language
send_email('zerver/emails/notify_change_in_email', to_emails=[old_email],
from_name="Zulip Account Security", from_address=FromAddress.SUPPORT,
language=user_profile.default_language, context=context)
from_name=FromAddress.security_email_from_name(user_profile=user_profile),
from_address=FromAddress.SUPPORT, language=language,
context=context)
ctx = {
'new_email': new_email,