Merge branch 'v2-suggestions' into 'develop'
[akkoma] / lib / pleroma / config / deprecation_warnings.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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_simple_policy_tuples do
24 has_strings =
25 Config.get([:mrf_simple])
26 |> Enum.any?(fn {_, v} -> Enum.any?(v, &is_binary/1) end)
27
28 if has_strings do
29 Logger.warn("""
30 !!!DEPRECATION WARNING!!!
31 Your config is using strings in the SimplePolicy configuration instead of tuples. They should work for now, but you are advised to change to the new configuration to prevent possible issues later:
32
33 ```
34 config :pleroma, :mrf_simple,
35 media_removal: ["instance.tld"],
36 media_nsfw: ["instance.tld"],
37 federated_timeline_removal: ["instance.tld"],
38 report_removal: ["instance.tld"],
39 reject: ["instance.tld"],
40 followers_only: ["instance.tld"],
41 accept: ["instance.tld"],
42 avatar_removal: ["instance.tld"],
43 banner_removal: ["instance.tld"],
44 reject_deletes: ["instance.tld"]
45 ```
46
47 Is now
48
49
50 ```
51 config :pleroma, :mrf_simple,
52 media_removal: [{"instance.tld", "Reason for media removal"}],
53 media_nsfw: [{"instance.tld", "Reason for media nsfw"}],
54 federated_timeline_removal: [{"instance.tld", "Reason for federated timeline removal"}],
55 report_removal: [{"instance.tld", "Reason for report removal"}],
56 reject: [{"instance.tld", "Reason for reject"}],
57 followers_only: [{"instance.tld", "Reason for followers only"}],
58 accept: [{"instance.tld", "Reason for accept"}],
59 avatar_removal: [{"instance.tld", "Reason for avatar removal"}],
60 banner_removal: [{"instance.tld", "Reason for banner removal"}],
61 reject_deletes: [{"instance.tld", "Reason for reject deletes"}]
62 ```
63 """)
64
65 new_config =
66 Config.get([:mrf_simple])
67 |> Enum.map(fn {k, v} ->
68 {k,
69 Enum.map(v, fn
70 {instance, reason} -> {instance, reason}
71 instance -> {instance, ""}
72 end)}
73 end)
74
75 Config.put([:mrf_simple], new_config)
76
77 :error
78 else
79 :ok
80 end
81 end
82
83 def check_quarantined_instances_tuples do
84 has_strings = Config.get([:instance, :quarantined_instances]) |> Enum.any?(&is_binary/1)
85
86 if has_strings do
87 Logger.warn("""
88 !!!DEPRECATION WARNING!!!
89 Your config is using strings in the quarantined_instances configuration instead of tuples. They should work for now, but you are advised to change to the new configuration to prevent possible issues later:
90
91 ```
92 config :pleroma, :instance,
93 quarantined_instances: ["instance.tld"]
94 ```
95
96 Is now
97
98
99 ```
100 config :pleroma, :instance,
101 quarantined_instances: [{"instance.tld", "Reason for quarantine"}]
102 ```
103 """)
104
105 new_config =
106 Config.get([:instance, :quarantined_instances])
107 |> Enum.map(fn
108 {instance, reason} -> {instance, reason}
109 instance -> {instance, ""}
110 end)
111
112 Config.put([:instance, :quarantined_instances], new_config)
113
114 :error
115 else
116 :ok
117 end
118 end
119
120 def check_transparency_exclusions_tuples do
121 has_strings = Config.get([:mrf, :transparency_exclusions]) |> Enum.any?(&is_binary/1)
122
123 if has_strings do
124 Logger.warn("""
125 !!!DEPRECATION WARNING!!!
126 Your config is using strings in the transparency_exclusions configuration instead of tuples. They should work for now, but you are advised to change to the new configuration to prevent possible issues later:
127
128 ```
129 config :pleroma, :mrf,
130 transparency_exclusions: ["instance.tld"]
131 ```
132
133 Is now
134
135
136 ```
137 config :pleroma, :mrf,
138 transparency_exclusions: [{"instance.tld", "Reason to exlude transparency"}]
139 ```
140 """)
141
142 new_config =
143 Config.get([:mrf, :transparency_exclusions])
144 |> Enum.map(fn
145 {instance, reason} -> {instance, reason}
146 instance -> {instance, ""}
147 end)
148
149 Config.put([:mrf, :transparency_exclusions], new_config)
150
151 :error
152 else
153 :ok
154 end
155 end
156
157 def check_hellthread_threshold do
158 if Config.get([:mrf_hellthread, :threshold]) do
159 Logger.warn("""
160 !!!DEPRECATION WARNING!!!
161 You are using the old configuration mechanism for the hellthread filter. Please check config.md.
162 """)
163
164 :error
165 else
166 :ok
167 end
168 end
169
170 def warn do
171 [
172 check_hellthread_threshold(),
173 check_old_mrf_config(),
174 check_media_proxy_whitelist_config(),
175 check_welcome_message_config(),
176 check_gun_pool_options(),
177 check_activity_expiration_config(),
178 check_remote_ip_plug_name(),
179 check_uploders_s3_public_endpoint(),
180 check_old_chat_shoutbox(),
181 check_quarantined_instances_tuples(),
182 check_transparency_exclusions_tuples(),
183 check_simple_policy_tuples()
184 ]
185 |> Enum.reduce(:ok, fn
186 :ok, :ok -> :ok
187 _, _ -> :error
188 end)
189 end
190
191 def check_welcome_message_config do
192 instance_config = Pleroma.Config.get([:instance])
193
194 use_old_config =
195 Keyword.has_key?(instance_config, :welcome_user_nickname) or
196 Keyword.has_key?(instance_config, :welcome_message)
197
198 if use_old_config do
199 Logger.error("""
200 !!!DEPRECATION WARNING!!!
201 Your config is using the old namespace for Welcome messages configuration. You need to convert to the new namespace. e.g.,
202 \n* `config :pleroma, :instance, welcome_user_nickname` and `config :pleroma, :instance, welcome_message` are now equal to:
203 \n* `config :pleroma, :welcome, direct_message: [enabled: true, sender_nickname: "NICKNAME", message: "Your welcome message"]`"
204 """)
205
206 :error
207 else
208 :ok
209 end
210 end
211
212 def check_old_mrf_config do
213 warning_preface = """
214 !!!DEPRECATION WARNING!!!
215 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:
216 """
217
218 move_namespace_and_warn(@mrf_config_map, warning_preface)
219 end
220
221 @spec move_namespace_and_warn([config_map()], String.t()) :: :ok | nil
222 def move_namespace_and_warn(config_map, warning_preface) do
223 warning =
224 Enum.reduce(config_map, "", fn
225 {old, new, err_msg}, acc ->
226 old_config = Config.get(old)
227
228 if old_config do
229 Config.put(new, old_config)
230 acc <> err_msg
231 else
232 acc
233 end
234 end)
235
236 if warning == "" do
237 :ok
238 else
239 Logger.warn(warning_preface <> warning)
240 :error
241 end
242 end
243
244 @spec check_media_proxy_whitelist_config() :: :ok | nil
245 def check_media_proxy_whitelist_config do
246 whitelist = Config.get([:media_proxy, :whitelist])
247
248 if Enum.any?(whitelist, &(not String.starts_with?(&1, "http"))) do
249 Logger.warn("""
250 !!!DEPRECATION WARNING!!!
251 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.
252 """)
253
254 :error
255 else
256 :ok
257 end
258 end
259
260 def check_gun_pool_options do
261 pool_config = Config.get(:connections_pool)
262
263 if timeout = pool_config[:await_up_timeout] do
264 Logger.warn("""
265 !!!DEPRECATION WARNING!!!
266 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.
267 """)
268
269 Config.put(:connections_pool, Keyword.put_new(pool_config, :connect_timeout, timeout))
270 end
271
272 pools_configs = Config.get(:pools)
273
274 warning_preface = """
275 !!!DEPRECATION WARNING!!!
276 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.
277 """
278
279 updated_config =
280 Enum.reduce(pools_configs, [], fn {pool_name, config}, acc ->
281 if timeout = config[:timeout] do
282 Keyword.put(acc, pool_name, Keyword.put_new(config, :recv_timeout, timeout))
283 else
284 acc
285 end
286 end)
287
288 if updated_config != [] do
289 pool_warnings =
290 updated_config
291 |> Keyword.keys()
292 |> Enum.map(fn pool_name ->
293 "\n* `:timeout` options in #{pool_name} pool is now `:recv_timeout`"
294 end)
295
296 Logger.warn(Enum.join([warning_preface | pool_warnings]))
297
298 Config.put(:pools, updated_config)
299 :error
300 else
301 :ok
302 end
303 end
304
305 @spec check_activity_expiration_config() :: :ok | nil
306 def check_activity_expiration_config do
307 warning_preface = """
308 !!!DEPRECATION WARNING!!!
309 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:
310 """
311
312 move_namespace_and_warn(
313 [
314 {Pleroma.ActivityExpiration, Pleroma.Workers.PurgeExpiredActivity,
315 "\n* `config :pleroma, Pleroma.ActivityExpiration` is now `config :pleroma, Pleroma.Workers.PurgeExpiredActivity`"}
316 ],
317 warning_preface
318 )
319 end
320
321 @spec check_remote_ip_plug_name() :: :ok | nil
322 def check_remote_ip_plug_name do
323 warning_preface = """
324 !!!DEPRECATION WARNING!!!
325 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:
326 """
327
328 move_namespace_and_warn(
329 [
330 {Pleroma.Plugs.RemoteIp, Pleroma.Web.Plugs.RemoteIp,
331 "\n* `config :pleroma, Pleroma.Plugs.RemoteIp` is now `config :pleroma, Pleroma.Web.Plugs.RemoteIp`"}
332 ],
333 warning_preface
334 )
335 end
336
337 @spec check_uploders_s3_public_endpoint() :: :ok | nil
338 def check_uploders_s3_public_endpoint do
339 s3_config = Pleroma.Config.get([Pleroma.Uploaders.S3])
340
341 use_old_config = Keyword.has_key?(s3_config, :public_endpoint)
342
343 if use_old_config do
344 Logger.error("""
345 !!!DEPRECATION WARNING!!!
346 Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket.\n
347 Please make the following change at your earliest convenience.\n
348 \n* `config :pleroma, Pleroma.Uploaders.S3, public_endpoint` is now equal to:
349 \n* `config :pleroma, Pleroma.Upload, base_url`
350 """)
351
352 :error
353 else
354 :ok
355 end
356 end
357
358 @spec check_old_chat_shoutbox() :: :ok | nil
359 def check_old_chat_shoutbox do
360 instance_config = Pleroma.Config.get([:instance])
361 chat_config = Pleroma.Config.get([:chat]) || []
362
363 use_old_config =
364 Keyword.has_key?(instance_config, :chat_limit) or
365 Keyword.has_key?(chat_config, :enabled)
366
367 if use_old_config do
368 Logger.error("""
369 !!!DEPRECATION WARNING!!!
370 Your config is using the old namespace for the Shoutbox configuration. You need to convert to the new namespace. e.g.,
371 \n* `config :pleroma, :chat, enabled` and `config :pleroma, :instance, chat_limit` are now equal to:
372 \n* `config :pleroma, :shout, enabled` and `config :pleroma, :shout, limit`
373 """)
374
375 :error
376 else
377 :ok
378 end
379 end
380 end