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() | [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.
37 with :ok <- check_hellthread_threshold(),
38 :ok <- check_old_mrf_config(),
39 :ok <- check_media_proxy_whitelist_config(),
40 :ok <- check_welcome_message_config(),
41 :ok <- check_gun_pool_options(),
42 :ok <- check_activity_expiration_config(),
43 :ok <- check_remote_ip_plug_name() do
51 def check_welcome_message_config do
52 instance_config = Pleroma.Config.get([:instance])
55 Keyword.has_key?(instance_config, :welcome_user_nickname) or
56 Keyword.has_key?(instance_config, :welcome_message)
60 !!!DEPRECATION WARNING!!!
61 Your config is using the old namespace for Welcome messages configuration. You need to convert to the new namespace. e.g.,
62 \n* `config :pleroma, :instance, welcome_user_nickname` and `config :pleroma, :instance, welcome_message` are now equal to:
63 \n* `config :pleroma, :welcome, direct_message: [enabled: true, sender_nickname: "NICKNAME", message: "Your welcome message"]`"
72 def check_old_mrf_config do
74 !!!DEPRECATION WARNING!!!
75 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:
78 move_namespace_and_warn(@mrf_config_map, warning_preface)
81 @spec move_namespace_and_warn([config_map()], String.t()) :: :ok | nil
82 def move_namespace_and_warn(config_map, warning_preface) do
84 Enum.reduce(config_map, "", fn
85 {old, new, err_msg}, acc ->
86 old_config = Config.get(old)
89 Config.put(new, old_config)
99 Logger.warn(warning_preface <> warning)
104 @spec check_media_proxy_whitelist_config() :: :ok | nil
105 def check_media_proxy_whitelist_config do
106 whitelist = Config.get([:media_proxy, :whitelist])
108 if Enum.any?(whitelist, &(not String.starts_with?(&1, "http"))) do
110 !!!DEPRECATION WARNING!!!
111 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 `config :pleroma, :connections_pool, await_up_timeout`. Please change to `config :pleroma, :connections_pool, connect_timeout` to ensure compatibility with future releases.
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)
165 @spec check_activity_expiration_config() :: :ok | nil
166 def check_activity_expiration_config do
167 warning_preface = """
168 !!!DEPRECATION WARNING!!!
169 Your config is using old namespace for activity expiration configuration. Setting should work for now, but you are advised to change to new namespace to prevent possible issues later:
172 move_namespace_and_warn(
174 {Pleroma.ActivityExpiration, Pleroma.Workers.PurgeExpiredActivity,
175 "\n* `config :pleroma, Pleroma.ActivityExpiration` is now `config :pleroma, Pleroma.Workers.PurgeExpiredActivity`"}
181 @spec check_remote_ip_plug_name() :: :ok | nil
182 def check_remote_ip_plug_name do
183 warning_preface = """
184 !!!DEPRECATION WARNING!!!
185 Your config is using old namespace for RemoteIp Plug. Setting should work for now, but you are advised to change to new namespace to prevent possible issues later:
188 move_namespace_and_warn(
190 {Pleroma.Plugs.RemoteIp, Pleroma.Web.Plugs.RemoteIp,
191 "\n* `config :pleroma, Pleroma.Plugs.RemoteIp` is now `config :pleroma, Pleroma.Web.Plugs.RemoteIp`"}