2018-04-14 11:31:12 +00:00
|
|
|
defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
|
|
|
|
alias Pleroma.User
|
2018-05-10 16:34:09 +00:00
|
|
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
2018-04-14 11:31:12 +00:00
|
|
|
|
|
|
|
@mrf_policy Application.get_env(:pleroma, :mrf_simple)
|
|
|
|
|
2018-06-19 21:23:37 +00:00
|
|
|
@accept Keyword.get(@mrf_policy, :accept)
|
|
|
|
defp check_accept(actor_info, object) do
|
2018-06-21 17:28:39 +00:00
|
|
|
if length(@accept) > 0 and not (actor_info.host in @accept) do
|
2018-06-19 21:23:37 +00:00
|
|
|
{:reject, nil}
|
|
|
|
else
|
|
|
|
{:ok, object}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-14 11:31:12 +00:00
|
|
|
@reject Keyword.get(@mrf_policy, :reject)
|
|
|
|
defp check_reject(actor_info, object) do
|
|
|
|
if actor_info.host in @reject do
|
|
|
|
{:reject, nil}
|
|
|
|
else
|
|
|
|
{:ok, object}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@media_removal Keyword.get(@mrf_policy, :media_removal)
|
|
|
|
defp check_media_removal(actor_info, object) do
|
|
|
|
if actor_info.host in @media_removal do
|
2018-04-25 21:25:56 +00:00
|
|
|
child_object = Map.delete(object["object"], "attachment")
|
|
|
|
object = Map.put(object, "object", child_object)
|
2018-05-06 06:58:59 +00:00
|
|
|
{:ok, object}
|
|
|
|
else
|
|
|
|
{:ok, object}
|
2018-04-14 11:31:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@media_nsfw Keyword.get(@mrf_policy, :media_nsfw)
|
|
|
|
defp check_media_nsfw(actor_info, object) do
|
2018-04-19 12:29:35 +00:00
|
|
|
child_object = object["object"]
|
2018-04-24 19:25:31 +00:00
|
|
|
|
|
|
|
if actor_info.host in @media_nsfw and child_object["attachment"] != nil and
|
|
|
|
length(child_object["attachment"]) > 0 do
|
2018-04-19 12:29:35 +00:00
|
|
|
tags = (child_object["tag"] || []) ++ ["nsfw"]
|
|
|
|
child_object = Map.put(child_object, "tags", tags)
|
|
|
|
child_object = Map.put(child_object, "sensitive", true)
|
|
|
|
object = Map.put(object, "object", child_object)
|
2018-05-06 06:58:59 +00:00
|
|
|
{:ok, object}
|
|
|
|
else
|
|
|
|
{:ok, object}
|
2018-04-14 11:31:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@ftl_removal Keyword.get(@mrf_policy, :federated_timeline_removal)
|
|
|
|
defp check_ftl_removal(actor_info, object) do
|
|
|
|
if actor_info.host in @ftl_removal do
|
|
|
|
user = User.get_by_ap_id(object["actor"])
|
|
|
|
|
|
|
|
# flip to/cc relationship to make the post unlisted
|
2018-05-06 06:58:59 +00:00
|
|
|
object =
|
|
|
|
if "https://www.w3.org/ns/activitystreams#Public" in object["to"] and
|
|
|
|
user.follower_address in object["cc"] do
|
|
|
|
to =
|
|
|
|
List.delete(object["to"], "https://www.w3.org/ns/activitystreams#Public") ++
|
|
|
|
[user.follower_address]
|
2018-04-24 19:25:31 +00:00
|
|
|
|
2018-05-06 06:58:59 +00:00
|
|
|
cc =
|
|
|
|
List.delete(object["cc"], user.follower_address) ++
|
|
|
|
["https://www.w3.org/ns/activitystreams#Public"]
|
2018-04-14 11:31:12 +00:00
|
|
|
|
2018-05-06 06:58:59 +00:00
|
|
|
object
|
|
|
|
|> Map.put("to", to)
|
|
|
|
|> Map.put("cc", cc)
|
|
|
|
else
|
|
|
|
object
|
|
|
|
end
|
2018-04-14 11:31:12 +00:00
|
|
|
|
2018-05-06 06:58:59 +00:00
|
|
|
{:ok, object}
|
|
|
|
else
|
|
|
|
{:ok, object}
|
|
|
|
end
|
2018-04-14 11:31:12 +00:00
|
|
|
end
|
|
|
|
|
2018-05-10 16:34:09 +00:00
|
|
|
@impl true
|
2018-04-14 11:31:12 +00:00
|
|
|
def filter(object) do
|
|
|
|
actor_info = URI.parse(object["actor"])
|
|
|
|
|
2018-06-19 21:23:37 +00:00
|
|
|
with {:ok, object} <- check_accept(actor_info, object),
|
|
|
|
{:ok, object} <- check_reject(actor_info, object),
|
2018-04-14 11:31:12 +00:00
|
|
|
{:ok, object} <- check_media_removal(actor_info, object),
|
|
|
|
{:ok, object} <- check_media_nsfw(actor_info, object),
|
|
|
|
{:ok, object} <- check_ftl_removal(actor_info, object) do
|
|
|
|
{:ok, object}
|
|
|
|
else
|
2018-05-04 20:59:01 +00:00
|
|
|
_e -> {:reject, nil}
|
2018-04-14 11:31:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|