From e221c681dcd387aa445c35957a32fdc0189a0955 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 23 Jan 2019 12:40:57 +0100 Subject: New frontend configuration mechanism. --- config/config.exs | 19 ++++++++++++++++++ docs/config.md | 17 ++++++++++++++++ lib/pleroma/web/router.ex | 1 + .../web/twitter_api/controllers/util_controller.ex | 8 ++++++++ test/web/twitter_api/util_controller_test.exs | 23 ++++++++++++++++++++++ 5 files changed, 68 insertions(+) diff --git a/config/config.exs b/config/config.exs index d30b0aad0..7f63a0a39 100644 --- a/config/config.exs +++ b/config/config.exs @@ -154,6 +154,7 @@ config :pleroma, :markup, Pleroma.HTML.Scrubber.Default ] +# Deprecated, will be gone in 1.0 config :pleroma, :fe, theme: "pleroma-dark", logo: "/static/logo.png", @@ -172,6 +173,24 @@ config :pleroma, :fe, subject_line_behavior: "email", always_show_subject_input: true +config :pleroma, :frontend_configurations, + pleroma_fe: %{ + theme: "pleroma-dark", + logo: "/static/logo.png", + background: "/static/aurora_borealis.jpg", + redirectRootNoLogin: "/main/all", + redirectRootLogin: "/main/friends", + showInstanceSpecificPanel: true, + scopeOptionsEnabled: false, + formattingOptionsEnabled: false, + collapseMessageWithSubject: false, + hidePostStats: false, + hideUserStats: false, + scopeCopy: true, + subjectLineBehavior: "email", + alwaysShowSubjectInput: true + } + config :pleroma, :activitypub, accept_blocks: true, unfollow_blocked: true, diff --git a/docs/config.md b/docs/config.md index 6bf7b9ea7..ff4a1012c 100644 --- a/docs/config.md +++ b/docs/config.md @@ -101,7 +101,24 @@ config :pleroma, Pleroma.Mailer, * `backends`: `:console` is used to send logs to stdout, `{ExSyslogger, :ex_syslogger}` to log to syslog See: [logger’s documentation](https://hexdocs.pm/logger/Logger.html) and [ex_syslogger’s documentation](https://hexdocs.pm/ex_syslogger/) + +## :frontend_configurations + +This can be used to configure a keyword list that keeps the configuration data for any kind of frontend. By default, settings for `pleroma_fe` are configured. + +Frontends can access these settings at `/api/pleroma/frontend_configurations` + +To add your own configuration for PleromaFE, use it like this: + +`config :pleroma, :frontend_configurations, :pleroma_fe, %{theme: "my-theme", ...}` + +These settings need to be complete, they will overide the defaults. + ## :fe +__THIS IS DEPRACTED__ + +If you are using this method, please change it to the `frontend_configurations` method. + This section is used to configure Pleroma-FE, unless ``:managed_config`` in ``:instance`` is set to false. * `theme`: Which theme to use, they are defined in ``styles.json`` diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 69ab58c6a..8ddc642ea 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -284,6 +284,7 @@ defmodule Pleroma.Web.Router do post("/help/test", TwitterAPI.UtilController, :help_test) get("/statusnet/config", TwitterAPI.UtilController, :config) get("/statusnet/version", TwitterAPI.UtilController, :version) + get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations) end scope "/api", Pleroma.Web do diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index a79072f3d..085642876 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -216,6 +216,14 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do end end + def frontend_configurations(conn, _params) do + config = + Pleroma.Config.get(:frontend_configurations, %{}) + |> Enum.into(%{}) + + json(conn, config) + end + def version(conn, _params) do version = Pleroma.Application.named_version() diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index 73aa70bd5..c099db003 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -32,4 +32,27 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do assert response == "job started" end end + + describe "GET /api/pleroma/frontent_configurations" do + test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do + config = [ + frontend_a: %{ + x: 1, + y: 2 + }, + frontend_b: %{ + z: 3 + } + ] + + Pleroma.Config.put(:frontend_configurations, config) + + response = + conn + |> get("/api/pleroma/frontend_configurations") + |> json_response(:ok) + + assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!() + end + end end -- cgit v1.2.3 From f231313b709cef32611927cabd8cadb5b0787dc5 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 28 Jan 2019 12:09:41 +0100 Subject: Add deprecation warning mechanism. --- lib/pleroma/application.ex | 2 ++ lib/pleroma/deprecation_warnings.ex | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 lib/pleroma/deprecation_warnings.ex diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index ad2797209..f63477934 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -22,6 +22,8 @@ defmodule Pleroma.Application do def start(_type, _args) do import Cachex.Spec + Task.start(&Pleroma.DeprecationWarnings.warn/0) + # Define workers and child supervisors to be supervised children = [ diff --git a/lib/pleroma/deprecation_warnings.ex b/lib/pleroma/deprecation_warnings.ex new file mode 100644 index 000000000..abb649919 --- /dev/null +++ b/lib/pleroma/deprecation_warnings.ex @@ -0,0 +1,20 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.DeprecationWarnings do + require Logger + + def check_frontend_config_mechanism() do + if Pleroma.Config.get(:fe) do + Logger.warn(""" + !!!DEPRECATION WARNING!!! + You are using the old configuration mechanism for the frontend. Please check config.md. + """) + end + end + + def warn do + check_frontend_config_mechanism() + end +end -- cgit v1.2.3 From 39b245773456b6bd5f0950139788108039557efa Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 28 Jan 2019 13:04:51 +0100 Subject: Change default bg image in new config. --- config/config.exs | 2 +- priv/static/images/city.jpg | Bin 0 -> 3191646 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 priv/static/images/city.jpg diff --git a/config/config.exs b/config/config.exs index 7f63a0a39..1fec46f0b 100644 --- a/config/config.exs +++ b/config/config.exs @@ -177,7 +177,7 @@ config :pleroma, :frontend_configurations, pleroma_fe: %{ theme: "pleroma-dark", logo: "/static/logo.png", - background: "/static/aurora_borealis.jpg", + background: "/images/city.jpg", redirectRootNoLogin: "/main/all", redirectRootLogin: "/main/friends", showInstanceSpecificPanel: true, diff --git a/priv/static/images/city.jpg b/priv/static/images/city.jpg new file mode 100644 index 000000000..c32204719 Binary files /dev/null and b/priv/static/images/city.jpg differ -- cgit v1.2.3 From f1d58c5c494d66f89573e2787935ee9f50f18c31 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 28 Jan 2019 13:05:17 +0100 Subject: Don't run warnings in a task. --- lib/pleroma/application.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index f63477934..aa46bcbc4 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -22,7 +22,7 @@ defmodule Pleroma.Application do def start(_type, _args) do import Cachex.Spec - Task.start(&Pleroma.DeprecationWarnings.warn/0) + Pleroma.DeprecationWarnings.warn() # Define workers and child supervisors to be supervised children = -- cgit v1.2.3 From bcc559e4e61988c9d2c74dd407329b1a4c458400 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 28 Jan 2019 13:06:28 +0100 Subject: Update config.md --- docs/config.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/config.md b/docs/config.md index ff4a1012c..7af6119bd 100644 --- a/docs/config.md +++ b/docs/config.md @@ -115,9 +115,9 @@ To add your own configuration for PleromaFE, use it like this: These settings need to be complete, they will overide the defaults. ## :fe -__THIS IS DEPRACTED__ +__THIS IS DEPRECATED__ -If you are using this method, please change it to the `frontend_configurations` method. +If you are using this method, please change it to the `frontend_configurations` method. Please set this option to false in your config like this: `config :pleroma, :fe, false`. This section is used to configure Pleroma-FE, unless ``:managed_config`` in ``:instance`` is set to false. -- cgit v1.2.3 From 8e8a1e1ba8a08bc297884fe085b4542a052d6d01 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 28 Jan 2019 13:07:12 +0100 Subject: 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. --- .../web/twitter_api/controllers/util_controller.ex | 44 ++++++++++++--------- test/web/twitter_api/util_controller_test.exs | 46 +++++++++++++++++++++- 2 files changed, 70 insertions(+), 20 deletions(-) diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 085642876..b347faa71 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -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) diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index c099db003..dc9bad369 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -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: %{ -- cgit v1.2.3 From f53d464db0194eb66557b00c7d92b9df8c798ada Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 28 Jan 2019 14:39:54 +0100 Subject: Put deprecation warnings undre Pleroma.Config. --- lib/pleroma/application.ex | 2 +- lib/pleroma/config/deprecation_warnings.ex | 20 ++++++++++++++++++++ lib/pleroma/deprecation_warnings.ex | 20 -------------------- 3 files changed, 21 insertions(+), 21 deletions(-) create mode 100644 lib/pleroma/config/deprecation_warnings.ex delete mode 100644 lib/pleroma/deprecation_warnings.ex diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index aa46bcbc4..31f2605b8 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -22,7 +22,7 @@ defmodule Pleroma.Application do def start(_type, _args) do import Cachex.Spec - Pleroma.DeprecationWarnings.warn() + Pleroma.Config.DeprecationWarnings.warn() # Define workers and child supervisors to be supervised children = diff --git a/lib/pleroma/config/deprecation_warnings.ex b/lib/pleroma/config/deprecation_warnings.ex new file mode 100644 index 000000000..dc50682ee --- /dev/null +++ b/lib/pleroma/config/deprecation_warnings.ex @@ -0,0 +1,20 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Config.DeprecationWarnings do + require Logger + + def check_frontend_config_mechanism() do + if Pleroma.Config.get(:fe) do + Logger.warn(""" + !!!DEPRECATION WARNING!!! + You are using the old configuration mechanism for the frontend. Please check config.md. + """) + end + end + + def warn do + check_frontend_config_mechanism() + end +end diff --git a/lib/pleroma/deprecation_warnings.ex b/lib/pleroma/deprecation_warnings.ex deleted file mode 100644 index abb649919..000000000 --- a/lib/pleroma/deprecation_warnings.ex +++ /dev/null @@ -1,20 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.DeprecationWarnings do - require Logger - - def check_frontend_config_mechanism() do - if Pleroma.Config.get(:fe) do - Logger.warn(""" - !!!DEPRECATION WARNING!!! - You are using the old configuration mechanism for the frontend. Please check config.md. - """) - end - end - - def warn do - check_frontend_config_mechanism() - end -end -- cgit v1.2.3