logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

20201005124600_quarantained_policy_string_to_tuple.exs (1712B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Repo.Migrations.QuarantainedStringToTuple do
  5. use Ecto.Migration
  6. alias Pleroma.ConfigDB
  7. def up,
  8. do:
  9. ConfigDB.get_by_params(%{group: :pleroma, key: :instance})
  10. |> update_quarantined_instances_to_tuples
  11. def down,
  12. do:
  13. ConfigDB.get_by_params(%{group: :pleroma, key: :instance})
  14. |> update_quarantined_instances_to_strings
  15. defp update_quarantined_instances_to_tuples(%{value: settings}) do
  16. settings |> List.keyfind(:quarantined_instances, 0) |> update_to_tuples
  17. end
  18. defp update_quarantined_instances_to_tuples(nil), do: {:ok, nil}
  19. defp update_to_tuples({:quarantined_instances, instance_list}) do
  20. new_value =
  21. instance_list
  22. |> Enum.map(fn
  23. {v, r} -> {v, r}
  24. v -> {v, ""}
  25. end)
  26. ConfigDB.update_or_create(%{
  27. group: :pleroma,
  28. key: :instance,
  29. value: [quarantined_instances: new_value]
  30. })
  31. end
  32. defp update_to_tuples(nil), do: {:ok, nil}
  33. defp update_quarantined_instances_to_strings(%{value: settings}) do
  34. settings |> List.keyfind(:quarantined_instances, 0) |> update_to_strings
  35. end
  36. defp update_quarantined_instances_to_strings(nil), do: {:ok, nil}
  37. defp update_to_strings({:quarantined_instances, instance_list}) do
  38. new_value =
  39. instance_list
  40. |> Enum.map(fn
  41. {v, _} -> v
  42. v -> v
  43. end)
  44. ConfigDB.update_or_create(%{
  45. group: :pleroma,
  46. key: :instance,
  47. value: [quarantined_instances: new_value]
  48. })
  49. end
  50. defp update_to_strings(nil), do: {:ok, nil}
  51. end