2020-01-26 21:36:50 +01:00
|
|
|
defmodule Mobilizon.Web.Email.Admin do
|
2019-07-23 13:49:22 +02:00
|
|
|
@moduledoc """
|
2019-09-07 23:58:53 +02:00
|
|
|
Handles emails sent to admins.
|
2019-07-23 13:49:22 +02:00
|
|
|
"""
|
|
|
|
|
2022-04-05 12:16:22 +02:00
|
|
|
use Phoenix.Swoosh, view: Mobilizon.Web.EmailView
|
2019-09-07 23:58:53 +02:00
|
|
|
|
2020-01-26 21:36:50 +01:00
|
|
|
import Mobilizon.Web.Gettext
|
2019-09-07 23:58:53 +02:00
|
|
|
|
2019-09-17 02:45:32 +02:00
|
|
|
alias Mobilizon.Config
|
2019-07-23 13:49:22 +02:00
|
|
|
alias Mobilizon.Reports.Report
|
2019-09-07 23:58:53 +02:00
|
|
|
alias Mobilizon.Users.User
|
2019-07-23 13:49:22 +02:00
|
|
|
|
2021-07-27 19:47:54 +02:00
|
|
|
alias Mobilizon.Web.Email
|
2019-09-17 02:45:32 +02:00
|
|
|
|
2022-04-05 12:16:22 +02:00
|
|
|
@spec report(User.t(), Report.t()) :: Swoosh.Email.t()
|
2021-10-05 15:29:06 +02:00
|
|
|
def report(%User{email: email} = user, %Report{} = report) do
|
|
|
|
locale = Map.get(user, :locale, "en")
|
2020-01-28 19:18:33 +01:00
|
|
|
Gettext.put_locale(locale)
|
2019-07-23 13:49:22 +02:00
|
|
|
|
2019-09-07 23:58:53 +02:00
|
|
|
subject =
|
|
|
|
gettext(
|
2019-09-23 19:33:58 +02:00
|
|
|
"New report on Mobilizon instance %{instance}",
|
|
|
|
instance: Config.instance_name()
|
2019-09-07 23:58:53 +02:00
|
|
|
)
|
|
|
|
|
2022-04-05 12:16:22 +02:00
|
|
|
[to: email, subject: subject]
|
|
|
|
|> Email.base_email()
|
|
|
|
|> render_body(:report, %{locale: locale, subject: subject, report: report})
|
2019-07-23 13:49:22 +02:00
|
|
|
end
|
2022-01-14 18:10:50 +01:00
|
|
|
|
2022-04-05 12:16:22 +02:00
|
|
|
@spec user_email_change_old(User.t(), String.t()) :: Swoosh.Email.t()
|
2022-01-14 18:10:50 +01:00
|
|
|
def user_email_change_old(
|
|
|
|
%User{
|
|
|
|
locale: user_locale,
|
|
|
|
email: new_email
|
|
|
|
},
|
|
|
|
old_email
|
|
|
|
) do
|
|
|
|
Gettext.put_locale(user_locale)
|
|
|
|
|
|
|
|
subject =
|
|
|
|
gettext(
|
|
|
|
"An administrator manually changed the email attached to your account on %{instance}",
|
|
|
|
instance: Config.instance_name()
|
|
|
|
)
|
|
|
|
|
2022-04-05 12:16:22 +02:00
|
|
|
[to: old_email, subject: subject]
|
|
|
|
|> Email.base_email()
|
|
|
|
|> render_body(:admin_user_email_changed_old, %{
|
|
|
|
locale: user_locale,
|
|
|
|
subject: subject,
|
|
|
|
new_email: new_email,
|
|
|
|
old_email: old_email,
|
|
|
|
offer_unsupscription: false
|
|
|
|
})
|
2022-01-14 18:10:50 +01:00
|
|
|
end
|
|
|
|
|
2022-04-05 12:16:22 +02:00
|
|
|
@spec user_email_change_new(User.t(), String.t()) :: Swoosh.Email.t()
|
2022-01-14 18:10:50 +01:00
|
|
|
def user_email_change_new(
|
|
|
|
%User{
|
|
|
|
locale: user_locale,
|
|
|
|
email: new_email
|
|
|
|
},
|
|
|
|
old_email
|
|
|
|
) do
|
|
|
|
Gettext.put_locale(user_locale)
|
|
|
|
|
|
|
|
subject =
|
|
|
|
gettext(
|
|
|
|
"An administrator manually changed the email attached to your account on %{instance}",
|
|
|
|
instance: Config.instance_name()
|
|
|
|
)
|
|
|
|
|
2022-04-05 12:16:22 +02:00
|
|
|
[to: old_email, subject: subject]
|
|
|
|
|> Email.base_email()
|
|
|
|
|> render_body(:admin_user_email_changed_new, %{
|
|
|
|
locale: user_locale,
|
|
|
|
subject: subject,
|
|
|
|
new_email: new_email,
|
|
|
|
old_email: old_email,
|
|
|
|
offer_unsupscription: false
|
|
|
|
})
|
2022-01-14 18:10:50 +01:00
|
|
|
end
|
|
|
|
|
2022-04-05 12:16:22 +02:00
|
|
|
@spec user_role_change(User.t(), atom()) :: Swoosh.Email.t()
|
2022-01-14 18:10:50 +01:00
|
|
|
def user_role_change(
|
|
|
|
%User{
|
|
|
|
locale: user_locale,
|
|
|
|
email: email,
|
|
|
|
role: new_role
|
|
|
|
},
|
|
|
|
old_role
|
|
|
|
) do
|
|
|
|
Gettext.put_locale(user_locale)
|
|
|
|
|
|
|
|
subject =
|
|
|
|
gettext(
|
|
|
|
"An administrator updated your role on %{instance}",
|
|
|
|
instance: Config.instance_name()
|
|
|
|
)
|
|
|
|
|
2022-04-05 12:16:22 +02:00
|
|
|
[to: email, subject: subject]
|
|
|
|
|> Email.base_email()
|
|
|
|
|> render_body(:admin_user_role_changed, %{
|
|
|
|
locale: user_locale,
|
|
|
|
subject: subject,
|
|
|
|
old_role: old_role,
|
|
|
|
new_role: new_role,
|
|
|
|
offer_unsupscription: false
|
|
|
|
})
|
2022-01-14 18:10:50 +01:00
|
|
|
end
|
|
|
|
|
2022-04-05 12:16:22 +02:00
|
|
|
@spec user_confirmation(User.t()) :: Swoosh.Email.t()
|
2022-01-14 18:10:50 +01:00
|
|
|
def user_confirmation(%User{
|
|
|
|
locale: user_locale,
|
|
|
|
email: email
|
|
|
|
}) do
|
|
|
|
Gettext.put_locale(user_locale)
|
|
|
|
|
|
|
|
subject =
|
|
|
|
gettext(
|
|
|
|
"An administrator confirmed your account on %{instance}",
|
|
|
|
instance: Config.instance_name()
|
|
|
|
)
|
|
|
|
|
2022-04-05 12:16:22 +02:00
|
|
|
[to: email, subject: subject]
|
|
|
|
|> Email.base_email()
|
|
|
|
|> render_body(:admin_user_confirmation, %{
|
|
|
|
locale: user_locale,
|
|
|
|
subject: subject,
|
|
|
|
offer_unsupscription: false
|
|
|
|
})
|
2019-07-23 13:49:22 +02:00
|
|
|
end
|
2022-01-14 18:10:50 +01:00
|
|
|
|
|
|
|
@spec user_email_change_old(User.t(), String.t()) :: Bamboo.Email.t()
|
|
|
|
def user_email_change_old(
|
|
|
|
%User{
|
|
|
|
locale: user_locale,
|
|
|
|
email: new_email
|
|
|
|
},
|
|
|
|
old_email
|
|
|
|
) do
|
|
|
|
Gettext.put_locale(user_locale)
|
|
|
|
|
|
|
|
subject =
|
|
|
|
gettext(
|
|
|
|
"An administrator manually changed the email attached to your account on %{instance}",
|
|
|
|
instance: Config.instance_name()
|
|
|
|
)
|
|
|
|
|
|
|
|
Email.base_email(to: old_email, subject: subject)
|
|
|
|
|> assign(:locale, user_locale)
|
|
|
|
|> assign(:subject, subject)
|
|
|
|
|> assign(:new_email, new_email)
|
|
|
|
|> assign(:old_email, old_email)
|
|
|
|
|> assign(:offer_unsupscription, false)
|
|
|
|
|> render(:admin_user_email_changed_old)
|
|
|
|
end
|
|
|
|
|
|
|
|
@spec user_email_change_new(User.t(), String.t()) :: Bamboo.Email.t()
|
|
|
|
def user_email_change_new(
|
|
|
|
%User{
|
|
|
|
locale: user_locale,
|
|
|
|
email: new_email
|
|
|
|
},
|
|
|
|
old_email
|
|
|
|
) do
|
|
|
|
Gettext.put_locale(user_locale)
|
|
|
|
|
|
|
|
subject =
|
|
|
|
gettext(
|
|
|
|
"An administrator manually changed the email attached to your account on %{instance}",
|
|
|
|
instance: Config.instance_name()
|
|
|
|
)
|
|
|
|
|
|
|
|
Email.base_email(to: new_email, subject: subject)
|
|
|
|
|> assign(:locale, user_locale)
|
|
|
|
|> assign(:subject, subject)
|
|
|
|
|> assign(:old_email, old_email)
|
|
|
|
|> assign(:new_email, new_email)
|
|
|
|
|> assign(:offer_unsupscription, false)
|
|
|
|
|> render(:admin_user_email_changed_new)
|
|
|
|
end
|
|
|
|
|
|
|
|
@spec user_role_change(User.t(), atom()) :: Bamboo.Email.t()
|
|
|
|
def user_role_change(
|
|
|
|
%User{
|
|
|
|
locale: user_locale,
|
|
|
|
email: email,
|
|
|
|
role: new_role
|
|
|
|
},
|
|
|
|
old_role
|
|
|
|
) do
|
|
|
|
Gettext.put_locale(user_locale)
|
|
|
|
|
|
|
|
subject =
|
|
|
|
gettext(
|
|
|
|
"An administrator updated your role on %{instance}",
|
|
|
|
instance: Config.instance_name()
|
|
|
|
)
|
|
|
|
|
|
|
|
Email.base_email(to: email, subject: subject)
|
|
|
|
|> assign(:locale, user_locale)
|
|
|
|
|> assign(:subject, subject)
|
|
|
|
|> assign(:old_role, old_role)
|
|
|
|
|> assign(:new_role, new_role)
|
|
|
|
|> assign(:offer_unsupscription, false)
|
|
|
|
|> render(:admin_user_role_changed)
|
|
|
|
end
|
|
|
|
|
|
|
|
@spec user_confirmation(User.t()) :: Bamboo.Email.t()
|
|
|
|
def user_confirmation(%User{
|
|
|
|
locale: user_locale,
|
|
|
|
email: email
|
|
|
|
}) do
|
|
|
|
Gettext.put_locale(user_locale)
|
|
|
|
|
|
|
|
subject =
|
|
|
|
gettext(
|
|
|
|
"An administrator confirmed your account on %{instance}",
|
|
|
|
instance: Config.instance_name()
|
|
|
|
)
|
|
|
|
|
|
|
|
Email.base_email(to: email, subject: subject)
|
|
|
|
|> assign(:locale, user_locale)
|
|
|
|
|> assign(:subject, subject)
|
|
|
|
|> assign(:offer_unsupscription, false)
|
|
|
|
|> render(:admin_user_confirmation)
|
|
|
|
end
|
2019-07-23 13:49:22 +02:00
|
|
|
end
|