1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy do
8 @moduledoc "Accept-list of users from specified instances"
9 @behaviour Pleroma.Web.ActivityPub.MRF
11 defp filter_by_list(object, []), do: {:ok, object}
13 defp filter_by_list(%{"actor" => actor} = object, allow_list) do
14 if actor in allow_list do
17 {:reject, "[UserAllowListPolicy] #{actor} not in the list"}
22 def filter(%{"actor" => actor} = object) do
23 actor_info = URI.parse(actor)
27 [:mrf_user_allowlist, actor_info.host],
31 filter_by_list(object, allow_list)
34 def filter(object), do: {:ok, object}
39 Config.get([:mrf_user_allowlist], [])
40 |> Enum.into(%{}, fn {k, v} -> {k, length(v)} end)
42 {:ok, %{mrf_user_allowlist: mrf_user_allowlist}}
46 def config_description do
48 key: :mrf_user_allowlist,
49 related_policy: "Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy",
51 "The keys in this section are the domain names that the policy should apply to." <>
52 " Each key should be assigned a list of users that should be allowed through by their ActivityPub ID",
54 %{"example.org" => ["https://example.org/users/admin"]}