Merge branch 'feature/mastofe-admin-scope' into 'develop'
[akkoma] / lib / pleroma / web / activity_pub / mrf / vocabulary_policy.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicy do
6 @moduledoc "Filter messages which belong to certain activity vocabularies"
7
8 @behaviour Pleroma.Web.ActivityPub.MRF
9
10 def filter(%{"type" => "Undo", "object" => child_message} = message) do
11 with {:ok, _} <- filter(child_message) do
12 {:ok, message}
13 else
14 {:reject, nil} ->
15 {:reject, nil}
16 end
17 end
18
19 def filter(%{"type" => message_type} = message) do
20 with accepted_vocabulary <- Pleroma.Config.get([:mrf_vocabulary, :accept]),
21 rejected_vocabulary <- Pleroma.Config.get([:mrf_vocabulary, :reject]),
22 true <-
23 Enum.empty?(accepted_vocabulary) || Enum.member?(accepted_vocabulary, message_type),
24 false <-
25 length(rejected_vocabulary) > 0 && Enum.member?(rejected_vocabulary, message_type),
26 {:ok, _} <- filter(message["object"]) do
27 {:ok, message}
28 else
29 _ -> {:reject, nil}
30 end
31 end
32
33 def filter(message), do: {:ok, message}
34
35 def describe,
36 do: {:ok, %{mrf_vocabulary: Pleroma.Config.get(:mrf_vocabulary) |> Enum.into(%{})}}
37 end