From 31ce8a37304e24381b26d678dfbbc7b7a6b1ba35 Mon Sep 17 00:00:00 2001
From: Mark Felder <feld@feld.me>
Date: Thu, 1 Apr 2021 10:09:32 -0500
Subject: [PATCH 01/10] Fix CHANGELOG entry meant for next release

---
 CHANGELOG.md | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 43f2bb638..6c45cad85 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,8 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 
 ## Unreleased
 
+### Changed
+
 - The `application` metadata returned with statuses is no longer hardcoded. Apps that want to display these details will now have valid data for new posts after this change.
 
+### Added
+
+- MRF (`FollowBotPolicy`): New MRF Policy which makes a designated local Bot account attempt to follow all users in public Notes received by your instance. Users who require approving follower requests or have #nobot in their profile are excluded.
+
 ## Unreleased (Patch)
 
 ### Fixed
@@ -75,7 +81,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - Ability to define custom HTTP headers per each frontend
 - MRF (`NoEmptyPolicy`): New MRF Policy which will deny empty statuses or statuses of only mentions from being created by local users
 - New users will receive a simple email confirming their registration if no other emails will be dispatched. (e.g., Welcome, Confirmation, or Approval Required)
-- MRF (`FollowBotPolicy`): New MRF Policy which makes a designated local Bot account attempt to follow all users in public Notes received by your instance. Users who require approving follower requests or have #nobot in their profile are excluded.
 
 <details>
   <summary>API Changes</summary>

From 0feafcc20cec168258f592b9d509c1e6ccc8efba Mon Sep 17 00:00:00 2001
From: Mark Felder <feld@feld.me>
Date: Fri, 9 Apr 2021 10:30:27 -0500
Subject: [PATCH 02/10] Use URI.merge to prevent concatenating two canonical
 URLs when a custom instance thumbnail was uploaded via AdminFE

---
 lib/pleroma/web/mastodon_api/views/instance_view.ex | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex
index 73205fb6d..dac68d8e6 100644
--- a/lib/pleroma/web/mastodon_api/views/instance_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/instance_view.ex
@@ -23,7 +23,8 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
         streaming_api: Pleroma.Web.Endpoint.websocket_url()
       },
       stats: Pleroma.Stats.get_stats(),
-      thumbnail: Pleroma.Web.base_url() <> Keyword.get(instance, :instance_thumbnail),
+      thumbnail:
+        URI.merge(Pleroma.Web.base_url(), Keyword.get(instance, :instance_thumbnail)) |> to_string,
       languages: ["en"],
       registrations: Keyword.get(instance, :registrations_open),
       approval_required: Keyword.get(instance, :account_approval_required),

From 9fbcdc15b11dedf27bc5c78d09048ba354906c16 Mon Sep 17 00:00:00 2001
From: Mark Felder <feld@feld.me>
Date: Tue, 13 Apr 2021 10:52:53 -0500
Subject: [PATCH 03/10] Validate custom instance thumbnail set via AdminAPI
 produces correct URL

---
 CHANGELOG.md                                  |  1 +
 .../controllers/config_controller_test.exs    | 42 +++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6c45cad85..1553245e5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 ### Fixed
 
 - Try to save exported ConfigDB settings (migrate_from_db) in the system temp directory if default location is not writable.
+- Uploading custom instance thumbnail via AdminAPI/AdminFE generated invalid URL to the image
 
 ## [2.3.0] - 2020-03-01
 
diff --git a/test/pleroma/web/admin_api/controllers/config_controller_test.exs b/test/pleroma/web/admin_api/controllers/config_controller_test.exs
index 578a4c914..71151712e 100644
--- a/test/pleroma/web/admin_api/controllers/config_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/config_controller_test.exs
@@ -1410,6 +1410,48 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                "need_reboot" => false
              }
     end
+
+    test "custom instance thumbnail", %{conn: conn} do
+      clear_config([:instance])
+
+      params = %{
+        "group" => ":pleroma",
+        "key" => ":instance",
+        "value" => [
+          %{
+            "tuple" => [
+              ":instance_thumbnail",
+              "https://example.com/media/new_thumbnail.jpg"
+            ]
+          }
+        ]
+      }
+
+      res =
+        assert conn
+               |> put_req_header("content-type", "application/json")
+               |> post("/api/pleroma/admin/config", %{"configs" => [params]})
+               |> json_response_and_validate_schema(200)
+
+      assert res == %{
+               "configs" => [
+                 %{
+                   "db" => [":instance_thumbnail"],
+                   "group" => ":pleroma",
+                   "key" => ":instance",
+                   "value" => params["value"]
+                 }
+               ],
+               "need_reboot" => false
+             }
+
+      assert res =
+               conn
+               |> get("/api/v1/instance")
+               |> json_response_and_validate_schema(200)
+
+      assert res = %{"thumbnail" => "https://example.com/media/new_thumbnail.jpg"}
+    end
   end
 
   describe "GET /api/pleroma/admin/config/descriptions" do

From cdd271b0655799e65bb9a13016dc82441ec34f87 Mon Sep 17 00:00:00 2001
From: Mark Felder <feld@feld.me>
Date: Tue, 13 Apr 2021 10:55:54 -0500
Subject: [PATCH 04/10] Fix assignment / assertion

---
 .../web/admin_api/controllers/config_controller_test.exs      | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/test/pleroma/web/admin_api/controllers/config_controller_test.exs b/test/pleroma/web/admin_api/controllers/config_controller_test.exs
index 71151712e..c4d07d61c 100644
--- a/test/pleroma/web/admin_api/controllers/config_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/config_controller_test.exs
@@ -1445,8 +1445,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                "need_reboot" => false
              }
 
-      assert res =
-               conn
+      _res =
+        assert conn
                |> get("/api/v1/instance")
                |> json_response_and_validate_schema(200)
 

From 905efc57e9f2a96519bf1ac84b56f88d1818cca3 Mon Sep 17 00:00:00 2001
From: Mark Felder <feld@feld.me>
Date: Tue, 13 Apr 2021 11:15:52 -0500
Subject: [PATCH 05/10] Initial test validating the AdminAPI issue

---
 .../controllers/config_controller_test.exs    | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/test/pleroma/web/admin_api/controllers/config_controller_test.exs b/test/pleroma/web/admin_api/controllers/config_controller_test.exs
index c4d07d61c..d26fd3150 100644
--- a/test/pleroma/web/admin_api/controllers/config_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/config_controller_test.exs
@@ -1452,6 +1452,41 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
 
       assert res = %{"thumbnail" => "https://example.com/media/new_thumbnail.jpg"}
     end
+
+    test "Concurrent Limiter", %{conn: conn} do
+      clear_config([ConcurrentLimiter])
+
+      params = %{
+        "group" => ":pleroma",
+        "key" => "ConcurrentLimiter",
+        "value" => [
+          %{
+            "tuple" => [
+              "Pleroma.Web.RichMedia.Helpers",
+              [
+                %{"tuple" => [":max_running", 6]},
+                %{"tuple" => [":max_waiting", 6]}
+              ]
+            ]
+          },
+          %{
+            "tuple" => [
+              "Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy",
+              [
+                %{"tuple" => [":max_running", 7]},
+                %{"tuple" => [":max_waiting", 7]}
+              ]
+            ]
+          }
+        ]
+      }
+
+      _res =
+        assert conn
+               |> put_req_header("content-type", "application/json")
+               |> post("/api/pleroma/admin/config", %{"configs" => [params]})
+               |> json_response_and_validate_schema(200)
+    end
   end
 
   describe "GET /api/pleroma/admin/config/descriptions" do

From ee53ad4d7705328a5a583680c6f551c4c3bf2302 Mon Sep 17 00:00:00 2001
From: Mark Felder <feld@feld.me>
Date: Tue, 13 Apr 2021 12:09:18 -0500
Subject: [PATCH 06/10] Add ConcurrentLimiter to module_name?/1 and apply
 string_to_elixir_types/1 to search_opts keys during update_or_create/1

---
 lib/pleroma/config_db.ex | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/pleroma/config_db.ex b/lib/pleroma/config_db.ex
index b874e0e37..03905c06b 100644
--- a/lib/pleroma/config_db.ex
+++ b/lib/pleroma/config_db.ex
@@ -141,7 +141,9 @@ defmodule Pleroma.ConfigDB do
   @spec update_or_create(map()) :: {:ok, ConfigDB.t()} | {:error, Changeset.t()}
   def update_or_create(params) do
     params = Map.put(params, :value, to_elixir_types(params[:value]))
-    search_opts = Map.take(params, [:group, :key])
+
+    search_opts =
+      Map.take(params, [:group, :key]) |> Map.update!(:key, &string_to_elixir_types(&1))
 
     with %ConfigDB{} = config <- ConfigDB.get_by_params(search_opts),
          {_, true, config} <- {:partial_update, can_be_partially_updated?(config), config},
@@ -387,6 +389,6 @@ defmodule Pleroma.ConfigDB do
   @spec module_name?(String.t()) :: boolean()
   def module_name?(string) do
     Regex.match?(~r/^(Pleroma|Phoenix|Tesla|Quack|Ueberauth|Swoosh)\./, string) or
-      string in ["Oban", "Ueberauth", "ExSyslogger"]
+      string in ["Oban", "Ueberauth", "ExSyslogger", "ConcurrentLimiter"]
   end
 end

From 861f1928526930eeb78f79c4840c69cee5c2f215 Mon Sep 17 00:00:00 2001
From: Mark Felder <feld@feld.me>
Date: Tue, 13 Apr 2021 14:39:44 -0500
Subject: [PATCH 07/10] Document fixed ability to save ConcurrentLimiter
 settings in ConfigDB

---
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1553245e5..6e13b3875 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 
 - Try to save exported ConfigDB settings (migrate_from_db) in the system temp directory if default location is not writable.
 - Uploading custom instance thumbnail via AdminAPI/AdminFE generated invalid URL to the image
+- Applying ConcurrentLimiter settings via AdminAPI
 
 ## [2.3.0] - 2020-03-01
 

From c3b8c77967b0c42f93286f864236b7d6f1471c13 Mon Sep 17 00:00:00 2001
From: Mark Felder <feld@feld.me>
Date: Tue, 13 Apr 2021 14:25:15 -0500
Subject: [PATCH 08/10] Improve string_to_elixir_types/1 with guards

---
 lib/pleroma/config_db.ex | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/pleroma/config_db.ex b/lib/pleroma/config_db.ex
index 03905c06b..eeeb026c1 100644
--- a/lib/pleroma/config_db.ex
+++ b/lib/pleroma/config_db.ex
@@ -327,7 +327,7 @@ defmodule Pleroma.ConfigDB do
 
   @spec string_to_elixir_types(String.t()) ::
           atom() | Regex.t() | module() | String.t() | no_return()
-  def string_to_elixir_types("~r" <> _pattern = regex) do
+  def string_to_elixir_types("~r" <> _pattern = regex) when is_binary(regex) do
     pattern =
       ~r/^~r(?'delimiter'[\/|"'([{<]{1})(?'pattern'.+)[\/|"')\]}>]{1}(?'modifier'[uismxfU]*)/u
 
@@ -341,9 +341,9 @@ defmodule Pleroma.ConfigDB do
     end
   end
 
-  def string_to_elixir_types(":" <> atom), do: String.to_atom(atom)
+  def string_to_elixir_types(":" <> atom) when is_binary(atom), do: String.to_atom(atom)
 
-  def string_to_elixir_types(value) do
+  def string_to_elixir_types(value) when is_binary(value) do
     if module_name?(value) do
       String.to_existing_atom("Elixir." <> value)
     else
@@ -351,6 +351,8 @@ defmodule Pleroma.ConfigDB do
     end
   end
 
+  def string_to_elixir_types(value) when is_atom(value), do: value
+
   defp parse_host("localhost"), do: :localhost
 
   defp parse_host(host) do

From f95b52255b2d7373a3e0bf4adff81f83c080b2ef Mon Sep 17 00:00:00 2001
From: Mark Felder <feld@feld.me>
Date: Wed, 14 Apr 2021 09:39:57 -0500
Subject: [PATCH 09/10] Revert guards on string_to_elixir_types/1, remove
 unnecessary assignment in test

---
 lib/pleroma/config_db.ex                             | 12 ++++--------
 .../admin_api/controllers/config_controller_test.exs |  9 ++++-----
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/lib/pleroma/config_db.ex b/lib/pleroma/config_db.ex
index eeeb026c1..cb57673e3 100644
--- a/lib/pleroma/config_db.ex
+++ b/lib/pleroma/config_db.ex
@@ -141,9 +141,7 @@ defmodule Pleroma.ConfigDB do
   @spec update_or_create(map()) :: {:ok, ConfigDB.t()} | {:error, Changeset.t()}
   def update_or_create(params) do
     params = Map.put(params, :value, to_elixir_types(params[:value]))
-
-    search_opts =
-      Map.take(params, [:group, :key]) |> Map.update!(:key, &string_to_elixir_types(&1))
+    search_opts = Map.take(params, [:group, :key])
 
     with %ConfigDB{} = config <- ConfigDB.get_by_params(search_opts),
          {_, true, config} <- {:partial_update, can_be_partially_updated?(config), config},
@@ -327,7 +325,7 @@ defmodule Pleroma.ConfigDB do
 
   @spec string_to_elixir_types(String.t()) ::
           atom() | Regex.t() | module() | String.t() | no_return()
-  def string_to_elixir_types("~r" <> _pattern = regex) when is_binary(regex) do
+  def string_to_elixir_types("~r" <> _pattern = regex) do
     pattern =
       ~r/^~r(?'delimiter'[\/|"'([{<]{1})(?'pattern'.+)[\/|"')\]}>]{1}(?'modifier'[uismxfU]*)/u
 
@@ -341,9 +339,9 @@ defmodule Pleroma.ConfigDB do
     end
   end
 
-  def string_to_elixir_types(":" <> atom) when is_binary(atom), do: String.to_atom(atom)
+  def string_to_elixir_types(":" <> atom), do: String.to_atom(atom)
 
-  def string_to_elixir_types(value) when is_binary(value) do
+  def string_to_elixir_types(value) do
     if module_name?(value) do
       String.to_existing_atom("Elixir." <> value)
     else
@@ -351,8 +349,6 @@ defmodule Pleroma.ConfigDB do
     end
   end
 
-  def string_to_elixir_types(value) when is_atom(value), do: value
-
   defp parse_host("localhost"), do: :localhost
 
   defp parse_host(host) do
diff --git a/test/pleroma/web/admin_api/controllers/config_controller_test.exs b/test/pleroma/web/admin_api/controllers/config_controller_test.exs
index d26fd3150..c39c1b1e1 100644
--- a/test/pleroma/web/admin_api/controllers/config_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/config_controller_test.exs
@@ -1481,11 +1481,10 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
         ]
       }
 
-      _res =
-        assert conn
-               |> put_req_header("content-type", "application/json")
-               |> post("/api/pleroma/admin/config", %{"configs" => [params]})
-               |> json_response_and_validate_schema(200)
+      assert conn
+             |> put_req_header("content-type", "application/json")
+             |> post("/api/pleroma/admin/config", %{"configs" => [params]})
+             |> json_response_and_validate_schema(200)
     end
   end
 

From d9fce0133ef3444ef7d09ae7e2760583540d1cd2 Mon Sep 17 00:00:00 2001
From: Sean King <seanking2919@protonmail.com>
Date: Wed, 14 Apr 2021 14:01:33 -0600
Subject: [PATCH 10/10] Fix Mastodon interface link

---
 docs/index.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/index.md b/docs/index.md
index 1a90d0a8d..80c5d2631 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -20,7 +20,7 @@ The default front-end used by Pleroma is Pleroma-FE. You can find more informati
 
 ### Mastodon interface
 If the Pleroma interface isn't your thing, or you're just trying something new but you want to keep using the familiar Mastodon interface, we got that too!
-Just add a "/web" after your instance url (e.g. <https://pleroma.soycaf.com/web>) and you'll end on the Mastodon web interface, but with a Pleroma backend! MAGIC!
+Just add a "/web" after your instance url (e.g. <https://pleroma.soykaf.com/web>) and you'll end on the Mastodon web interface, but with a Pleroma backend! MAGIC!
 The Mastodon interface is from the Glitch-soc fork. For more information on the Mastodon interface you can check the [Mastodon](https://docs.joinmastodon.org/) and [Glitch-soc](https://glitch-soc.github.io/docs/) documentation.
 
 Remember, what you see is only the frontend part of Mastodon, the backend is still Pleroma.