Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85595592
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/config/config.exs b/config/config.exs
index 80183a3d9..e6a4eb3e6 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -966,6 +966,10 @@ config :pleroma, Pleroma.Search.QdrantSearch,
vectors: %{size: 384, distance: "Cosine"}
}
+config :pleroma, :database_config_blacklist, [
+ {:pleroma, :logger}
+]
+
config :pleroma, :database_config_whitelist, [
{:pleroma},
{:cors_plug},
diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex
index c5f2e9b0a..a389252ac 100644
--- a/lib/mix/tasks/pleroma/config.ex
+++ b/lib/mix/tasks/pleroma/config.ex
@@ -289,6 +289,52 @@ defmodule Mix.Tasks.Pleroma.Config do
end
end
+ # Removes blacklisted configuration sections
+ def run(["filter_blacklisted" | rest]) do
+ {options, [], []} =
+ OptionParser.parse(
+ rest,
+ strict: [force: :boolean],
+ aliases: [f: :force]
+ )
+
+ force = Keyword.get(options, :force, false)
+
+ start_pleroma()
+
+ blacklisted_configs = Pleroma.Config.get(:database_config_blacklist)
+
+ if blacklisted_configs in [nil, false] do
+ shell_error("No unwanted settings in ConfigDB. No changes made.")
+ else
+ blacklisted_keys =
+ blacklisted_configs
+ |> Enum.filter(fn
+ {_group, _key} -> true
+ _ -> false
+ end)
+
+ filtered =
+ from(c in ConfigDB)
+ |> Repo.all()
+ |> Enum.filter(&blacklisted?(&1, blacklisted_keys))
+
+ if not Enum.empty?(filtered) do
+ shell_info("The following settings will be removed from ConfigDB:\n")
+ Enum.each(filtered, &dump(&1))
+
+ if force or shell_prompt("Are you sure you want to continue?", "n") in ~w(Yn Y y) do
+ filtered_ids = Enum.map(filtered, fn %{id: id} -> id end)
+
+ Repo.delete_all(from(c in ConfigDB, where: c.id in ^filtered_ids))
+ else
+ shell_error("No changes made.")
+ end
+ else
+ shell_error("No unwanted settings in ConfigDB. No changes made.")
+ end
+ end
+ end
@spec migrate_to_db(Path.t() | nil) :: any()
def migrate_to_db(file_path \\ nil) do
with :ok <- Pleroma.Config.DeprecationWarnings.warn() do
@@ -494,4 +540,8 @@ defmodule Mix.Tasks.Pleroma.Config do
not Enum.member?(whitelisted_groups, group) and
not Enum.member?(whitelisted_keys, {group, key})
end
+
+ defp blacklisted?(%{group: group, key: key}, blacklisted_keys) do
+ Enum.member?(blacklisted_keys, {group, key})
+ end
end
diff --git a/test/mix/tasks/pleroma/config_test.exs b/test/mix/tasks/pleroma/config_test.exs
index f672d8c13..3ae6e7f16 100644
--- a/test/mix/tasks/pleroma/config_test.exs
+++ b/test/mix/tasks/pleroma/config_test.exs
@@ -369,5 +369,40 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
MixTask.run(["filter_whitelisted", "--force"])
assert config_records() == existing
end
+
+ test "filters blacklisted settings" do
+ clear_config(:database_config_whitelist, [{:pleroma}])
+ clear_config(:database_config_blacklist, [
+ {:pleroma, :logger}
+ ])
+
+ insert_config_record(:pleroma, :logger, backends: :console)
+ insert_config_record(:web_push_encryption, :vapid_details, a: 1)
+
+ MixTask.run(["filter_blacklisted", "--force"])
+
+ assert [
+ %ConfigDB{group: :pleroma, key: :instance},
+ %ConfigDB{group: :pleroma, key: Pleroma.Captcha},
+ %ConfigDB{group: :pleroma2, key: :key2},
+ %ConfigDB{group: :web_push_encryption, key: :vapid_details},
+ ] = config_records()
+ end
+
+ test "filter_blacklisted doesn't crash when blacklist is unset" do
+ clear_config(:database_config_blacklist, nil)
+
+ existing = config_records()
+ MixTask.run(["filter_blacklisted", "--force"])
+ assert config_records() == existing
+ end
+
+ test "filter_blacklisted doesn't crash when blacklist is disabled" do
+ clear_config(:database_config_blacklist, false)
+
+ existing = config_records()
+ MixTask.run(["filter_blacklisted", "--force"])
+ assert config_records() == existing
+ end
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jul 19, 2:34 PM (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1695297
Default Alt Text
(4 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment