2020-01-26 20:36:50 +00:00
|
|
|
defmodule Mobilizon.Web.Email.Admin do
|
2019-07-23 11:49:22 +00:00
|
|
|
@moduledoc """
|
2019-09-07 21:58:53 +00:00
|
|
|
Handles emails sent to admins.
|
2019-07-23 11:49:22 +00:00
|
|
|
"""
|
|
|
|
|
2020-01-26 20:36:50 +00:00
|
|
|
use Bamboo.Phoenix, view: Mobilizon.Web.EmailView
|
2019-09-07 21:58:53 +00:00
|
|
|
|
2019-09-23 17:33:58 +00:00
|
|
|
import Bamboo.Phoenix
|
2019-09-07 21:58:53 +00:00
|
|
|
|
2020-01-26 20:36:50 +00:00
|
|
|
import Mobilizon.Web.Gettext
|
2019-09-07 21:58:53 +00:00
|
|
|
|
2019-09-17 00:45:32 +00:00
|
|
|
alias Mobilizon.Config
|
2019-07-23 11:49:22 +00:00
|
|
|
alias Mobilizon.Reports.Report
|
2019-09-07 21:58:53 +00:00
|
|
|
alias Mobilizon.Users.User
|
2019-07-23 11:49:22 +00:00
|
|
|
|
2020-01-28 18:18:33 +00:00
|
|
|
alias Mobilizon.Web.{Email, Gettext}
|
2019-09-17 00:45:32 +00:00
|
|
|
|
2019-09-07 21:58:53 +00:00
|
|
|
@spec report(User.t(), Report.t(), String.t()) :: Bamboo.Email.t()
|
2020-09-30 13:25:30 +00:00
|
|
|
def report(%User{email: email} = user, %Report{} = report, default_locale \\ "en") do
|
|
|
|
locale = Map.get(user, :locale, default_locale)
|
2020-01-28 18:18:33 +00:00
|
|
|
Gettext.put_locale(locale)
|
2019-07-23 11:49:22 +00:00
|
|
|
|
2019-09-07 21:58:53 +00:00
|
|
|
subject =
|
|
|
|
gettext(
|
2019-09-23 17:33:58 +00:00
|
|
|
"New report on Mobilizon instance %{instance}",
|
|
|
|
instance: Config.instance_name()
|
2019-09-07 21:58:53 +00:00
|
|
|
)
|
|
|
|
|
2019-09-23 17:33:58 +00:00
|
|
|
Email.base_email(to: email, subject: subject)
|
|
|
|
|> assign(:locale, locale)
|
|
|
|
|> assign(:subject, subject)
|
2019-07-23 11:49:22 +00:00
|
|
|
|> assign(:report, report)
|
2019-09-24 10:09:43 +00:00
|
|
|
|> render(:report)
|
2019-07-23 11:49:22 +00:00
|
|
|
end
|
|
|
|
end
|