fix(migration): leave ConfigDB upload configs without filters alone
Keyword.update/4 added filters: [] to a Pleroma.Upload ConfigDB entry without a :filters key, which would hide the filters from the config file, GPS stripping included. Only rewrite lists that change.
This commit is contained in:
parent
d1deb9da45
commit
ce8b2276c2
2 changed files with 22 additions and 13 deletions
|
|
@ -22,20 +22,20 @@ defmodule Pleroma.Repo.Migrations.UploadFilterExiftoolToExif do
|
|||
|
||||
def down, do: rename_filters(@down)
|
||||
|
||||
# Only touch configs that list filters: adding an empty list would hide the
|
||||
# filters from the config file.
|
||||
defp rename_filters(renames) do
|
||||
case ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}) do
|
||||
%{value: value} ->
|
||||
new_value =
|
||||
Keyword.update(value, :filters, [], fn filters ->
|
||||
filters
|
||||
|> Enum.map(&Map.get(renames, &1, &1))
|
||||
|> Enum.uniq()
|
||||
end)
|
||||
|
||||
ConfigDB.update_or_create(%{group: :pleroma, key: Pleroma.Upload, value: new_value})
|
||||
|
||||
_ ->
|
||||
nil
|
||||
with %{value: value} <- ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}),
|
||||
filters when is_list(filters) <- value[:filters],
|
||||
new_filters when new_filters != filters <-
|
||||
filters |> Enum.map(&Map.get(renames, &1, &1)) |> Enum.uniq() do
|
||||
ConfigDB.update_or_create(%{
|
||||
group: :pleroma,
|
||||
key: Pleroma.Upload,
|
||||
value: Keyword.put(value, :filters, new_filters)
|
||||
})
|
||||
else
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -61,4 +61,13 @@ defmodule Pleroma.Repo.Migrations.UploadFilterExiftoolToExifTest do
|
|||
assert migration.up() == nil
|
||||
assert ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}) == nil
|
||||
end
|
||||
|
||||
test "up/0 does not add filters to a database config without them", %{migration: migration} do
|
||||
insert(:config, group: :pleroma, key: Pleroma.Upload, value: [uploader: Pleroma.Uploaders.S3])
|
||||
|
||||
migration.up()
|
||||
|
||||
value = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}).value
|
||||
assert value == [uploader: Pleroma.Uploaders.S3]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue