-
Notifications
You must be signed in to change notification settings - Fork 0
/
no_public_policy.ex
68 lines (57 loc) · 1.54 KB
/
no_public_policy.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
defmodule Pleroma.Web.ActivityPub.MRF.NoPublicPolicy do
@moduledoc "MRF policy which drops as:Public from outgoing activities"
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
require Logger
defp local?(actor) do
String.starts_with?(actor, Pleroma.Web.Endpoint.url())
end
defp remove_public(recipients) do
Enum.filter(recipients, fn value ->
value not in ["Public", "as:Public", "https://www.w3.org/ns/activitystreams#Public"]
end)
end
defp maybe_update_nested_object_addressing(message, to, cc) do
if is_map(Map.get(message, "object")) do
object =
Map.get(message, "object")
|> Map.put("to", to)
|> Map.put("cc", cc)
Map.put(message, "object", object)
else
message
end
end
@impl true
def filter(
%{
"to" => to,
"cc" => cc,
"actor" => actor
} = message
) do
message = if local?(actor) do
to = to |> remove_public()
cc = cc |> remove_public()
message
|> Map.put("to", to)
|> Map.put("cc", cc)
|> maybe_update_nested_object_addressing(to, cc)
else
message
end
{:ok, message}
end
@impl true
def filter(message), do: {:ok, message}
@impl true
def describe, do: {:ok, %{}}
@impl true
def config_description do
%{
key: :mrf_disallow_public,
related_policy: "Pleroma.Web.ActivityPub.MRF.NoPublicPolicy",
label: "Disallow posting to Public",
description: "Drop as:Public addressing from outgoing activities"
}
end
end