merge
[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_hellthread_threshold do
24 if Config.get([:mrf_hellthread, :threshold]) do
25 Logger.warn("""
26 !!!DEPRECATION WARNING!!!
27 You are using the old configuration mechanism for the hellthread filter. Please check config.md.
28 """)
29
30 :error
31 else
32 :ok
33 end
34 end
35
36 def warn do
37 with :ok <- check_hellthread_threshold(),
38 :ok <- check_old_mrf_config(),
39 :ok <- check_media_proxy_whitelist_config(),
40 :ok <- check_welcome_message_config(),
41 :ok <- check_gun_pool_options(),
42 :ok <- check_activity_expiration_config(),
43 :ok <- check_remote_ip_plug_name(),
44 :ok <- check_uploders_s3_public_endpoint(),
45 :ok <- check_old_chat_shoutbox() do
46 :ok
47 else
48 _ ->
49 :error
50 end
51 end
52
53 def check_welcome_message_config do
54 instance_config = Pleroma.Config.get([:instance])
55
56 use_old_config =
57 Keyword.has_key?(instance_config, :welcome_user_nickname) or
58 Keyword.has_key?(instance_config, :welcome_message)
59
60 if use_old_config do
61 Logger.error("""
62 !!!DEPRECATION WARNING!!!
63 Your config is using the old namespace for Welcome messages configuration. You need to convert to the new namespace. e.g.,
64 \n* `config :pleroma, :instance, welcome_user_nickname` and `config :pleroma, :instance, welcome_message` are now equal to:
65 \n* `config :pleroma, :welcome, direct_message: [enabled: true, sender_nickname: "NICKNAME", message: "Your welcome message"]`"
66 """)
67
68 :error
69 else
70 :ok
71 end
72 end
73
74 def check_old_mrf_config do
75 warning_preface = """
76 !!!DEPRECATION WARNING!!!
77 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:
78 """
79
80 move_namespace_and_warn(@mrf_config_map, warning_preface)
81 end
82
83 @spec move_namespace_and_warn([config_map()], String.t()) :: :ok | nil
84 def move_namespace_and_warn(config_map, warning_preface) do
85 warning =
86 Enum.reduce(config_map, "", fn
87 {old, new, err_msg}, acc ->
88 old_config = Config.get(old)
89
90 if old_config do
91 Config.put(new, old_config)
92 acc <> err_msg
93 else
94 acc
95 end
96 end)
97
98 if warning == "" do
99 :ok
100 else
101 Logger.warn(warning_preface <> warning)
102 :error
103 end
104 end
105
106 @spec check_media_proxy_whitelist_config() :: :ok | nil
107 def check_media_proxy_whitelist_config do
108 whitelist = Config.get([:media_proxy, :whitelist])
109
110 if Enum.any?(whitelist, &(not String.starts_with?(&1, "http"))) do
111 Logger.warn("""
112 !!!DEPRECATION WARNING!!!
113 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.
114 """)
115
116 :error
117 else
118 :ok
119 end
120 end
121
122 def check_gun_pool_options do
123 pool_config = Config.get(:connections_pool)
124
125 if timeout = pool_config[:await_up_timeout] do
126 Logger.warn("""
127 !!!DEPRECATION WARNING!!!
128 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.
129 """)
130
131 Config.put(:connections_pool, Keyword.put_new(pool_config, :connect_timeout, timeout))
132 end
133
134 pools_configs = Config.get(:pools)
135
136 warning_preface = """
137 !!!DEPRECATION WARNING!!!
138 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.
139 """
140
141 updated_config =
142 Enum.reduce(pools_configs, [], fn {pool_name, config}, acc ->
143 if timeout = config[:timeout] do
144 Keyword.put(acc, pool_name, Keyword.put_new(config, :recv_timeout, timeout))
145 else
146 acc
147 end
148 end)
149
150 if updated_config != [] do
151 pool_warnings =
152 updated_config
153 |> Keyword.keys()
154 |> Enum.map(fn pool_name ->
155 "\n* `:timeout` options in #{pool_name} pool is now `:recv_timeout`"
156 end)
157
158 Logger.warn(Enum.join([warning_preface | pool_warnings]))
159
160 Config.put(:pools, updated_config)
161 :error
162 else
163 :ok
164 end
165 end
166
167 @spec check_activity_expiration_config() :: :ok | nil
168 def check_activity_expiration_config do
169 warning_preface = """
170 !!!DEPRECATION WARNING!!!
171 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:
172 """
173
174 move_namespace_and_warn(
175 [
176 {Pleroma.ActivityExpiration, Pleroma.Workers.PurgeExpiredActivity,
177 "\n* `config :pleroma, Pleroma.ActivityExpiration` is now `config :pleroma, Pleroma.Workers.PurgeExpiredActivity`"}
178 ],
179 warning_preface
180 )
181 end
182
183 @spec check_remote_ip_plug_name() :: :ok | nil
184 def check_remote_ip_plug_name do
185 warning_preface = """
186 !!!DEPRECATION WARNING!!!
187 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:
188 """
189
190 move_namespace_and_warn(
191 [
192 {Pleroma.Plugs.RemoteIp, Pleroma.Web.Plugs.RemoteIp,
193 "\n* `config :pleroma, Pleroma.Plugs.RemoteIp` is now `config :pleroma, Pleroma.Web.Plugs.RemoteIp`"}
194 ],
195 warning_preface
196 )
197 end
198
199 @spec check_uploders_s3_public_endpoint() :: :ok | nil
200 def check_uploders_s3_public_endpoint do
201 s3_config = Pleroma.Config.get([Pleroma.Uploaders.S3])
202
203 use_old_config = Keyword.has_key?(s3_config, :public_endpoint)
204
205 if use_old_config do
206 Logger.error("""
207 !!!DEPRECATION WARNING!!!
208 Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket.\n
209 Please make the following change at your earliest convenience.\n
210 \n* `config :pleroma, Pleroma.Uploaders.S3, public_endpoint` is now equal to:
211 \n* `config :pleroma, Pleroma.Upload, base_url`
212 """)
213
214 :error
215 else
216 :ok
217 end
218 end
219
220 @spec check_old_chat_shoutbox() :: :ok | nil
221 def check_old_chat_shoutbox do
222 instance_config = Pleroma.Config.get([:instance])
223 chat_config = Pleroma.Config.get([:chat]) || []
224
225 use_old_config =
226 Keyword.has_key?(instance_config, :chat_limit) or
227 Keyword.has_key?(chat_config, :enabled)
228
229 if use_old_config do
230 Logger.error("""
231 !!!DEPRECATION WARNING!!!
232 Your config is using the old namespace for the Shoutbox configuration. You need to convert to the new namespace. e.g.,
233 \n* `config :pleroma, :chat, enabled` and `config :pleroma, :instance, chat_limit` are now equal to:
234 \n* `config :pleroma, :shout, enabled` and `config :pleroma, :shout, limit`
235 """)
236
237 :error
238 else
239 :ok
240 end
241 end
242 end