2019-07-23 13:49:22 +02:00
|
|
|
defmodule Mobilizon.Email.Admin do
|
|
|
|
@moduledoc """
|
2019-09-07 23:58:53 +02:00
|
|
|
Handles emails sent to admins.
|
2019-07-23 13:49:22 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
use Bamboo.Phoenix, view: Mobilizon.EmailView
|
2019-09-07 23:58:53 +02:00
|
|
|
|
|
|
|
import Bamboo.{Email, Phoenix}
|
|
|
|
|
2019-07-23 13:49:22 +02:00
|
|
|
import MobilizonWeb.Gettext
|
2019-09-07 23:58:53 +02:00
|
|
|
|
|
|
|
alias Mobilizon.{Config, Email}
|
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
|
|
|
|
2019-09-07 23:58:53 +02:00
|
|
|
@spec report(User.t(), Report.t(), String.t()) :: Bamboo.Email.t()
|
|
|
|
def report(%User{email: email}, %Report{} = report, locale \\ "en") do
|
2019-07-23 13:49:22 +02:00
|
|
|
Gettext.put_locale(locale)
|
|
|
|
|
2019-09-07 23:58:53 +02:00
|
|
|
instance_url = Config.instance_url()
|
|
|
|
|
|
|
|
subject =
|
|
|
|
gettext(
|
|
|
|
"Mobilizon: New report on instance %{instance}",
|
|
|
|
instance: instance_url
|
|
|
|
)
|
|
|
|
|
|
|
|
Email.base_email()
|
2019-07-23 13:49:22 +02:00
|
|
|
|> to(email)
|
2019-09-07 23:58:53 +02:00
|
|
|
|> subject(subject)
|
|
|
|
|> put_header("Reply-To", Config.instance_email_reply_to())
|
2019-07-23 13:49:22 +02:00
|
|
|
|> assign(:report, report)
|
|
|
|
|> assign(:instance, instance_url)
|
|
|
|
|> render(:report)
|
|
|
|
end
|
|
|
|
end
|