ActivityPub: implement MRF core hook and baseline noop policy object

This commit is contained in:
William Pitcock 2018-04-14 09:20:18 +00:00
parent fef8daa454
commit 4a178b3d65
4 changed files with 20 additions and 2 deletions

View File

@ -52,7 +52,8 @@ config :pleroma, :instance,
limit: 5000, limit: 5000,
upload_limit: 16_000_000, upload_limit: 16_000_000,
registrations_open: true, registrations_open: true,
federating: true federating: true,
rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy
config :pleroma, :media_proxy, config :pleroma, :media_proxy,
enabled: false, enabled: false,

View File

@ -10,6 +10,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
@httpoison Application.get_env(:pleroma, :httpoison) @httpoison Application.get_env(:pleroma, :httpoison)
@instance Application.get_env(:pleroma, :instance)
@rewrite_policy Keyword.get(@instance, :rewrite_policy)
def get_recipients(data) do def get_recipients(data) do
(data["to"] || []) ++ (data["cc"] || []) (data["to"] || []) ++ (data["cc"] || [])
end end
@ -17,7 +20,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
def insert(map, local \\ true) when is_map(map) do def insert(map, local \\ true) when is_map(map) do
with nil <- Activity.get_by_ap_id(map["id"]), with nil <- Activity.get_by_ap_id(map["id"]),
map <- lazy_put_activity_defaults(map), map <- lazy_put_activity_defaults(map),
:ok <- insert_full_object(map) do :ok <- insert_full_object(map),
{:ok, map} <- @rewrite_policy.filter(map) do
{:ok, activity} = {:ok, activity} =
Repo.insert(%Activity{ Repo.insert(%Activity{
data: map, data: map,

View File

@ -0,0 +1,8 @@
defmodule Pleroma.Web.ActivityPub.MRF.DropPolicy do
require Logger
def filter(object) do
Logger.info("REJECTING #{inspect(object)}")
{:reject, object}
end
end

View File

@ -0,0 +1,5 @@
defmodule Pleroma.Web.ActivityPub.MRF.NoOpPolicy do
def filter(object) do
{:ok, object}
end
end