logo

pleroma

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

reject_non_public.ex (2044B)


  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.RejectNonPublic do
  5. @moduledoc "Rejects non-public (followers-only, direct) activities"
  6. alias Pleroma.Config
  7. alias Pleroma.User
  8. @behaviour Pleroma.Web.ActivityPub.MRF.Policy
  9. require Pleroma.Constants
  10. @impl true
  11. def filter(%{"type" => "Create"} = object) do
  12. user = User.get_cached_by_ap_id(object["actor"])
  13. # Determine visibility
  14. visibility =
  15. cond do
  16. Pleroma.Constants.as_public() in object["to"] -> "public"
  17. Pleroma.Constants.as_public() in object["cc"] -> "unlisted"
  18. user.follower_address in object["to"] -> "followers"
  19. true -> "direct"
  20. end
  21. policy = Config.get(:mrf_rejectnonpublic)
  22. cond do
  23. visibility in ["public", "unlisted"] ->
  24. {:ok, object}
  25. visibility == "followers" and Keyword.get(policy, :allow_followersonly) ->
  26. {:ok, object}
  27. visibility == "direct" and Keyword.get(policy, :allow_direct) ->
  28. {:ok, object}
  29. true ->
  30. {:reject, "[RejectNonPublic] visibility: #{visibility}"}
  31. end
  32. end
  33. @impl true
  34. def filter(object), do: {:ok, object}
  35. @impl true
  36. def describe,
  37. do: {:ok, %{mrf_rejectnonpublic: Config.get(:mrf_rejectnonpublic) |> Map.new()}}
  38. @impl true
  39. def config_description do
  40. %{
  41. key: :mrf_rejectnonpublic,
  42. related_policy: "Pleroma.Web.ActivityPub.MRF.RejectNonPublic",
  43. description: "RejectNonPublic drops posts with non-public visibility settings.",
  44. label: "MRF Reject Non Public",
  45. children: [
  46. %{
  47. key: :allow_followersonly,
  48. label: "Allow followers-only",
  49. type: :boolean,
  50. description: "Whether to allow followers-only posts"
  51. },
  52. %{
  53. key: :allow_direct,
  54. type: :boolean,
  55. description: "Whether to allow direct messages"
  56. }
  57. ]
  58. }
  59. end
  60. end