Improve the way the instance name is injected into emails

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-09-30 09:34:39 +02:00
parent 6edeeef9a9
commit 4a7c6a861e
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
18 changed files with 21 additions and 29 deletions

View file

@ -8,8 +8,8 @@ defmodule Mobilizon.Web.Email.Actor do
import Mobilizon.Web.Gettext
alias Mobilizon.Actors.Actor
alias Mobilizon.{Config, Users}
alias Mobilizon.Events.{Event, Participant}
alias Mobilizon.Users
alias Mobilizon.Users.User
alias Mobilizon.Web.Email
@ -40,7 +40,6 @@ defmodule Mobilizon.Web.Email.Actor do
) do
with %User{email: email, locale: locale} <- Users.get_user!(user_id) do
Gettext.put_locale(locale)
instance = Config.instance_name()
subject = gettext("Your participation to %{event} has been cancelled!", event: event.title)
@ -50,7 +49,6 @@ defmodule Mobilizon.Web.Email.Actor do
|> assign(:event, event)
|> assign(:role, member_role)
|> assign(:subject, subject)
|> assign(:instance, instance)
|> render(:actor_suspension_participants)
|> Email.Mailer.send_email_later()

View file

@ -12,15 +12,13 @@ defmodule Mobilizon.Web.Email do
@spec base_email(keyword()) :: Bamboo.Email.t()
def base_email(args) do
instance = Config.instance_config()
args
|> new_email()
|> from({Config.instance_name(), Config.instance_email_from()})
|> put_header("Reply-To", Config.instance_email_reply_to())
|> maybe_put_date_header()
|> maybe_put_message_id()
|> assign(:instance, instance)
|> assign(:instance_name, Config.instance_name())
|> put_html_layout({EmailView, "email.html"})
|> put_text_layout({EmailView, "email.text"})
end

View file

@ -92,13 +92,12 @@ defmodule Mobilizon.Web.Email.Group do
}) do
with %User{email: email, locale: locale} <- Users.get_user!(user_id) do
Gettext.put_locale(locale)
instance = Config.instance_name()
subject =
gettext(
"The group %{group} has been suspended on %{instance}",
group: group.name,
instance: instance
instance: Config.instance_name()
)
Email.base_email(to: email, subject: subject)
@ -106,7 +105,6 @@ defmodule Mobilizon.Web.Email.Group do
|> assign(:group, group)
|> assign(:role, member_role)
|> assign(:subject, subject)
|> assign(:instance, instance)
|> render(:group_suspension)
|> Email.Mailer.send_email_later()

View file

@ -172,19 +172,17 @@ defmodule Mobilizon.Web.Email.User do
_locale \\ "en"
) do
Gettext.put_locale(user_locale)
instance_name = Config.instance_name()
subject =
gettext(
"Mobilizon on %{instance}: confirm your email address",
instance: instance_name
instance: Config.instance_name()
)
Email.base_email(to: unconfirmed_email, subject: subject)
|> assign(:locale, user_locale)
|> assign(:subject, subject)
|> assign(:token, confirmation_token)
|> assign(:instance_name, instance_name)
|> render(:email_changed_new)
end

View file

@ -10,7 +10,7 @@
<tr>
<td bgcolor="#ffffff" align="center" valign="top" style="padding: 40px 20px 20px 20px; border-radius: 4px 4px 0px 0px; color: #3A384C; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 48px; font-weight: 400; line-height: 48px;">
<h1 style="font-size: 48px; font-weight: 400; margin: 0;">
<%= gettext "Your participation to %{event} has been cancelled!", event: (@event.title), instance: @instance %>
<%= gettext "Your participation to %{event} has been cancelled!", event: (@event.title), instance: @instance_name %>
</h1>
</td>
</tr>

View file

@ -1,3 +1,3 @@
<%= gettext "Your participation to %{event} has been cancelled!", event: (@event.title), instance: @instance %>
<%= gettext "Your participation to %{event} has been cancelled!", event: (@event.title), instance: @instance_name %>
==
<%= gettext "Your instance's moderation team has decided to suspend %{actor_name} (%{actor_address}). All of their events have been removed and your participation cancelled.", group_name: @actor.name || @actor.preferred_username, actor_address: if @actor.domain, do: "@#{@actor.preferred_username}@#{@actor.domain}", else: "@#{@actor.preferred_username}" %>

View file

@ -56,7 +56,7 @@
<tr>
<td align="center" valign="top" style="padding: 40px 10px 40px 10px;">
<a href="<%= Mobilizon.Web.Endpoint.url() %>" target="_blank">
<img alt="<%= Mobilizon.Config.instance_name() %>" src="<%= "#{Mobilizon.Web.Endpoint.url()}/img/mobilizon_logo.png" %>" width="366" height="108" style="display: block; width: 366px; max-width: 366px; min-width: 366px; font-family: 'Roboto', Helvetica, Arial, sans-serif; color: #ffffff; font-size: 18px;" border="0">
<img alt="<%= @instance_name %>" src="<%= "#{Mobilizon.Web.Endpoint.url()}/img/mobilizon_logo.png" %>" width="366" height="108" style="display: block; width: 366px; max-width: 366px; min-width: 366px; font-family: 'Roboto', Helvetica, Arial, sans-serif; color: #ffffff; font-size: 18px;" border="0">
</a>
</td>
</tr>
@ -140,7 +140,7 @@
<tr>
<td bgcolor="#ECEBF2" align="center" style="padding: 30px 30px 30px 30px; color: #474467; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 14px; font-weight: 400; line-height: 18px;" >
<p style="margin: 0;">
<%= gettext("<b>%{instance}</b> is powered by Mobilizon.", instance: @instance[:name]) |> raw %><br />
<%= gettext("<b>%{instance}</b> is powered by Mobilizon.", instance: @instance_name) |> raw %><br />
<a href="https://joinmobilizon.org"><%= gettext "Learn more about Mobilizon here!" %></a>
</p>
</td>

View file

@ -8,4 +8,4 @@
<%= gettext "Need help? Is something not working as expected?" %>
<%= gettext "Ask the community on Framacolibri" %> https://framacolibri.org/c/mobilizon/39
<%= gettext "%{instance} is powered by Mobilizon.", instance: @instance[:name] %> <%= gettext "Learn more about Mobilizon here!" %> https://joinmobilizon.org
<%= gettext "%{instance} is powered by Mobilizon.", instance: @instance_name %> <%= gettext "Learn more about Mobilizon here!" %> https://joinmobilizon.org

View file

@ -35,7 +35,7 @@
<tr>
<td bgcolor="#ffffff" align="left" style="padding: 20px 30px 0px 30px; color: #474467; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;" >
<p style="margin: 0;">
<%= gettext("The email address for your account on <b>%{host}</b> is being changed to:", host: @instance[:name]) |> raw %>
<%= gettext("The email address for your account on <b>%{host}</b> is being changed to:", host: @instance_name) |> raw %>
</p>
</td>
</tr>
@ -59,7 +59,7 @@
<tr>
<td bgcolor="#ffffff" align="left" style="padding: 20px 30px 0px 30px; color: #474467; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;" >
<p>
<%= gettext("If you did not trigger this change yourself, it is likely that someone has gained access to your %{host} account. Please log in and change your password immediately. If you cannot login, contact the admin on %{host}.", host: @instance[:name]) %>
<%= gettext("If you did not trigger this change yourself, it is likely that someone has gained access to your %{host} account. Please log in and change your password immediately. If you cannot login, contact the admin on %{host}.", host: @instance_name) %>
</p>
</td>
</tr>

View file

@ -1,5 +1,5 @@
<%= gettext "New email confirmation" %>
==
<%= gettext "Hi there! Just a quick note to confirm that the email address linked to your account on %{host} has been changed from this one to:", host: @instance[:name] %>
<%= gettext "Hi there! Just a quick note to confirm that the email address linked to your account on %{host} has been changed from this one to:", host: @instance_name %>
<%= @new_email %>
<%= gettext "If you did not trigger this change yourself, it is likely that someone has gained access to your %{host} account. Please log in and change your password immediately. If you cannot login, contact the admin on %{host}.", host: @instance[:name] %>
<%= gettext "If you did not trigger this change yourself, it is likely that someone has gained access to your %{host} account. Please log in and change your password immediately. If you cannot login, contact the admin on %{host}.", host: @instance_name %>

View file

@ -10,7 +10,7 @@
<tr>
<td bgcolor="#ffffff" align="center" valign="top" style="padding: 40px 20px 20px 20px; border-radius: 4px 4px 0px 0px; color: #3A384C; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 48px; font-weight: 400; line-height: 48px;">
<h1 style="font-size: 48px; font-weight: 400; margin: 0;">
<%= gettext "The group %{group} has been suspended on %{instance}!", group: (@group.name || @group.preferred_username), instance: @instance %>
<%= gettext "The group %{group} has been suspended on %{instance}!", group: (@group.name || @group.preferred_username), instance: @instance_name %>
</h1>
</td>
</tr>

View file

@ -1,4 +1,4 @@
<%= gettext "The group %{group} has been suspended on %{instance}!", group: (@group.name || @group.preferred_username), instance: @instance %>
<%= gettext "The group %{group} has been suspended on %{instance}!", group: (@group.name || @group.preferred_username), instance: @instance_name %>
==
<%= gettext "Your instance's moderation team has decided to suspend %{group_name} (%{group_address}). You are no longer a member of this group.", group_name: @group.name, group_address: if @group.domain, do: "@#{@group.preferred_username}@#{@group.domain}", else: "@#{@group.preferred_username}" %>
<%= if is_nil(@group.domain) do %>

View file

@ -35,7 +35,7 @@
<tr>
<td bgcolor="#ffffff" align="left" style="padding: 20px 30px 0px 30px; color: #474467; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;" >
<p style="margin: 0;">
<%= gettext("You requested a new password for your account on <b>%{instance}</b>.", instance: @instance[:name]) |> raw %>
<%= gettext("You requested a new password for your account on <b>%{instance}</b>.", instance: @instance_name) |> raw %>
</p>
<p style="margin: 0">
<%= gettext "Resetting your password is easy. Just press the button below and follow the instructions. We'll have you up and running in no time." %>

View file

@ -2,7 +2,7 @@
==
<%= gettext "You requested a new password for your account on %{instance}.", instance: @instance[:name] %>
<%= gettext "You requested a new password for your account on %{instance}.", instance: @instance_name %>
<%= gettext "Resetting your password is easy. Just click the link below and follow the instructions. We'll have you up and running in no time." %>

View file

@ -35,7 +35,7 @@
<tr>
<td bgcolor="#ffffff" align="left" style="padding: 20px 30px 0px 30px; color: #474467; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;" >
<p style="margin: 0;">
<%= gettext("You created an account on <b>%{host}</b> with this email address. You are one click away from activating it.", host: @instance[:name]) |> raw %>
<%= gettext("You created an account on <b>%{host}</b> with this email address. You are one click away from activating it.", host: @instance_name) |> raw %>
</p>
</td>
</tr>

View file

@ -2,6 +2,6 @@
==
<%= gettext "You created an account on %{host} with this email address. You are one click away from activating it. If this wasn't you, please ignore this email.", host: @instance[:name] %>
<%= gettext "You created an account on %{host} with this email address. You are one click away from activating it. If this wasn't you, please ignore this email.", host: @instance_name %>
<%= Mobilizon.Web.Endpoint.url() <> "/validate/#{@token}" %>

View file

@ -10,7 +10,7 @@
<tr>
<td bgcolor="#ffffff" align="center" valign="top" style="padding: 40px 20px 20px 20px; border-radius: 4px 4px 0px 0px; color: #3A384C; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 48px; font-weight: 400; line-height: 48px;">
<h1 style="font-size: 48px; font-weight: 400; margin: 0;">
<%= gettext("New report on <b>%{instance}</b>", instance: @instance[:name]) |> raw %>
<%= gettext("New report on <b>%{instance}</b>", instance: @instance_name) |> raw %>
</h1>
</td>
</tr>

View file

@ -1,4 +1,4 @@
<%= gettext "New report from %{reporter} on %{instance}", reporter: Mobilizon.Actors.Actor.display_name_and_username(@report.reporter), instance: @instance[:name] %>
<%= gettext "New report from %{reporter} on %{instance}", reporter: Mobilizon.Actors.Actor.display_name_and_username(@report.reporter), instance: @instance_name %>
--
<%= if @report.reported do %>
<%= if @report.reported.type == :Group do %>