2018-12-23 20:04:54 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 20:04:54 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-11-26 23:23:43 +00:00
|
|
|
defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy do
|
|
|
|
alias Pleroma.Config
|
|
|
|
|
2019-05-06 02:28:04 +00:00
|
|
|
@moduledoc "Accept-list of users from specified instances"
|
2021-06-07 19:22:08 +00:00
|
|
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
2018-11-26 23:23:43 +00:00
|
|
|
|
|
|
|
defp filter_by_list(object, []), do: {:ok, object}
|
|
|
|
|
|
|
|
defp filter_by_list(%{"actor" => actor} = object, allow_list) do
|
|
|
|
if actor in allow_list do
|
|
|
|
{:ok, object}
|
|
|
|
else
|
2020-07-13 13:47:13 +00:00
|
|
|
{:reject, "[UserAllowListPolicy] #{actor} not in the list"}
|
2018-11-26 23:23:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
2019-05-22 04:15:59 +00:00
|
|
|
def filter(%{"actor" => actor} = object) do
|
|
|
|
actor_info = URI.parse(actor)
|
2019-07-10 05:12:21 +00:00
|
|
|
|
|
|
|
allow_list =
|
|
|
|
Config.get(
|
2020-06-10 15:34:23 +00:00
|
|
|
[:mrf_user_allowlist, actor_info.host],
|
2019-07-10 05:12:21 +00:00
|
|
|
[]
|
|
|
|
)
|
2018-11-26 23:23:43 +00:00
|
|
|
|
|
|
|
filter_by_list(object, allow_list)
|
|
|
|
end
|
2019-05-22 04:15:59 +00:00
|
|
|
|
|
|
|
def filter(object), do: {:ok, object}
|
2019-08-13 21:52:54 +00:00
|
|
|
|
|
|
|
@impl true
|
2019-08-13 22:36:24 +00:00
|
|
|
def describe do
|
2019-08-13 21:52:54 +00:00
|
|
|
mrf_user_allowlist =
|
|
|
|
Config.get([:mrf_user_allowlist], [])
|
2021-02-04 13:23:21 +00:00
|
|
|
|> Map.new(fn {k, v} -> {k, length(v)} end)
|
2019-08-13 21:52:54 +00:00
|
|
|
|
|
|
|
{:ok, %{mrf_user_allowlist: mrf_user_allowlist}}
|
|
|
|
end
|
2020-11-10 16:18:53 +00:00
|
|
|
|
2020-11-11 07:10:57 +00:00
|
|
|
# TODO: change way of getting settings on `lib/pleroma/web/activity_pub/mrf/user_allow_list_policy.ex:18` to use `hosts` subkey
|
|
|
|
# @impl true
|
|
|
|
# def config_description do
|
|
|
|
# %{
|
|
|
|
# key: :mrf_user_allowlist,
|
|
|
|
# related_policy: "Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy",
|
|
|
|
# description: "Accept-list of users from specified instances",
|
|
|
|
# children: [
|
|
|
|
# %{
|
|
|
|
# key: :hosts,
|
|
|
|
# type: :map,
|
|
|
|
# description:
|
|
|
|
# "The keys in this section are the domain names that the policy should apply to." <>
|
2020-11-11 07:48:03 +00:00
|
|
|
# " Each key should be assigned a list of users that should be allowed " <>
|
|
|
|
# "through by their ActivityPub ID",
|
2020-11-11 07:10:57 +00:00
|
|
|
# suggestions: [%{"example.org" => ["https://example.org/users/admin"]}]
|
|
|
|
# }
|
|
|
|
# ]
|
|
|
|
# }
|
|
|
|
# end
|
2018-11-26 23:23:43 +00:00
|
|
|
end
|