Return new-style config if old-style config is set to false.
authorlain <lain@soykaf.club>
Mon, 28 Jan 2019 12:07:12 +0000 (13:07 +0100)
committerlain <lain@soykaf.club>
Mon, 28 Jan 2019 12:07:12 +0000 (13:07 +0100)
This is in preparation for 1.0. We'll be able to switch the config to the new
mechanism on PleromaFE then as well.

lib/pleroma/web/twitter_api/controllers/util_controller.ex
test/web/twitter_api/util_controller_test.exs

index 0856428765372e010fc2547395a98229d1cb9819..b347faa71e204ee5f48fb567c26516b29fe63228 100644 (file)
@@ -183,25 +183,31 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
           invitesEnabled: if(Keyword.get(instance, :invites_enabled, false), do: "1", else: "0")
         }
 
-        pleroma_fe = %{
-          theme: Keyword.get(instance_fe, :theme),
-          background: Keyword.get(instance_fe, :background),
-          logo: Keyword.get(instance_fe, :logo),
-          logoMask: Keyword.get(instance_fe, :logo_mask),
-          logoMargin: Keyword.get(instance_fe, :logo_margin),
-          redirectRootNoLogin: Keyword.get(instance_fe, :redirect_root_no_login),
-          redirectRootLogin: Keyword.get(instance_fe, :redirect_root_login),
-          chatDisabled: !Keyword.get(instance_chat, :enabled),
-          showInstanceSpecificPanel: Keyword.get(instance_fe, :show_instance_panel),
-          scopeOptionsEnabled: Keyword.get(instance_fe, :scope_options_enabled),
-          formattingOptionsEnabled: Keyword.get(instance_fe, :formatting_options_enabled),
-          collapseMessageWithSubject: Keyword.get(instance_fe, :collapse_message_with_subject),
-          hidePostStats: Keyword.get(instance_fe, :hide_post_stats),
-          hideUserStats: Keyword.get(instance_fe, :hide_user_stats),
-          scopeCopy: Keyword.get(instance_fe, :scope_copy),
-          subjectLineBehavior: Keyword.get(instance_fe, :subject_line_behavior),
-          alwaysShowSubjectInput: Keyword.get(instance_fe, :always_show_subject_input)
-        }
+        pleroma_fe =
+          if instance_fe do
+            %{
+              theme: Keyword.get(instance_fe, :theme),
+              background: Keyword.get(instance_fe, :background),
+              logo: Keyword.get(instance_fe, :logo),
+              logoMask: Keyword.get(instance_fe, :logo_mask),
+              logoMargin: Keyword.get(instance_fe, :logo_margin),
+              redirectRootNoLogin: Keyword.get(instance_fe, :redirect_root_no_login),
+              redirectRootLogin: Keyword.get(instance_fe, :redirect_root_login),
+              chatDisabled: !Keyword.get(instance_chat, :enabled),
+              showInstanceSpecificPanel: Keyword.get(instance_fe, :show_instance_panel),
+              scopeOptionsEnabled: Keyword.get(instance_fe, :scope_options_enabled),
+              formattingOptionsEnabled: Keyword.get(instance_fe, :formatting_options_enabled),
+              collapseMessageWithSubject:
+                Keyword.get(instance_fe, :collapse_message_with_subject),
+              hidePostStats: Keyword.get(instance_fe, :hide_post_stats),
+              hideUserStats: Keyword.get(instance_fe, :hide_user_stats),
+              scopeCopy: Keyword.get(instance_fe, :scope_copy),
+              subjectLineBehavior: Keyword.get(instance_fe, :subject_line_behavior),
+              alwaysShowSubjectInput: Keyword.get(instance_fe, :always_show_subject_input)
+            }
+          else
+            Pleroma.Config.get([:frontend_configurations, :pleroma_fe])
+          end
 
         managed_config = Keyword.get(instance, :managed_config)
 
index c099db00381acc2505dfcda138df631627fb34a8..dc9bad3693d8b027b02db2520b7dfc6e59dc55ee 100644 (file)
@@ -33,7 +33,51 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
     end
   end
 
-  describe "GET /api/pleroma/frontent_configurations" do
+  describe "GET /api/statusnet/config.json" do
+    test "it returns the managed config", %{conn: conn} do
+      Pleroma.Config.put([:instance, :managed_config], false)
+
+      response =
+        conn
+        |> get("/api/statusnet/config.json")
+        |> json_response(:ok)
+
+      refute response["site"]["pleromafe"]
+
+      Pleroma.Config.put([:instance, :managed_config], true)
+
+      response =
+        conn
+        |> get("/api/statusnet/config.json")
+        |> json_response(:ok)
+
+      assert response["site"]["pleromafe"]
+    end
+
+    test "if :pleroma, :fe is false, it returns the new style config settings", %{conn: conn} do
+      Pleroma.Config.put([:instance, :managed_config], true)
+      Pleroma.Config.put([:fe, :theme], "rei-ayanami-towel")
+      Pleroma.Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
+
+      response =
+        conn
+        |> get("/api/statusnet/config.json")
+        |> json_response(:ok)
+
+      assert response["site"]["pleromafe"]["theme"] == "rei-ayanami-towel"
+
+      Pleroma.Config.put([:fe], false)
+
+      response =
+        conn
+        |> get("/api/statusnet/config.json")
+        |> json_response(:ok)
+
+      assert response["site"]["pleromafe"]["theme"] == "asuka-hospital"
+    end
+  end
+
+  describe "GET /api/pleroma/frontend_configurations" do
     test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do
       config = [
         frontend_a: %{