Merge branch 'oban-overuse' into 'develop'
[akkoma] / lib / pleroma / config / deprecation_warnings.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Config.DeprecationWarnings do
6 alias Pleroma.Config
7
8 require Logger
9 alias Pleroma.Config
10
11 @type config_namespace() :: atom() | [atom()]
12 @type config_map() :: {config_namespace(), config_namespace(), String.t()}
13
14 @mrf_config_map [
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`"}
21 ]
22
23 def check_hellthread_threshold do
24 if Config.get([:mrf_hellthread, :threshold]) do
25 Logger.warn("""
26 !!!DEPRECATION WARNING!!!
27 You are using the old configuration mechanism for the hellthread filter. Please check config.md.
28 """)
29 end
30 end
31
32 def mrf_user_allowlist do
33 config = Config.get(:mrf_user_allowlist)
34
35 if config && Enum.any?(config, fn {k, _} -> is_atom(k) end) do
36 rewritten =
37 Enum.reduce(Config.get(:mrf_user_allowlist), Map.new(), fn {k, v}, acc ->
38 Map.put(acc, to_string(k), v)
39 end)
40
41 Config.put(:mrf_user_allowlist, rewritten)
42
43 Logger.error("""
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:
47
48 config :pleroma, :mrf_user_allowlist, #{inspect(rewritten, pretty: true)}
49 """)
50 end
51 end
52
53 def warn do
54 check_hellthread_threshold()
55 mrf_user_allowlist()
56 check_old_mrf_config()
57 check_media_proxy_whitelist_config()
58 check_welcome_message_config()
59 check_gun_pool_options()
60 check_activity_expiration_config()
61 end
62
63 def check_welcome_message_config do
64 instance_config = Pleroma.Config.get([:instance])
65
66 use_old_config =
67 Keyword.has_key?(instance_config, :welcome_user_nickname) or
68 Keyword.has_key?(instance_config, :welcome_message)
69
70 if use_old_config do
71 Logger.error("""
72 !!!DEPRECATION WARNING!!!
73 Your config is using the old namespace for Welcome messages configuration. You need to change to the new namespace:
74 \n* `config :pleroma, :instance, welcome_user_nickname` is now `config :pleroma, :welcome, :direct_message, :sender_nickname`
75 \n* `config :pleroma, :instance, welcome_message` is now `config :pleroma, :welcome, :direct_message, :message`
76 """)
77 end
78 end
79
80 def check_old_mrf_config do
81 warning_preface = """
82 !!!DEPRECATION WARNING!!!
83 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:
84 """
85
86 move_namespace_and_warn(@mrf_config_map, warning_preface)
87 end
88
89 @spec move_namespace_and_warn([config_map()], String.t()) :: :ok | nil
90 def move_namespace_and_warn(config_map, warning_preface) do
91 warning =
92 Enum.reduce(config_map, "", fn
93 {old, new, err_msg}, acc ->
94 old_config = Config.get(old)
95
96 if old_config do
97 Config.put(new, old_config)
98 acc <> err_msg
99 else
100 acc
101 end
102 end)
103
104 if warning != "" do
105 Logger.warn(warning_preface <> warning)
106 end
107 end
108
109 @spec check_media_proxy_whitelist_config() :: :ok | nil
110 def check_media_proxy_whitelist_config do
111 whitelist = Config.get([:media_proxy, :whitelist])
112
113 if Enum.any?(whitelist, &(not String.starts_with?(&1, "http"))) do
114 Logger.warn("""
115 !!!DEPRECATION WARNING!!!
116 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.
117 """)
118 end
119 end
120
121 def check_gun_pool_options do
122 pool_config = Config.get(:connections_pool)
123
124 if timeout = pool_config[:await_up_timeout] do
125 Logger.warn("""
126 !!!DEPRECATION WARNING!!!
127 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.
128 """)
129
130 Config.put(:connections_pool, Keyword.put_new(pool_config, :connect_timeout, timeout))
131 end
132
133 pools_configs = Config.get(:pools)
134
135 warning_preface = """
136 !!!DEPRECATION WARNING!!!
137 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.
138 """
139
140 updated_config =
141 Enum.reduce(pools_configs, [], fn {pool_name, config}, acc ->
142 if timeout = config[:timeout] do
143 Keyword.put(acc, pool_name, Keyword.put_new(config, :recv_timeout, timeout))
144 else
145 acc
146 end
147 end)
148
149 if updated_config != [] do
150 pool_warnings =
151 updated_config
152 |> Keyword.keys()
153 |> Enum.map(fn pool_name ->
154 "\n* `:timeout` options in #{pool_name} pool is now `:recv_timeout`"
155 end)
156
157 Logger.warn(Enum.join([warning_preface | pool_warnings]))
158
159 Config.put(:pools, updated_config)
160 end
161 end
162
163 @spec check_activity_expiration_config() :: :ok | nil
164 def check_activity_expiration_config do
165 warning_preface = """
166 !!!DEPRECATION WARNING!!!
167 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:
168 """
169
170 move_namespace_and_warn(
171 [
172 {Pleroma.ActivityExpiration, Pleroma.Workers.PurgeExpiredActivity,
173 "\n* `config :pleroma, Pleroma.ActivityExpiration` is now `config :pleroma, Pleroma.Workers.PurgeExpiredActivity`"}
174 ],
175 warning_preface
176 )
177 end
178 end