1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 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_exiftool_filter do
24 filters = Config.get([Pleroma.Upload]) |> Keyword.get(:filters, [])
26 if Pleroma.Upload.Filter.Exiftool in filters do
28 !!!DEPRECATION WARNING!!!
29 Your config is using Exiftool as a filter instead of Exiftool.StripLocation. This should work for now, but you are advised to change to the new configuration to prevent possible issues later:
32 config :pleroma, Pleroma.Upload,
33 filters: [Pleroma.Upload.Filter.Exiftool]
40 config :pleroma, Pleroma.Upload,
41 filters: [Pleroma.Upload.Filter.Exiftool.StripLocation]
48 Pleroma.Upload.Filter.Exiftool -> Pleroma.Upload.Filter.Exiftool.StripLocation
52 Config.put([Pleroma.Upload, :filters], new_config)
60 def check_simple_policy_tuples do
62 Config.get([:mrf_simple])
63 |> Enum.any?(fn {_, v} -> Enum.any?(v, &is_binary/1) end)
67 !!!DEPRECATION WARNING!!!
68 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:
71 config :pleroma, :mrf_simple,
72 media_removal: ["instance.tld"],
73 media_nsfw: ["instance.tld"],
74 federated_timeline_removal: ["instance.tld"],
75 report_removal: ["instance.tld"],
76 reject: ["instance.tld"],
77 followers_only: ["instance.tld"],
78 accept: ["instance.tld"],
79 avatar_removal: ["instance.tld"],
80 banner_removal: ["instance.tld"],
81 reject_deletes: ["instance.tld"]
88 config :pleroma, :mrf_simple,
89 media_removal: [{"instance.tld", "Reason for media removal"}],
90 media_nsfw: [{"instance.tld", "Reason for media nsfw"}],
91 federated_timeline_removal: [{"instance.tld", "Reason for federated timeline removal"}],
92 report_removal: [{"instance.tld", "Reason for report removal"}],
93 reject: [{"instance.tld", "Reason for reject"}],
94 followers_only: [{"instance.tld", "Reason for followers only"}],
95 accept: [{"instance.tld", "Reason for accept"}],
96 avatar_removal: [{"instance.tld", "Reason for avatar removal"}],
97 banner_removal: [{"instance.tld", "Reason for banner removal"}],
98 reject_deletes: [{"instance.tld", "Reason for reject deletes"}]
103 Config.get([:mrf_simple])
104 |> Enum.map(fn {k, v} ->
107 {instance, reason} -> {instance, reason}
108 instance -> {instance, ""}
112 Config.put([:mrf_simple], new_config)
120 def check_quarantined_instances_tuples do
121 has_strings = Config.get([:instance, :quarantined_instances]) |> Enum.any?(&is_binary/1)
125 !!!DEPRECATION WARNING!!!
126 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:
129 config :pleroma, :instance,
130 quarantined_instances: ["instance.tld"]
137 config :pleroma, :instance,
138 quarantined_instances: [{"instance.tld", "Reason for quarantine"}]
143 Config.get([:instance, :quarantined_instances])
145 {instance, reason} -> {instance, reason}
146 instance -> {instance, ""}
149 Config.put([:instance, :quarantined_instances], new_config)
157 def check_transparency_exclusions_tuples do
158 has_strings = Config.get([:mrf, :transparency_exclusions]) |> Enum.any?(&is_binary/1)
162 !!!DEPRECATION WARNING!!!
163 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:
166 config :pleroma, :mrf,
167 transparency_exclusions: ["instance.tld"]
174 config :pleroma, :mrf,
175 transparency_exclusions: [{"instance.tld", "Reason to exlude transparency"}]
180 Config.get([:mrf, :transparency_exclusions])
182 {instance, reason} -> {instance, reason}
183 instance -> {instance, ""}
186 Config.put([:mrf, :transparency_exclusions], new_config)
194 def check_hellthread_threshold do
195 if Config.get([:mrf_hellthread, :threshold]) do
197 !!!DEPRECATION WARNING!!!
198 You are using the old configuration mechanism for the hellthread filter. Please check config.md.
209 check_hellthread_threshold(),
210 check_old_mrf_config(),
211 check_media_proxy_whitelist_config(),
212 check_welcome_message_config(),
213 check_gun_pool_options(),
214 check_activity_expiration_config(),
215 check_remote_ip_plug_name(),
216 check_uploders_s3_public_endpoint(),
217 check_old_chat_shoutbox(),
218 check_quarantined_instances_tuples(),
219 check_transparency_exclusions_tuples(),
220 check_simple_policy_tuples(),
221 check_exiftool_filter()
223 |> Enum.reduce(:ok, fn
229 def check_welcome_message_config do
230 instance_config = Pleroma.Config.get([:instance])
233 Keyword.has_key?(instance_config, :welcome_user_nickname) or
234 Keyword.has_key?(instance_config, :welcome_message)
238 !!!DEPRECATION WARNING!!!
239 Your config is using the old namespace for Welcome messages configuration. You need to convert to the new namespace. e.g.,
240 \n* `config :pleroma, :instance, welcome_user_nickname` and `config :pleroma, :instance, welcome_message` are now equal to:
241 \n* `config :pleroma, :welcome, direct_message: [enabled: true, sender_nickname: "NICKNAME", message: "Your welcome message"]`"
250 def check_old_mrf_config do
251 warning_preface = """
252 !!!DEPRECATION WARNING!!!
253 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:
256 move_namespace_and_warn(@mrf_config_map, warning_preface)
259 @spec move_namespace_and_warn([config_map()], String.t()) :: :ok | nil
260 def move_namespace_and_warn(config_map, warning_preface) do
262 Enum.reduce(config_map, "", fn
263 {old, new, err_msg}, acc ->
264 old_config = Config.get(old)
267 Config.put(new, old_config)
277 Logger.warn(warning_preface <> warning)
282 @spec check_media_proxy_whitelist_config() :: :ok | nil
283 def check_media_proxy_whitelist_config do
284 whitelist = Config.get([:media_proxy, :whitelist])
286 if Enum.any?(whitelist, &(not String.starts_with?(&1, "http"))) do
288 !!!DEPRECATION WARNING!!!
289 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.
298 def check_gun_pool_options do
299 pool_config = Config.get(:connections_pool)
301 if timeout = pool_config[:await_up_timeout] do
303 !!!DEPRECATION WARNING!!!
304 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.
307 Config.put(:connections_pool, Keyword.put_new(pool_config, :connect_timeout, timeout))
310 pools_configs = Config.get(:pools)
312 warning_preface = """
313 !!!DEPRECATION WARNING!!!
314 Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings. The setting will not take effect until updated.
318 Enum.reduce(pools_configs, [], fn {pool_name, config}, acc ->
319 if timeout = config[:timeout] do
320 Keyword.put(acc, pool_name, Keyword.put_new(config, :recv_timeout, timeout))
326 if updated_config != [] do
330 |> Enum.map(fn pool_name ->
331 "\n* `:timeout` options in #{pool_name} pool is now `:recv_timeout`"
334 Logger.warn(Enum.join([warning_preface | pool_warnings]))
336 Config.put(:pools, updated_config)
343 @spec check_activity_expiration_config() :: :ok | nil
344 def check_activity_expiration_config do
345 warning_preface = """
346 !!!DEPRECATION WARNING!!!
347 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:
350 move_namespace_and_warn(
352 {Pleroma.ActivityExpiration, Pleroma.Workers.PurgeExpiredActivity,
353 "\n* `config :pleroma, Pleroma.ActivityExpiration` is now `config :pleroma, Pleroma.Workers.PurgeExpiredActivity`"}
359 @spec check_remote_ip_plug_name() :: :ok | nil
360 def check_remote_ip_plug_name do
361 warning_preface = """
362 !!!DEPRECATION WARNING!!!
363 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:
366 move_namespace_and_warn(
368 {Pleroma.Plugs.RemoteIp, Pleroma.Web.Plugs.RemoteIp,
369 "\n* `config :pleroma, Pleroma.Plugs.RemoteIp` is now `config :pleroma, Pleroma.Web.Plugs.RemoteIp`"}
375 @spec check_uploders_s3_public_endpoint() :: :ok | nil
376 def check_uploders_s3_public_endpoint do
377 s3_config = Pleroma.Config.get([Pleroma.Uploaders.S3])
379 use_old_config = Keyword.has_key?(s3_config, :public_endpoint)
383 !!!DEPRECATION WARNING!!!
384 Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket.\n
385 Please make the following change at your earliest convenience.\n
386 \n* `config :pleroma, Pleroma.Uploaders.S3, public_endpoint` is now equal to:
387 \n* `config :pleroma, Pleroma.Upload, base_url`
396 @spec check_old_chat_shoutbox() :: :ok | nil
397 def check_old_chat_shoutbox do
398 instance_config = Pleroma.Config.get([:instance])
399 chat_config = Pleroma.Config.get([:chat]) || []
402 Keyword.has_key?(instance_config, :chat_limit) or
403 Keyword.has_key?(chat_config, :enabled)
407 !!!DEPRECATION WARNING!!!
408 Your config is using the old namespace for the Shoutbox configuration. You need to convert to the new namespace. e.g.,
409 \n* `config :pleroma, :chat, enabled` and `config :pleroma, :instance, chat_limit` are now equal to:
410 \n* `config :pleroma, :shout, enabled` and `config :pleroma, :shout, limit`