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, &is_binary/1) 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
84 has_strings = Config.get([:instance, :quarantined_instances]) |> Enum.any?(&is_binary/1)
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:
92 config :pleroma, :instance,
93 quarantined_instances: ["instance.tld"]
100 config :pleroma, :instance,
101 quarantined_instances: [{"instance.tld", "Reason for quarantine"}]
106 Config.get([:instance, :quarantined_instances])
108 {instance, reason} -> {instance, reason}
109 instance -> {instance, ""}
112 Config.put([:instance, :quarantined_instances], new_config)
120 def check_transparency_exclusions_tuples do
121 has_strings = Config.get([:mrf, :transparency_exclusions]) |> Enum.any?(&is_binary/1)
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:
129 config :pleroma, :mrf,
130 transparency_exclusions: ["instance.tld"]
137 config :pleroma, :mrf,
138 transparency_exclusions: [{"instance.tld", "Reason to exlude transparency"}]
143 Config.get([:mrf, :transparency_exclusions])
145 {instance, reason} -> {instance, reason}
146 instance -> {instance, ""}
149 Config.put([:mrf, :transparency_exclusions], new_config)
157 def check_hellthread_threshold do
158 if Config.get([:mrf_hellthread, :threshold]) do
160 !!!DEPRECATION WARNING!!!
161 You are using the old configuration mechanism for the hellthread filter. Please check config.md.
172 check_hellthread_threshold(),
173 check_old_mrf_config(),
174 check_media_proxy_whitelist_config(),
175 check_welcome_message_config(),
176 check_activity_expiration_config(),
177 check_remote_ip_plug_name(),
178 check_uploders_s3_public_endpoint(),
179 check_quarantined_instances_tuples(),
180 check_transparency_exclusions_tuples(),
181 check_simple_policy_tuples()
183 |> Enum.reduce(:ok, fn
189 def check_welcome_message_config do
190 instance_config = Pleroma.Config.get([:instance])
193 Keyword.has_key?(instance_config, :welcome_user_nickname) or
194 Keyword.has_key?(instance_config, :welcome_message)
198 !!!DEPRECATION WARNING!!!
199 Your config is using the old namespace for Welcome messages configuration. You need to convert to the new namespace. e.g.,
200 \n* `config :pleroma, :instance, welcome_user_nickname` and `config :pleroma, :instance, welcome_message` are now equal to:
201 \n* `config :pleroma, :welcome, direct_message: [enabled: true, sender_nickname: "NICKNAME", message: "Your welcome message"]`"
210 def check_old_mrf_config do
211 warning_preface = """
212 !!!DEPRECATION WARNING!!!
213 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 move_namespace_and_warn(@mrf_config_map, warning_preface)
219 @spec move_namespace_and_warn([config_map()], String.t()) :: :ok | nil
220 def move_namespace_and_warn(config_map, warning_preface) do
222 Enum.reduce(config_map, "", fn
223 {old, new, err_msg}, acc ->
224 old_config = Config.get(old)
227 Config.put(new, old_config)
237 Logger.warn(warning_preface <> warning)
242 @spec check_media_proxy_whitelist_config() :: :ok | nil
243 def check_media_proxy_whitelist_config do
244 whitelist = Config.get([:media_proxy, :whitelist])
246 if Enum.any?(whitelist, &(not String.starts_with?(&1, "http"))) do
248 !!!DEPRECATION WARNING!!!
249 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.
258 @spec check_activity_expiration_config() :: :ok | nil
259 def check_activity_expiration_config do
260 warning_preface = """
261 !!!DEPRECATION WARNING!!!
262 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:
265 move_namespace_and_warn(
267 {Pleroma.ActivityExpiration, Pleroma.Workers.PurgeExpiredActivity,
268 "\n* `config :pleroma, Pleroma.ActivityExpiration` is now `config :pleroma, Pleroma.Workers.PurgeExpiredActivity`"}
274 @spec check_remote_ip_plug_name() :: :ok | nil
275 def check_remote_ip_plug_name do
276 warning_preface = """
277 !!!DEPRECATION WARNING!!!
278 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:
281 move_namespace_and_warn(
283 {Pleroma.Plugs.RemoteIp, Pleroma.Web.Plugs.RemoteIp,
284 "\n* `config :pleroma, Pleroma.Plugs.RemoteIp` is now `config :pleroma, Pleroma.Web.Plugs.RemoteIp`"}
290 @spec check_uploders_s3_public_endpoint() :: :ok | nil
291 def check_uploders_s3_public_endpoint do
292 s3_config = Pleroma.Config.get([Pleroma.Uploaders.S3])
294 use_old_config = Keyword.has_key?(s3_config, :public_endpoint)
298 !!!DEPRECATION WARNING!!!
299 Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket.\n
300 Please make the following change at your earliest convenience.\n
301 \n* `config :pleroma, Pleroma.Uploaders.S3, public_endpoint` is now equal to:
302 \n* `config :pleroma, Pleroma.Upload, base_url`