Add publicTimelineVisibility to nodeinfo
authorFloatingGhost <hannah@coffee-and-dreams.uk>
Wed, 15 Mar 2023 22:13:18 +0000 (22:13 +0000)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Wed, 15 Mar 2023 22:13:18 +0000 (22:13 +0000)
lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
test/pleroma/web/node_info_test.exs

index a0dee7c6bc283d370e667a051bb61ad530adcdf4..9a76574d54e0f682e08e3b9a1a570e9f29ffca4e 100644 (file)
@@ -89,7 +89,11 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
         features: features,
         restrictedNicknames: Config.get([Pleroma.User, :restricted_nicknames]),
         skipThreadContainment: Config.get([:instance, :skip_thread_containment], false),
-        localBubbleInstances: Config.get([:instance, :local_bubble], [])
+        localBubbleInstances: Config.get([:instance, :local_bubble], []),
+        publicTimelineVisibility: %{
+          federated: !Config.restrict_unauthenticated_access?(:timelines, :federated),
+          local: !Config.restrict_unauthenticated_access?(:timelines, :local)
+        }
       }
     }
   end
index 05a078266c1d41d950f09653a4e37a0fa10de9e1..5f001be8516d177e1649e6d8c6090ca753a008cd 100644 (file)
@@ -292,4 +292,34 @@ defmodule Pleroma.Web.NodeInfoTest do
       assert response["metadata"]["federation"]["mrf_simple_info"] == expected_config
     end
   end
+
+  describe "public timeline visibility" do
+    test "shows public timeline visibility", %{conn: conn} do
+      clear_config([:restrict_unauthenticated, :timelines], %{local: false, federated: false})
+      response =
+        conn
+        |> get("/nodeinfo/2.1.json")
+        |> json_response(:ok)
+
+      assert response["metadata"]["publicTimelineVisibility"]["local"] == true
+      assert response["metadata"]["publicTimelineVisibility"]["federated"] == true
+
+      clear_config([:restrict_unauthenticated, :timelines], %{local: true, federated: false})
+      response =
+        conn
+        |> get("/nodeinfo/2.1.json")
+        |> json_response(:ok)
+      assert response["metadata"]["publicTimelineVisibility"]["local"] == false
+      assert response["metadata"]["publicTimelineVisibility"]["federated"] == true
+
+      clear_config([:restrict_unauthenticated, :timelines], %{local: false, federated: true})
+      response =
+        conn
+        |> get("/nodeinfo/2.1.json")
+        |> json_response(:ok)
+
+      assert response["metadata"]["publicTimelineVisibility"]["local"] == true
+      assert response["metadata"]["publicTimelineVisibility"]["federated"] == false
+    end
+  end
 end