logo

pleroma

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

vocabulary_policy.ex (2369B)


  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 activities which belong to certain activity vocabularies"
  6. @behaviour Pleroma.Web.ActivityPub.MRF.Policy
  7. @impl true
  8. def filter(%{"type" => "Undo", "object" => object} = activity) do
  9. with {:ok, _} <- filter(object) do
  10. {:ok, activity}
  11. else
  12. {:reject, _} = e -> e
  13. end
  14. end
  15. def filter(%{"type" => activity_type} = activity) 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, activity_type)},
  21. {_, false} <-
  22. {:rejected,
  23. length(rejected_vocabulary) > 0 && Enum.member?(rejected_vocabulary, activity_type)},
  24. {:ok, _} <- filter(activity["object"]) do
  25. {:ok, activity}
  26. else
  27. {:reject, _} = e -> e
  28. {:accepted, _} -> {:reject, "[VocabularyPolicy] #{activity_type} not in accept list"}
  29. {:rejected, _} -> {:reject, "[VocabularyPolicy] #{activity_type} in reject list"}
  30. end
  31. end
  32. def filter(activity), do: {:ok, activity}
  33. @impl true
  34. def describe,
  35. do: {:ok, %{mrf_vocabulary: Pleroma.Config.get(:mrf_vocabulary) |> Map.new()}}
  36. @impl true
  37. def config_description do
  38. %{
  39. key: :mrf_vocabulary,
  40. related_policy: "Pleroma.Web.ActivityPub.MRF.VocabularyPolicy",
  41. label: "MRF Vocabulary",
  42. description: "Filter activities which belong to certain activity vocabularies",
  43. children: [
  44. %{
  45. key: :accept,
  46. type: {:list, :string},
  47. description:
  48. "A list of ActivityStreams terms to accept. If empty, all supported activities are accepted.",
  49. suggestions: ["Create", "Follow", "Mention", "Announce", "Like"]
  50. },
  51. %{
  52. key: :reject,
  53. type: {:list, :string},
  54. description:
  55. "A list of ActivityStreams terms to reject. If empty, no activities are rejected.",
  56. suggestions: ["Create", "Follow", "Mention", "Announce", "Like"]
  57. }
  58. ]
  59. }
  60. end
  61. end