logo

pleroma

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

user_allow_list_policy.ex (1944B)


  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.UserAllowListPolicy do
  5. alias Pleroma.Config
  6. @moduledoc "Accept-list of users from specified instances"
  7. @behaviour Pleroma.Web.ActivityPub.MRF.Policy
  8. defp filter_by_list(object, []), do: {:ok, object}
  9. defp filter_by_list(%{"actor" => actor} = object, allow_list) do
  10. if actor in allow_list do
  11. {:ok, object}
  12. else
  13. {:reject, "[UserAllowListPolicy] #{actor} not in the list"}
  14. end
  15. end
  16. @impl true
  17. def filter(%{"actor" => actor} = object) do
  18. actor_info = URI.parse(actor)
  19. allow_list =
  20. Config.get(
  21. [:mrf_user_allowlist, actor_info.host],
  22. []
  23. )
  24. filter_by_list(object, allow_list)
  25. end
  26. def filter(object), do: {:ok, object}
  27. @impl true
  28. def describe do
  29. mrf_user_allowlist =
  30. Config.get([:mrf_user_allowlist], [])
  31. |> Map.new(fn {k, v} -> {k, length(v)} end)
  32. {:ok, %{mrf_user_allowlist: mrf_user_allowlist}}
  33. end
  34. # TODO: change way of getting settings on `lib/pleroma/web/activity_pub/mrf/user_allow_list_policy.ex:18` to use `hosts` subkey
  35. # @impl true
  36. # def config_description do
  37. # %{
  38. # key: :mrf_user_allowlist,
  39. # related_policy: "Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy",
  40. # description: "Accept-list of users from specified instances",
  41. # children: [
  42. # %{
  43. # key: :hosts,
  44. # type: :map,
  45. # description:
  46. # "The keys in this section are the domain names that the policy should apply to." <>
  47. # " Each key should be assigned a list of users that should be allowed " <>
  48. # "through by their ActivityPub ID",
  49. # suggestions: [%{"example.org" => ["https://example.org/users/admin"]}]
  50. # }
  51. # ]
  52. # }
  53. # end
  54. end