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}}
45 # TODO: change way of getting settings on `lib/pleroma/web/activity_pub/mrf/user_allow_list_policy.ex:18` to use `hosts` subkey
47 # def config_description do
49 # key: :mrf_user_allowlist,
50 # related_policy: "Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy",
51 # description: "Accept-list of users from specified instances",
57 # "The keys in this section are the domain names that the policy should apply to." <>
58 # " Each key should be assigned a list of users that should be allowed " <>
59 # "through by their ActivityPub ID",
60 # suggestions: [%{"example.org" => ["https://example.org/users/admin"]}]