2018-12-23 20:04:54 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-02 05:08:45 +00:00
|
|
|
# Copyright © 2017-2020 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"
|
2018-11-26 23:23:43 +00:00
|
|
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
|
|
|
|
|
|
|
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], [])
|
|
|
|
|> Enum.into(%{}, fn {k, v} -> {k, length(v)} end)
|
|
|
|
|
|
|
|
{:ok, %{mrf_user_allowlist: mrf_user_allowlist}}
|
|
|
|
end
|
2018-11-26 23:23:43 +00:00
|
|
|
end
|