Merge branch '1234-mastodon-2-4-3-oauth-scopes' into 'develop'
[akkoma] / lib / pleroma / emails / admin_email.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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.Web.Router.Helpers
11
12 defp instance_config, do: Pleroma.Config.get(:instance)
13 defp instance_name, do: instance_config()[:name]
14
15 defp instance_notify_email do
16 Keyword.get(instance_config(), :notify_email, instance_config()[:email])
17 end
18
19 defp user_url(user) do
20 Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, user.id)
21 end
22
23 def report(to, reporter, account, statuses, comment) do
24 comment_html =
25 if comment do
26 "<p>Comment: #{comment}"
27 else
28 ""
29 end
30
31 statuses_html =
32 if is_list(statuses) && length(statuses) > 0 do
33 statuses_list_html =
34 statuses
35 |> Enum.map(fn
36 %{id: id} ->
37 status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, id)
38 "<li><a href=\"#{status_url}\">#{status_url}</li>"
39
40 id when is_binary(id) ->
41 "<li><a href=\"#{id}\">#{id}</li>"
42 end)
43 |> Enum.join("\n")
44
45 """
46 <p> Statuses:
47 <ul>
48 #{statuses_list_html}
49 </ul>
50 </p>
51 """
52 else
53 ""
54 end
55
56 html_body = """
57 <p>Reported by: <a href="#{user_url(reporter)}">#{reporter.nickname}</a></p>
58 <p>Reported Account: <a href="#{user_url(account)}">#{account.nickname}</a></p>
59 #{comment_html}
60 #{statuses_html}
61 """
62
63 new()
64 |> to({to.name, to.email})
65 |> from({instance_name(), instance_notify_email()})
66 |> subject("#{instance_name()} Report")
67 |> html_body(html_body)
68 end
69 end