Return new-style config if old-style config is set to false.

This is in preparation for 1.0. We'll be able to switch the config to the new
mechanism on PleromaFE then as well.
This commit is contained in:
lain 2019-01-28 13:07:12 +01:00
parent bcc559e4e6
commit 8e8a1e1ba8
2 changed files with 70 additions and 20 deletions

View File

@ -183,25 +183,31 @@ def config(conn, _params) do
invitesEnabled: if(Keyword.get(instance, :invites_enabled, false), do: "1", else: "0") invitesEnabled: if(Keyword.get(instance, :invites_enabled, false), do: "1", else: "0")
} }
pleroma_fe = %{ pleroma_fe =
theme: Keyword.get(instance_fe, :theme), if instance_fe do
background: Keyword.get(instance_fe, :background), %{
logo: Keyword.get(instance_fe, :logo), theme: Keyword.get(instance_fe, :theme),
logoMask: Keyword.get(instance_fe, :logo_mask), background: Keyword.get(instance_fe, :background),
logoMargin: Keyword.get(instance_fe, :logo_margin), logo: Keyword.get(instance_fe, :logo),
redirectRootNoLogin: Keyword.get(instance_fe, :redirect_root_no_login), logoMask: Keyword.get(instance_fe, :logo_mask),
redirectRootLogin: Keyword.get(instance_fe, :redirect_root_login), logoMargin: Keyword.get(instance_fe, :logo_margin),
chatDisabled: !Keyword.get(instance_chat, :enabled), redirectRootNoLogin: Keyword.get(instance_fe, :redirect_root_no_login),
showInstanceSpecificPanel: Keyword.get(instance_fe, :show_instance_panel), redirectRootLogin: Keyword.get(instance_fe, :redirect_root_login),
scopeOptionsEnabled: Keyword.get(instance_fe, :scope_options_enabled), chatDisabled: !Keyword.get(instance_chat, :enabled),
formattingOptionsEnabled: Keyword.get(instance_fe, :formatting_options_enabled), showInstanceSpecificPanel: Keyword.get(instance_fe, :show_instance_panel),
collapseMessageWithSubject: Keyword.get(instance_fe, :collapse_message_with_subject), scopeOptionsEnabled: Keyword.get(instance_fe, :scope_options_enabled),
hidePostStats: Keyword.get(instance_fe, :hide_post_stats), formattingOptionsEnabled: Keyword.get(instance_fe, :formatting_options_enabled),
hideUserStats: Keyword.get(instance_fe, :hide_user_stats), collapseMessageWithSubject:
scopeCopy: Keyword.get(instance_fe, :scope_copy), Keyword.get(instance_fe, :collapse_message_with_subject),
subjectLineBehavior: Keyword.get(instance_fe, :subject_line_behavior), hidePostStats: Keyword.get(instance_fe, :hide_post_stats),
alwaysShowSubjectInput: Keyword.get(instance_fe, :always_show_subject_input) 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) managed_config = Keyword.get(instance, :managed_config)

View File

@ -33,7 +33,51 @@ test "it returns HTTP 200", %{conn: conn} do
end end
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 test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do
config = [ config = [
frontend_a: %{ frontend_a: %{