1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Config.DeprecationWarnings do
11 @type config_namespace() :: [atom()]
12 @type config_map() :: {config_namespace(), config_namespace(), String.t()}
15 {[:instance, :rewrite_policy], [:mrf, :policies],
16 "\n* `config :pleroma, :instance, rewrite_policy` is now `config :pleroma, :mrf, policies`"},
17 {[:instance, :mrf_transparency], [:mrf, :transparency],
18 "\n* `config :pleroma, :instance, mrf_transparency` is now `config :pleroma, :mrf, transparency`"},
19 {[:instance, :mrf_transparency_exclusions], [:mrf, :transparency_exclusions],
20 "\n* `config :pleroma, :instance, mrf_transparency_exclusions` is now `config :pleroma, :mrf, transparency_exclusions`"}
23 def check_hellthread_threshold do
24 if Config.get([:mrf_hellthread, :threshold]) do
26 !!!DEPRECATION WARNING!!!
27 You are using the old configuration mechanism for the hellthread filter. Please check config.md.
32 def mrf_user_allowlist do
33 config = Config.get(:mrf_user_allowlist)
35 if config && Enum.any?(config, fn {k, _} -> is_atom(k) end) do
37 Enum.reduce(Config.get(:mrf_user_allowlist), Map.new(), fn {k, v}, acc ->
38 Map.put(acc, to_string(k), v)
41 Config.put(:mrf_user_allowlist, rewritten)
44 !!!DEPRECATION WARNING!!!
45 As of Pleroma 2.0.7, the `mrf_user_allowlist` setting changed of format.
46 Pleroma 2.1 will remove support for the old format. Please change your configuration to match this:
48 config :pleroma, :mrf_user_allowlist, #{inspect(rewritten, pretty: true)}
54 check_hellthread_threshold()
56 check_old_mrf_config()
57 check_media_proxy_whitelist_config()
58 check_welcome_message_config()
59 check_gun_pool_options()
62 def check_welcome_message_config do
63 instance_config = Pleroma.Config.get([:instance])
66 Keyword.has_key?(instance_config, :welcome_user_nickname) or
67 Keyword.has_key?(instance_config, :welcome_message)
71 !!!DEPRECATION WARNING!!!
72 Your config is using the old namespace for Welcome messages configuration. You need to change to the new namespace:
73 \n* `config :pleroma, :instance, welcome_user_nickname` is now `config :pleroma, :welcome, :direct_message, :sender_nickname`
74 \n* `config :pleroma, :instance, welcome_message` is now `config :pleroma, :welcome, :direct_message, :message`
79 def check_old_mrf_config do
81 !!!DEPRECATION WARNING!!!
82 Your config is using old namespaces for MRF configuration. They should work for now, but you are advised to change to new namespaces to prevent possible issues later:
85 move_namespace_and_warn(@mrf_config_map, warning_preface)
88 @spec move_namespace_and_warn([config_map()], String.t()) :: :ok | nil
89 def move_namespace_and_warn(config_map, warning_preface) do
91 Enum.reduce(config_map, "", fn
92 {old, new, err_msg}, acc ->
93 old_config = Config.get(old)
96 Config.put(new, old_config)
104 Logger.warn(warning_preface <> warning)
108 @spec check_media_proxy_whitelist_config() :: :ok | nil
109 def check_media_proxy_whitelist_config do
110 whitelist = Config.get([:media_proxy, :whitelist])
112 if Enum.any?(whitelist, &(not String.starts_with?(&1, "http"))) do
114 !!!DEPRECATION WARNING!!!
115 Your config is using old format (only domain) for MediaProxy whitelist option. Setting should work for now, but you are advised to change format to scheme with port to prevent possible issues later.
120 def check_gun_pool_options do
121 pool_config = Config.get(:connections_pool)
123 if timeout = pool_config[:await_up_timeout] do
125 !!!DEPRECATION WARNING!!!
126 Your config is using old setting name `await_up_timeout` instead of `connect_timeout`. Setting should work for now, but you are advised to change format to scheme with port to prevent possible issues later.
129 Config.put(:connections_pool, Keyword.put_new(pool_config, :connect_timeout, timeout))
132 pools_configs = Config.get(:pools)
134 warning_preface = """
135 !!!DEPRECATION WARNING!!!
136 Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings. Setting should work for now, but you are advised to change format to scheme with port to prevent possible issues later.
140 Enum.reduce(pools_configs, [], fn {pool_name, config}, acc ->
141 if timeout = config[:timeout] do
142 Keyword.put(acc, pool_name, Keyword.put_new(config, :recv_timeout, timeout))
148 if updated_config != [] do
152 |> Enum.map(fn pool_name ->
153 "\n* `:timeout` options in #{pool_name} pool is now `:recv_timeout`"
156 Logger.warn(Enum.join([warning_preface | pool_warnings]))
158 Config.put(:pools, updated_config)