forked from AkkomaGang/akkoma
Merge branch 'feature/chain-policies' into 'develop'
chain policies See merge request pleroma/pleroma!150
This commit is contained in:
commit
4ad5e72012
5 changed files with 33 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
alias Pleroma.{Activity, Repo, Object, Upload, User, Notification}
|
alias Pleroma.{Activity, Repo, Object, Upload, User, Notification}
|
||||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
alias Pleroma.Web.ActivityPub.{Transmogrifier, MRF}
|
||||||
alias Pleroma.Web.WebFinger
|
alias Pleroma.Web.WebFinger
|
||||||
alias Pleroma.Web.Federator
|
alias Pleroma.Web.Federator
|
||||||
alias Pleroma.Web.OStatus
|
alias Pleroma.Web.OStatus
|
||||||
|
@ -11,7 +11,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
@httpoison Application.get_env(:pleroma, :httpoison)
|
@httpoison Application.get_env(:pleroma, :httpoison)
|
||||||
|
|
||||||
@instance Application.get_env(:pleroma, :instance)
|
@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"] || [])
|
||||||
|
@ -20,7 +19,7 @@ def get_recipients(data) 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, map} <- @rewrite_policy.filter(map),
|
{:ok, map} <- MRF.filter(map),
|
||||||
:ok <- insert_full_object(map) do
|
:ok <- insert_full_object(map) do
|
||||||
{:ok, activity} =
|
{:ok, activity} =
|
||||||
Repo.insert(%Activity{
|
Repo.insert(%Activity{
|
||||||
|
|
24
lib/pleroma/web/activity_pub/mrf.ex
Normal file
24
lib/pleroma/web/activity_pub/mrf.ex
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
defmodule Pleroma.Web.ActivityPub.MRF do
|
||||||
|
@callback filter(Map.t()) :: {:ok | :reject, Map.t()}
|
||||||
|
|
||||||
|
def filter(object) do
|
||||||
|
get_policies()
|
||||||
|
|> Enum.reduce({:ok, object}, fn
|
||||||
|
policy, {:ok, object} ->
|
||||||
|
policy.filter(object)
|
||||||
|
|
||||||
|
_, error ->
|
||||||
|
error
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_policies() do
|
||||||
|
Application.get_env(:pleroma, :instance, [])
|
||||||
|
|> Keyword.get(:rewrite_policy, [])
|
||||||
|
|> get_policies()
|
||||||
|
end
|
||||||
|
|
||||||
|
defp get_policies(policy) when is_atom(policy), do: [policy]
|
||||||
|
defp get_policies(policies) when is_list(policies), do: policies
|
||||||
|
defp get_policies(_), do: []
|
||||||
|
end
|
|
@ -1,6 +1,8 @@
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.DropPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.DropPolicy do
|
||||||
require Logger
|
require Logger
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
|
@impl true
|
||||||
def filter(object) do
|
def filter(object) do
|
||||||
Logger.info("REJECTING #{inspect(object)}")
|
Logger.info("REJECTING #{inspect(object)}")
|
||||||
{:reject, object}
|
{:reject, object}
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.NoOpPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.NoOpPolicy do
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
|
@impl true
|
||||||
def filter(object) do
|
def filter(object) do
|
||||||
{:ok, object}
|
{:ok, object}
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
@mrf_policy Application.get_env(:pleroma, :mrf_simple)
|
@mrf_policy Application.get_env(:pleroma, :mrf_simple)
|
||||||
|
|
||||||
|
@ -69,6 +70,7 @@ defp check_ftl_removal(actor_info, object) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
def filter(object) do
|
def filter(object) do
|
||||||
actor_info = URI.parse(object["actor"])
|
actor_info = URI.parse(object["actor"])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue