Return maps in node_info
It's easiest (and imo most proper) to use tuples {"instance, "reason"} in BE, but for FE maps like %{"instance": "instance", "reason", "reason"} are better. I changed it so that node_info returns maps now for simple_policy and quarantined instances.
This commit is contained in:
parent
3ca8feb246
commit
0ab917ec6f
@ -245,6 +245,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
|
|||||||
mrf_simple =
|
mrf_simple =
|
||||||
Config.get(:mrf_simple)
|
Config.get(:mrf_simple)
|
||||||
|> Enum.map(fn {k, v} -> {k, Enum.reject(v, fn {v, _} -> v in exclusions end)} end)
|
|> Enum.map(fn {k, v} -> {k, Enum.reject(v, fn {v, _} -> v in exclusions end)} end)
|
||||||
|
|> Enum.map(fn {k, v} ->
|
||||||
|
{k, Enum.map(v, fn {i, r} -> %{"instance" => i, "reason" => r} end)}
|
||||||
|
end)
|
||||||
|> Enum.into(%{})
|
|> Enum.into(%{})
|
||||||
|
|
||||||
{:ok, %{mrf_simple: mrf_simple}}
|
{:ok, %{mrf_simple: mrf_simple}}
|
||||||
|
@ -88,7 +88,11 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
|||||||
{:ok, data} = MRF.describe()
|
{:ok, data} = MRF.describe()
|
||||||
|
|
||||||
data
|
data
|
||||||
|> Map.merge(%{quarantined_instances: quarantined})
|
|> Map.merge(%{
|
||||||
|
quarantined_instances:
|
||||||
|
quarantined
|
||||||
|
|> Enum.map(fn {instance, reason} -> %{"instance" => instance, "reason" => reason} end)
|
||||||
|
})
|
||||||
else
|
else
|
||||||
%{}
|
%{}
|
||||||
end
|
end
|
||||||
|
@ -152,6 +152,22 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it shows quarantined instances data if enabled", %{conn: conn} do
|
||||||
|
clear_config([:mrf, :transparency], true)
|
||||||
|
|
||||||
|
quarantined_instances = [{"example.com", ""}]
|
||||||
|
clear_config([:instance, :quarantined_instances], quarantined_instances)
|
||||||
|
|
||||||
|
expected_config = [%{"instance" => "example.com", "reason" => ""}]
|
||||||
|
|
||||||
|
response =
|
||||||
|
conn
|
||||||
|
|> get("/nodeinfo/2.1.json")
|
||||||
|
|> json_response(:ok)
|
||||||
|
|
||||||
|
assert response["metadata"]["federation"]["quarantined_instances"] == expected_config
|
||||||
|
end
|
||||||
|
|
||||||
test "it shows MRF transparency data if enabled", %{conn: conn} do
|
test "it shows MRF transparency data if enabled", %{conn: conn} do
|
||||||
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
|
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
|
||||||
clear_config([:mrf, :transparency], true)
|
clear_config([:mrf, :transparency], true)
|
||||||
@ -159,7 +175,7 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||||||
simple_config = %{"reject" => [{"example.com", ""}]}
|
simple_config = %{"reject" => [{"example.com", ""}]}
|
||||||
clear_config(:mrf_simple, simple_config)
|
clear_config(:mrf_simple, simple_config)
|
||||||
|
|
||||||
expected_config = %{"reject" => [["example.com", ""]]}
|
expected_config = %{"reject" => [%{"instance" => "example.com", "reason" => ""}]}
|
||||||
|
|
||||||
response =
|
response =
|
||||||
conn
|
conn
|
||||||
@ -177,7 +193,7 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||||||
simple_config = %{"reject" => [{"example.com", ""}, {"other.site", ""}]}
|
simple_config = %{"reject" => [{"example.com", ""}, {"other.site", ""}]}
|
||||||
clear_config(:mrf_simple, simple_config)
|
clear_config(:mrf_simple, simple_config)
|
||||||
|
|
||||||
expected_config = %{"reject" => [["example.com", ""]]}
|
expected_config = %{"reject" => [%{"instance" => "example.com", "reason" => ""}]}
|
||||||
|
|
||||||
response =
|
response =
|
||||||
conn
|
conn
|
||||||
|
Loading…
Reference in New Issue
Block a user