1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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_simple_policy_tuples do
25 Config.get([:mrf_simple])
26 |> Enum.any?(fn {_, v} -> Enum.any?(v, fn e -> is_binary(e) end) end)
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:
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"]
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"}]
66 Config.get([:mrf_simple])
67 |> Enum.map(fn {k, v} ->
70 {instance, reason} -> {instance, reason}
71 instance -> {instance, ""}
75 Config.put([:mrf_simple], new_config)
83 def check_quarantined_instances_tuples do
85 Config.get([:instance, :quarantined_instances]) |> Enum.any?(fn e -> is_binary(e) end)
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:
93 config :pleroma, :instance,
94 quarantined_instances: ["instance.tld"]
101 config :pleroma, :instance,
102 quarantined_instances: [{"instance.tld", "Reason for quarantine"}]
107 Config.get([:instance, :quarantined_instances])
109 {instance, reason} -> {instance, reason}
110 instance -> {instance, ""}
113 Config.put([:instance, :quarantined_instances], new_config)
121 def check_transparency_exclusions_tuples do
123 Config.get([:mrf, :transparency_exclusions]) |> Enum.any?(fn e -> is_binary(e) end)
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:
131 config :pleroma, :mrf,
132 transparency_exclusions: ["instance.tld"]
139 config :pleroma, :mrf,
140 transparency_exclusions: [{"instance.tld", "Reason to exlude transparency"}]
145 Config.get([:mrf, :transparency_exclusions])
147 {instance, reason} -> {instance, reason}
148 instance -> {instance, ""}
151 Config.put([:mrf, :transparency_exclusions], new_config)
159 def check_hellthread_threshold do
160 if Config.get([:mrf_hellthread, :threshold]) do
162 !!!DEPRECATION WARNING!!!
163 You are using the old configuration mechanism for the hellthread filter. Please check config.md.
174 check_hellthread_threshold(),
175 check_old_mrf_config(),
176 check_media_proxy_whitelist_config(),
177 check_welcome_message_config(),
178 check_gun_pool_options(),
179 check_activity_expiration_config(),
180 check_remote_ip_plug_name(),
181 check_uploders_s3_public_endpoint(),
182 check_old_chat_shoutbox(),
183 check_quarantined_instances_tuples(),
184 check_transparency_exclusions_tuples(),
185 check_simple_policy_tuples()
187 |> Enum.reduce(:ok, fn
193 def check_welcome_message_config do
194 instance_config = Pleroma.Config.get([:instance])
197 Keyword.has_key?(instance_config, :welcome_user_nickname) or
198 Keyword.has_key?(instance_config, :welcome_message)
202 !!!DEPRECATION WARNING!!!
203 Your config is using the old namespace for Welcome messages configuration. You need to convert to the new namespace. e.g.,
204 \n* `config :pleroma, :instance, welcome_user_nickname` and `config :pleroma, :instance, welcome_message` are now equal to:
205 \n* `config :pleroma, :welcome, direct_message: [enabled: true, sender_nickname: "NICKNAME", message: "Your welcome message"]`"
214 def check_old_mrf_config do
215 warning_preface = """
216 !!!DEPRECATION WARNING!!!
217 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:
220 move_namespace_and_warn(@mrf_config_map, warning_preface)
223 @spec move_namespace_and_warn([config_map()], String.t()) :: :ok | nil
224 def move_namespace_and_warn(config_map, warning_preface) do
226 Enum.reduce(config_map, "", fn
227 {old, new, err_msg}, acc ->
228 old_config = Config.get(old)
231 Config.put(new, old_config)
241 Logger.warn(warning_preface <> warning)
246 @spec check_media_proxy_whitelist_config() :: :ok | nil
247 def check_media_proxy_whitelist_config do
248 whitelist = Config.get([:media_proxy, :whitelist])
250 if Enum.any?(whitelist, &(not String.starts_with?(&1, "http"))) do
252 !!!DEPRECATION WARNING!!!
253 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.
262 def check_gun_pool_options do
263 pool_config = Config.get(:connections_pool)
265 if timeout = pool_config[:await_up_timeout] do
267 !!!DEPRECATION WARNING!!!
268 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.
271 Config.put(:connections_pool, Keyword.put_new(pool_config, :connect_timeout, timeout))
274 pools_configs = Config.get(:pools)
276 warning_preface = """
277 !!!DEPRECATION WARNING!!!
278 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.
282 Enum.reduce(pools_configs, [], fn {pool_name, config}, acc ->
283 if timeout = config[:timeout] do
284 Keyword.put(acc, pool_name, Keyword.put_new(config, :recv_timeout, timeout))
290 if updated_config != [] do
294 |> Enum.map(fn pool_name ->
295 "\n* `:timeout` options in #{pool_name} pool is now `:recv_timeout`"
298 Logger.warn(Enum.join([warning_preface | pool_warnings]))
300 Config.put(:pools, updated_config)
307 @spec check_activity_expiration_config() :: :ok | nil
308 def check_activity_expiration_config do
309 warning_preface = """
310 !!!DEPRECATION WARNING!!!
311 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:
314 move_namespace_and_warn(
316 {Pleroma.ActivityExpiration, Pleroma.Workers.PurgeExpiredActivity,
317 "\n* `config :pleroma, Pleroma.ActivityExpiration` is now `config :pleroma, Pleroma.Workers.PurgeExpiredActivity`"}
323 @spec check_remote_ip_plug_name() :: :ok | nil
324 def check_remote_ip_plug_name do
325 warning_preface = """
326 !!!DEPRECATION WARNING!!!
327 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:
330 move_namespace_and_warn(
332 {Pleroma.Plugs.RemoteIp, Pleroma.Web.Plugs.RemoteIp,
333 "\n* `config :pleroma, Pleroma.Plugs.RemoteIp` is now `config :pleroma, Pleroma.Web.Plugs.RemoteIp`"}
339 @spec check_uploders_s3_public_endpoint() :: :ok | nil
340 def check_uploders_s3_public_endpoint do
341 s3_config = Pleroma.Config.get([Pleroma.Uploaders.S3])
343 use_old_config = Keyword.has_key?(s3_config, :public_endpoint)
347 !!!DEPRECATION WARNING!!!
348 Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket.\n
349 Please make the following change at your earliest convenience.\n
350 \n* `config :pleroma, Pleroma.Uploaders.S3, public_endpoint` is now equal to:
351 \n* `config :pleroma, Pleroma.Upload, base_url`
360 @spec check_old_chat_shoutbox() :: :ok | nil
361 def check_old_chat_shoutbox do
362 instance_config = Pleroma.Config.get([:instance])
363 chat_config = Pleroma.Config.get([:chat]) || []
366 Keyword.has_key?(instance_config, :chat_limit) or
367 Keyword.has_key?(chat_config, :enabled)
371 !!!DEPRECATION WARNING!!!
372 Your config is using the old namespace for the Shoutbox configuration. You need to convert to the new namespace. e.g.,
373 \n* `config :pleroma, :chat, enabled` and `config :pleroma, :instance, chat_limit` are now equal to:
374 \n* `config :pleroma, :shout, enabled` and `config :pleroma, :shout, limit`