Make notifs view work for reports
[akkoma] / lib / pleroma / emails / admin_email.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Emails.AdminEmail do
6 @moduledoc "Admin emails"
7
8 import Swoosh.Email
9
10 alias Pleroma.Config
11 alias Pleroma.HTML
12 alias Pleroma.Web.Router.Helpers
13
14 defp instance_config, do: Config.get(:instance)
15 defp instance_name, do: instance_config()[:name]
16
17 defp instance_notify_email do
18 Keyword.get(instance_config(), :notify_email, instance_config()[:email])
19 end
20
21 defp user_url(user) do
22 Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, user.id)
23 end
24
25 def test_email(mail_to \\ nil) do
26 html_body = """
27 <h3>Instance Test Email</h3>
28 <p>A test email was requested. Hello. :)</p>
29 """
30
31 new()
32 |> to(mail_to || Config.get([:instance, :email]))
33 |> from({instance_name(), instance_notify_email()})
34 |> subject("Instance Test Email")
35 |> html_body(html_body)
36 end
37
38 def report(to, reporter, account, statuses, comment) do
39 comment_html =
40 if comment do
41 "<p>Comment: #{comment}"
42 else
43 ""
44 end
45
46 statuses_html =
47 if is_list(statuses) && length(statuses) > 0 do
48 statuses_list_html =
49 statuses
50 |> Enum.map(fn
51 %{id: id} ->
52 status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, id)
53 "<li><a href=\"#{status_url}\">#{status_url}</li>"
54
55 id when is_binary(id) ->
56 "<li><a href=\"#{id}\">#{id}</li>"
57 end)
58 |> Enum.join("\n")
59
60 """
61 <p> Statuses:
62 <ul>
63 #{statuses_list_html}
64 </ul>
65 </p>
66 """
67 else
68 ""
69 end
70
71 html_body = """
72 <p>Reported by: <a href="#{user_url(reporter)}">#{reporter.nickname}</a></p>
73 <p>Reported Account: <a href="#{user_url(account)}">#{account.nickname}</a></p>
74 #{comment_html}
75 #{statuses_html}
76 <p>
77 <a href="#{Pleroma.Web.base_url()}/pleroma/admin/#/reports/index">View Reports in AdminFE</a>
78 """
79
80 new()
81 |> to({to.name, to.email})
82 |> from({instance_name(), instance_notify_email()})
83 |> subject("#{instance_name()} Report")
84 |> html_body(html_body)
85 end
86
87 def new_unapproved_registration(to, account) do
88 html_body = """
89 <p>New account for review: <a href="#{user_url(account)}">@#{account.nickname}</a></p>
90 <blockquote>#{HTML.strip_tags(account.registration_reason)}</blockquote>
91 <a href="#{Pleroma.Web.base_url()}/pleroma/admin/#/users/#{account.id}/">Visit AdminFE</a>
92 """
93
94 new()
95 |> to({to.name, to.email})
96 |> from({instance_name(), instance_notify_email()})
97 |> subject("New account up for review on #{instance_name()} (@#{account.nickname})")
98 |> html_body(html_body)
99 end
100 end