logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

vocabulary_policy.ex (2406B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicy do
  5. @moduledoc "Filter messages which belong to certain activity vocabularies"
  6. @behaviour Pleroma.Web.ActivityPub.MRF.Policy
  7. @impl true
  8. def filter(%{"type" => "Undo", "object" => child_message} = message) do
  9. with {:ok, _} <- filter(child_message) do
  10. {:ok, message}
  11. else
  12. {:reject, _} = e -> e
  13. end
  14. end
  15. def filter(%{"type" => message_type} = message) do
  16. with accepted_vocabulary <- Pleroma.Config.get([:mrf_vocabulary, :accept]),
  17. rejected_vocabulary <- Pleroma.Config.get([:mrf_vocabulary, :reject]),
  18. {_, true} <-
  19. {:accepted,
  20. Enum.empty?(accepted_vocabulary) || Enum.member?(accepted_vocabulary, message_type)},
  21. {_, false} <-
  22. {:rejected,
  23. length(rejected_vocabulary) > 0 && Enum.member?(rejected_vocabulary, message_type)},
  24. {:ok, _} <- filter(message["object"]) do
  25. {:ok, message}
  26. else
  27. {:reject, _} = e -> e
  28. {:accepted, _} -> {:reject, "[VocabularyPolicy] #{message_type} not in accept list"}
  29. {:rejected, _} -> {:reject, "[VocabularyPolicy] #{message_type} in reject list"}
  30. _ -> {:reject, "[VocabularyPolicy]"}
  31. end
  32. end
  33. def filter(message), do: {:ok, message}
  34. @impl true
  35. def describe,
  36. do: {:ok, %{mrf_vocabulary: Pleroma.Config.get(:mrf_vocabulary) |> Map.new()}}
  37. @impl true
  38. def config_description do
  39. %{
  40. key: :mrf_vocabulary,
  41. related_policy: "Pleroma.Web.ActivityPub.MRF.VocabularyPolicy",
  42. label: "MRF Vocabulary",
  43. description: "Filter messages which belong to certain activity vocabularies",
  44. children: [
  45. %{
  46. key: :accept,
  47. type: {:list, :string},
  48. description:
  49. "A list of ActivityStreams terms to accept. If empty, all supported messages are accepted.",
  50. suggestions: ["Create", "Follow", "Mention", "Announce", "Like"]
  51. },
  52. %{
  53. key: :reject,
  54. type: {:list, :string},
  55. description:
  56. "A list of ActivityStreams terms to reject. If empty, no messages are rejected.",
  57. suggestions: ["Create", "Follow", "Mention", "Announce", "Like"]
  58. }
  59. ]
  60. }
  61. end
  62. end