From 7fdc3cde065ce20257e0e03e416ca18775b18943 Mon Sep 17 00:00:00 2001 From: Ilja Date: Fri, 23 Oct 2020 20:27:13 +0200 Subject: [PATCH] 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. --- .../web/activity_pub/mrf/simple_policy.ex | 3 +++ .../web/mastodon_api/views/instance_view.ex | 6 +++++- test/pleroma/web/node_info_test.exs | 20 +++++++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex index 2f26fc3a0..0853a05a7 100644 --- a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex @@ -263,6 +263,9 @@ def describe do 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.map(v, fn {i, r} -> %{"instance" => i, "reason" => r} end)} + end) |> Enum.into(%{}) {:ok, %{mrf_simple: mrf_simple}} diff --git a/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex index 3528185d5..db40ea3fa 100644 --- a/lib/pleroma/web/mastodon_api/views/instance_view.ex +++ b/lib/pleroma/web/mastodon_api/views/instance_view.ex @@ -95,7 +95,11 @@ def federation do {:ok, data} = MRF.describe() data - |> Map.merge(%{quarantined_instances: quarantined}) + |> Map.merge(%{ + quarantined_instances: + quarantined + |> Enum.map(fn {instance, reason} -> %{"instance" => instance, "reason" => reason} end) + }) else %{} end diff --git a/test/pleroma/web/node_info_test.exs b/test/pleroma/web/node_info_test.exs index 477c44a51..cb910d668 100644 --- a/test/pleroma/web/node_info_test.exs +++ b/test/pleroma/web/node_info_test.exs @@ -150,6 +150,22 @@ test "it shows default features flags", %{conn: conn} do ) 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 clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy]) clear_config([:mrf, :transparency], true) @@ -157,7 +173,7 @@ test "it shows MRF transparency data if enabled", %{conn: conn} do simple_config = %{"reject" => [{"example.com", ""}]} clear_config(:mrf_simple, simple_config) - expected_config = %{"reject" => [["example.com", ""]]} + expected_config = %{"reject" => [%{"instance" => "example.com", "reason" => ""}]} response = conn @@ -175,7 +191,7 @@ test "it performs exclusions from MRF transparency data if configured", %{conn: simple_config = %{"reject" => [{"example.com", ""}, {"other.site", ""}]} clear_config(:mrf_simple, simple_config) - expected_config = %{"reject" => [["example.com", ""]]} + expected_config = %{"reject" => [%{"instance" => "example.com", "reason" => ""}]} response = conn