From 1489c2ae5fdb01ee2f1a40c40582842868cac888 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Tue, 4 Aug 2020 01:45:18 +0300 Subject: [PATCH 1/6] Fix :args settings description in Upload.Filter.Mogrify group --- config/description.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/description.exs b/config/description.exs index ae2f6d23f..00bab20eb 100644 --- a/config/description.exs +++ b/config/description.exs @@ -194,7 +194,7 @@ config :pleroma, :config_description, [ type: [:string, {:list, :string}, {:list, :tuple}], description: "List of actions for the mogrify command. It's possible to add self-written settings as string. " <> - "For example `[\"auto-orient\", \"strip\", {\"resize\", \"3840x1080>\"}]` string will be parsed into list of the settings.", + "For example `auto-orient, strip, {\"resize\", \"3840x1080>\"}` value will be parsed into valid list of the settings.", suggestions: [ "strip", "auto-orient", From ae95472dccbf708259f49730149a1599e9ac0e9c Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Tue, 4 Aug 2020 02:04:29 +0300 Subject: [PATCH 2/6] Update :welcome settings description --- config/description.exs | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/config/description.exs b/config/description.exs index 00bab20eb..a947c8f3f 100644 --- a/config/description.exs +++ b/config/description.exs @@ -964,25 +964,26 @@ config :pleroma, :config_description, [ ] }, %{ - group: :welcome, + group: :pleroma, + key: :welcome, type: :group, description: "Welcome messages settings", children: [ %{ - group: :direct_message, - type: :group, + key: :direct_message, + type: :keyword, descpiption: "Direct message settings", children: [ %{ key: :enabled, type: :boolean, - description: "Enables sends direct message for new user after registration" + description: "Enables sending a direct message to newly registered users" }, %{ key: :message, type: :string, description: - "A message that will be sent to a newly registered users as a direct message", + "A message that will be sent to newly registered users", suggestions: [ "Hi, @username! Welcome on board!" ] @@ -990,7 +991,7 @@ config :pleroma, :config_description, [ %{ key: :sender_nickname, type: :string, - description: "The nickname of the local user that sends the welcome message", + description: "The nickname of the local user that sends a welcome message", suggestions: [ "lain" ] @@ -998,20 +999,20 @@ config :pleroma, :config_description, [ ] }, %{ - group: :chat_message, - type: :group, + key: :chat_message, + type: :keyword, descpiption: "Chat message settings", children: [ %{ key: :enabled, type: :boolean, - description: "Enables sends chat message for new user after registration" + description: "Enables sending a chat message to newly registered users" }, %{ key: :message, type: :string, description: - "A message that will be sent to a newly registered users as a chat message", + "A message that will be sent to newly registered users as a chat message", suggestions: [ "Hello, welcome on board!" ] @@ -1019,7 +1020,7 @@ config :pleroma, :config_description, [ %{ key: :sender_nickname, type: :string, - description: "The nickname of the local user that sends the welcome message", + description: "The nickname of the local user that sends a welcome chat message", suggestions: [ "lain" ] @@ -1027,20 +1028,20 @@ config :pleroma, :config_description, [ ] }, %{ - group: :email, - type: :group, + key: :email, + type: :keyword, descpiption: "Email message settings", children: [ %{ key: :enabled, type: :boolean, - description: "Enables sends direct message for new user after registration" + description: "Enables sending an email to newly registered users" }, %{ key: :sender, type: [:string, :tuple], description: - "The email address or tuple with `{nickname, email}` that will use as sender to the welcome email.", + "Email address and/or nickname that will be used to send the welcome email.", suggestions: [ {"Pleroma App", "welcome@pleroma.app"} ] @@ -1049,21 +1050,21 @@ config :pleroma, :config_description, [ key: :subject, type: :string, description: - "The subject of welcome email. Can be use EEX template with `user` and `instance_name` variables.", + "Subject of the welcome email. EEX template with user and instance_name variables can be used.", suggestions: ["Welcome to <%= instance_name%>"] }, %{ key: :html, type: :string, description: - "The html content of welcome email. Can be use EEX template with `user` and `instance_name` variables.", + "HTML content of the welcome email. EEX template with user and instance_name variables can be used.", suggestions: ["

Hello <%= user.name%>. Welcome to <%= instance_name%>

"] }, %{ key: :text, type: :string, description: - "The text content of welcome email. Can be use EEX template with `user` and `instance_name` variables.", + "Text content of the welcome email. EEX template with user and instance_name variables can be used.", suggestions: ["Hello <%= user.name%>. \n Welcome to <%= instance_name%>\n"] } ] From 63b1ca6a0766772edb2affc65c42e2dad96c0de4 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Tue, 4 Aug 2020 02:21:25 +0300 Subject: [PATCH 3/6] Add label to :restrict_unauthenticated setting, fix typos --- config/description.exs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/config/description.exs b/config/description.exs index a947c8f3f..9c8e330bf 100644 --- a/config/description.exs +++ b/config/description.exs @@ -3293,13 +3293,13 @@ config :pleroma, :config_description, [ group: :pleroma, key: :connections_pool, type: :group, - description: "Advanced settings for `gun` connections pool", + description: "Advanced settings for `Gun` connections pool", children: [ %{ key: :connection_acquisition_wait, type: :integer, description: - "Timeout to acquire a connection from pool.The total max time is this value multiplied by the number of retries. Default: 250ms.", + "Timeout to acquire a connection from pool. The total max time is this value multiplied by the number of retries. Default: 250ms.", suggestions: [250] }, %{ @@ -3334,7 +3334,7 @@ config :pleroma, :config_description, [ group: :pleroma, key: :pools, type: :group, - description: "Advanced settings for `gun` workers pools", + description: "Advanced settings for `Gun` workers pools", children: Enum.map([:federation, :media, :upload, :default], fn pool_name -> %{ @@ -3363,7 +3363,7 @@ config :pleroma, :config_description, [ group: :pleroma, key: :hackney_pools, type: :group, - description: "Advanced settings for `hackney` connections pools", + description: "Advanced settings for `Hackney` connections pools", children: [ %{ key: :federation, @@ -3427,6 +3427,7 @@ config :pleroma, :config_description, [ %{ group: :pleroma, key: :restrict_unauthenticated, + label: "Restrict Unauthenticated", type: :group, description: "Disallow viewing timelines, user profiles and statuses for unauthenticated users.", From 8bb54415470852f95967bc75fb8917db78eb0fbd Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Tue, 4 Aug 2020 15:10:44 +0300 Subject: [PATCH 4/6] Update descriptions in :frontends group --- config/description.exs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config/description.exs b/config/description.exs index 9c8e330bf..7da01b175 100644 --- a/config/description.exs +++ b/config/description.exs @@ -3550,13 +3550,15 @@ config :pleroma, :config_description, [ children: [ %{ key: "name", + label: "Name", type: :string, - description: "Name of the installed primary frontend" + description: "Name of the installed primary frontend. Valid config must include both `Name` and `Reference` values." }, %{ key: "ref", + label: "Reference", type: :string, - description: "reference of the installed primary frontend to be used" + description: "Reference of the installed primary frontend to be used. Valid config must include both `Name` and `Reference` values." } ] } From 6e6276b4f8a7a46c6038480f6a842339c5214d1c Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Fri, 7 Aug 2020 09:47:05 +0300 Subject: [PATCH 5/6] added test --- config/description.exs | 9 +-- .../controllers/config_controller_test.exs | 69 +++++++++++++++++++ 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/config/description.exs b/config/description.exs index 7da01b175..ac43bc814 100644 --- a/config/description.exs +++ b/config/description.exs @@ -982,8 +982,7 @@ config :pleroma, :config_description, [ %{ key: :message, type: :string, - description: - "A message that will be sent to newly registered users", + description: "A message that will be sent to newly registered users", suggestions: [ "Hi, @username! Welcome on board!" ] @@ -3552,13 +3551,15 @@ config :pleroma, :config_description, [ key: "name", label: "Name", type: :string, - description: "Name of the installed primary frontend. Valid config must include both `Name` and `Reference` values." + description: + "Name of the installed primary frontend. Valid config must include both `Name` and `Reference` values." }, %{ key: "ref", label: "Reference", type: :string, - description: "Reference of the installed primary frontend to be used. Valid config must include both `Name` and `Reference` values." + description: + "Reference of the installed primary frontend to be used. Valid config must include both `Name` and `Reference` values." } ] } diff --git a/test/web/admin_api/controllers/config_controller_test.exs b/test/web/admin_api/controllers/config_controller_test.exs index 61bc9fd39..4e897455f 100644 --- a/test/web/admin_api/controllers/config_controller_test.exs +++ b/test/web/admin_api/controllers/config_controller_test.exs @@ -1342,6 +1342,75 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do args: ["auto-orient", "strip", {"implode", "1"}, {"resize", "3840x1080>"}] ] end + + test "enables the welcome messages", %{conn: conn} do + clear_config([:welcome]) + + params = %{ + "group" => ":pleroma", + "key" => ":welcome", + "value" => [ + %{ + "tuple" => [ + ":direct_message", + [ + %{"tuple" => [":enabled", true]}, + %{"tuple" => [":message", "Welcome to Pleroma!"]}, + %{"tuple" => [":sender_nickname", "pleroma"]} + ] + ] + }, + %{ + "tuple" => [ + ":chat_message", + [ + %{"tuple" => [":enabled", true]}, + %{"tuple" => [":message", "Welcome to Pleroma!"]}, + %{"tuple" => [":sender_nickname", "pleroma"]} + ] + ] + }, + %{ + "tuple" => [ + ":email", + [ + %{"tuple" => [":enabled", true]}, + %{"tuple" => [":sender", %{"tuple" => ["pleroma@dev.dev", "Pleroma"]}]}, + %{"tuple" => [":subject", "Welcome to <%= instance_name %>!"]}, + %{"tuple" => [":html", "Welcome to <%= instance_name %>!"]}, + %{"tuple" => [":text", "Welcome to <%= instance_name %>!"]} + ] + ] + } + ] + } + + refute Pleroma.User.WelcomeEmail.enabled?() + refute Pleroma.User.WelcomeMessage.enabled?() + refute Pleroma.User.WelcomeChatMessage.enabled?() + + res = + assert conn + |> put_req_header("content-type", "application/json") + |> post("/api/pleroma/admin/config", %{"configs" => [params]}) + |> json_response_and_validate_schema(200) + + assert Pleroma.User.WelcomeEmail.enabled?() + assert Pleroma.User.WelcomeMessage.enabled?() + assert Pleroma.User.WelcomeChatMessage.enabled?() + + assert res == %{ + "configs" => [ + %{ + "db" => [":direct_message", ":chat_message", ":email"], + "group" => ":pleroma", + "key" => ":welcome", + "value" => params["value"] + } + ], + "need_reboot" => false + } + end end describe "GET /api/pleroma/admin/config/descriptions" do From 8e1f7a3eff05a43f59f15dc6fa0483713e221fa7 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Fri, 7 Aug 2020 21:04:13 +0300 Subject: [PATCH 6/6] Add new `image` type to settings whose values are image urls --- config/description.exs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/config/description.exs b/config/description.exs index 7da01b175..e2f78e77d 100644 --- a/config/description.exs +++ b/config/description.exs @@ -951,7 +951,7 @@ config :pleroma, :config_description, [ }, %{ key: :instance_thumbnail, - type: :string, + type: {:string, :image}, description: "The instance thumbnail can be any image that represents your instance and is used by some apps or services when they display information about your instance.", suggestions: ["/instance/thumbnail.jpeg"] @@ -1237,7 +1237,7 @@ config :pleroma, :config_description, [ }, %{ key: :background, - type: :string, + type: {:string, :image}, description: "URL of the background, unless viewing a user profile with a background that is set", suggestions: ["/images/city.jpg"] @@ -1294,7 +1294,7 @@ config :pleroma, :config_description, [ }, %{ key: :logo, - type: :string, + type: {:string, :image}, description: "URL of the logo, defaults to Pleroma's logo", suggestions: ["/static/logo.png"] }, @@ -1326,7 +1326,7 @@ config :pleroma, :config_description, [ %{ key: :nsfwCensorImage, label: "NSFW Censor Image", - type: :string, + type: {:string, :image}, description: "URL of the image to use for hiding NSFW media attachments in the timeline", suggestions: ["/static/img/nsfw.74818f9.png"] @@ -1452,7 +1452,7 @@ config :pleroma, :config_description, [ }, %{ key: :default_user_avatar, - type: :string, + type: {:string, :image}, description: "URL of the default user avatar", suggestions: ["/images/avi.png"] } @@ -2643,7 +2643,7 @@ config :pleroma, :config_description, [ children: [ %{ key: :logo, - type: :string, + type: {:string, :image}, description: "A path to a custom logo. Set it to `nil` to use the default Pleroma logo.", suggestions: ["some/path/logo.png"] }, @@ -3552,13 +3552,15 @@ config :pleroma, :config_description, [ key: "name", label: "Name", type: :string, - description: "Name of the installed primary frontend. Valid config must include both `Name` and `Reference` values." + description: + "Name of the installed primary frontend. Valid config must include both `Name` and `Reference` values." }, %{ key: "ref", label: "Reference", type: :string, - description: "Reference of the installed primary frontend to be used. Valid config must include both `Name` and `Reference` values." + description: + "Reference of the installed primary frontend to be used. Valid config must include both `Name` and `Reference` values." } ] }