Deprecate transparency_exclusions
[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, fn e -> is_binary(e) end) 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 =
85 Config.get([:instance, :quarantined_instances]) |> Enum.any?(fn e -> is_binary(e) end)
86
87 if has_strings do
88 Logger.warn("""
89 !!!DEPRECATION WARNING!!!
90 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:
91
92 ```
93 config :pleroma, :instance,
94 quarantined_instances: ["instance.tld"]
95 ```
96
97 Is now
98
99
100 ```
101 config :pleroma, :instance,
102 quarantined_instances: [{"instance.tld", "Reason for quarantine"}]
103 ```
104 """)
105
106 new_config =
107 Config.get([:instance, :quarantined_instances])
108 |> Enum.map(fn
109 {instance, reason} -> {instance, reason}
110 instance -> {instance, ""}
111 end)
112
113 Config.put([:instance, :quarantined_instances], new_config)
114
115 :error
116 else
117 :ok
118 end
119 end
120
121 def check_transparency_exclusions_tuples do
122 has_strings =
123 Config.get([:mrf, :transparency_exclusions]) |> Enum.any?(fn e -> is_binary(e) end)
124
125 if has_strings do
126 Logger.warn("""
127 !!!DEPRECATION WARNING!!!
128 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:
129
130 ```
131 config :pleroma, :mrf,
132 transparency_exclusions: ["instance.tld"]
133 ```
134
135 Is now
136
137
138 ```
139 config :pleroma, :mrf,
140 transparency_exclusions: [{"instance.tld", "Reason to exlude transparency"}]
141 ```
142 """)
143
144 new_config =
145 Config.get([:mrf, :transparency_exclusions])
146 |> Enum.map(fn
147 {instance, reason} -> {instance, reason}
148 instance -> {instance, ""}
149 end)
150
151 Config.put([:mrf, :transparency_exclusions], new_config)
152
153 :error
154 else
155 :ok
156 end
157 end
158
159 def check_hellthread_threshold do
160 if Config.get([:mrf_hellthread, :threshold]) do
161 Logger.warn("""
162 !!!DEPRECATION WARNING!!!
163 You are using the old configuration mechanism for the hellthread filter. Please check config.md.
164 """)
165
166 :error
167 else
168 :ok
169 end
170 end
171
172 def warn do
173 with :ok <- check_hellthread_threshold(),
174 :ok <- check_old_mrf_config(),
175 :ok <- check_media_proxy_whitelist_config(),
176 :ok <- check_welcome_message_config(),
177 :ok <- check_gun_pool_options(),
178 :ok <- check_activity_expiration_config(),
179 :ok <- check_remote_ip_plug_name(),
180 :ok <- check_uploders_s3_public_endpoint(),
181 :ok <- check_old_chat_shoutbox(),
182 :ok <- check_quarantined_instances_tuples(),
183 :ok <- check_transparency_exclusions_tuples(),
184 :ok <- check_simple_policy_tuples() do
185 :ok
186 else
187 _ ->
188 :error
189 end
190 end
191
192 def check_welcome_message_config do
193 instance_config = Pleroma.Config.get([:instance])
194
195 use_old_config =
196 Keyword.has_key?(instance_config, :welcome_user_nickname) or
197 Keyword.has_key?(instance_config, :welcome_message)
198
199 if use_old_config do
200 Logger.error("""
201 !!!DEPRECATION WARNING!!!
202 Your config is using the old namespace for Welcome messages configuration. You need to convert to the new namespace. e.g.,
203 \n* `config :pleroma, :instance, welcome_user_nickname` and `config :pleroma, :instance, welcome_message` are now equal to:
204 \n* `config :pleroma, :welcome, direct_message: [enabled: true, sender_nickname: "NICKNAME", message: "Your welcome message"]`"
205 """)
206
207 :error
208 else
209 :ok
210 end
211 end
212
213 def check_old_mrf_config do
214 warning_preface = """
215 !!!DEPRECATION WARNING!!!
216 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:
217 """
218
219 move_namespace_and_warn(@mrf_config_map, warning_preface)
220 end
221
222 @spec move_namespace_and_warn([config_map()], String.t()) :: :ok | nil
223 def move_namespace_and_warn(config_map, warning_preface) do
224 warning =
225 Enum.reduce(config_map, "", fn
226 {old, new, err_msg}, acc ->
227 old_config = Config.get(old)
228
229 if old_config do
230 Config.put(new, old_config)
231 acc <> err_msg
232 else
233 acc
234 end
235 end)
236
237 if warning == "" do
238 :ok
239 else
240 Logger.warn(warning_preface <> warning)
241 :error
242 end
243 end
244
245 @spec check_media_proxy_whitelist_config() :: :ok | nil
246 def check_media_proxy_whitelist_config do
247 whitelist = Config.get([:media_proxy, :whitelist])
248
249 if Enum.any?(whitelist, &(not String.starts_with?(&1, "http"))) do
250 Logger.warn("""
251 !!!DEPRECATION WARNING!!!
252 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.
253 """)
254
255 :error
256 else
257 :ok
258 end
259 end
260
261 def check_gun_pool_options do
262 pool_config = Config.get(:connections_pool)
263
264 if timeout = pool_config[:await_up_timeout] do
265 Logger.warn("""
266 !!!DEPRECATION WARNING!!!
267 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.
268 """)
269
270 Config.put(:connections_pool, Keyword.put_new(pool_config, :connect_timeout, timeout))
271 end
272
273 pools_configs = Config.get(:pools)
274
275 warning_preface = """
276 !!!DEPRECATION WARNING!!!
277 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.
278 """
279
280 updated_config =
281 Enum.reduce(pools_configs, [], fn {pool_name, config}, acc ->
282 if timeout = config[:timeout] do
283 Keyword.put(acc, pool_name, Keyword.put_new(config, :recv_timeout, timeout))
284 else
285 acc
286 end
287 end)
288
289 if updated_config != [] do
290 pool_warnings =
291 updated_config
292 |> Keyword.keys()
293 |> Enum.map(fn pool_name ->
294 "\n* `:timeout` options in #{pool_name} pool is now `:recv_timeout`"
295 end)
296
297 Logger.warn(Enum.join([warning_preface | pool_warnings]))
298
299 Config.put(:pools, updated_config)
300 :error
301 else
302 :ok
303 end
304 end
305
306 @spec check_activity_expiration_config() :: :ok | nil
307 def check_activity_expiration_config do
308 warning_preface = """
309 !!!DEPRECATION WARNING!!!
310 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:
311 """
312
313 move_namespace_and_warn(
314 [
315 {Pleroma.ActivityExpiration, Pleroma.Workers.PurgeExpiredActivity,
316 "\n* `config :pleroma, Pleroma.ActivityExpiration` is now `config :pleroma, Pleroma.Workers.PurgeExpiredActivity`"}
317 ],
318 warning_preface
319 )
320 end
321
322 @spec check_remote_ip_plug_name() :: :ok | nil
323 def check_remote_ip_plug_name do
324 warning_preface = """
325 !!!DEPRECATION WARNING!!!
326 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:
327 """
328
329 move_namespace_and_warn(
330 [
331 {Pleroma.Plugs.RemoteIp, Pleroma.Web.Plugs.RemoteIp,
332 "\n* `config :pleroma, Pleroma.Plugs.RemoteIp` is now `config :pleroma, Pleroma.Web.Plugs.RemoteIp`"}
333 ],
334 warning_preface
335 )
336 end
337
338 @spec check_uploders_s3_public_endpoint() :: :ok | nil
339 def check_uploders_s3_public_endpoint do
340 s3_config = Pleroma.Config.get([Pleroma.Uploaders.S3])
341
342 use_old_config = Keyword.has_key?(s3_config, :public_endpoint)
343
344 if use_old_config do
345 Logger.error("""
346 !!!DEPRECATION WARNING!!!
347 Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket.\n
348 Please make the following change at your earliest convenience.\n
349 \n* `config :pleroma, Pleroma.Uploaders.S3, public_endpoint` is now equal to:
350 \n* `config :pleroma, Pleroma.Upload, base_url`
351 """)
352
353 :error
354 else
355 :ok
356 end
357 end
358
359 @spec check_old_chat_shoutbox() :: :ok | nil
360 def check_old_chat_shoutbox do
361 instance_config = Pleroma.Config.get([:instance])
362 chat_config = Pleroma.Config.get([:chat]) || []
363
364 use_old_config =
365 Keyword.has_key?(instance_config, :chat_limit) or
366 Keyword.has_key?(chat_config, :enabled)
367
368 if use_old_config do
369 Logger.error("""
370 !!!DEPRECATION WARNING!!!
371 Your config is using the old namespace for the Shoutbox configuration. You need to convert to the new namespace. e.g.,
372 \n* `config :pleroma, :chat, enabled` and `config :pleroma, :instance, chat_limit` are now equal to:
373 \n* `config :pleroma, :shout, enabled` and `config :pleroma, :shout, limit`
374 """)
375
376 :error
377 else
378 :ok
379 end
380 end
381 end