8a336c35a3d5ace64455f7926e5a2ccf68603b1c
[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 {[:instance, :quarantined_instances], [:mrf_simple, :reject],
22 "\n* `config :pleroma, :instance, :quarantined_instances` is now covered by `:pleroma, :mrf_simple, :reject`"}
23 ]
24
25 def check_simple_policy_tuples do
26 has_strings =
27 Config.get([:mrf_simple])
28 |> Enum.any?(fn {_, v} -> Enum.any?(v, &is_binary/1) end)
29
30 if has_strings do
31 Logger.warn("""
32 !!!DEPRECATION WARNING!!!
33 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
35 ```
36 config :pleroma, :mrf_simple,
37 media_removal: ["instance.tld"],
38 media_nsfw: ["instance.tld"],
39 federated_timeline_removal: ["instance.tld"],
40 report_removal: ["instance.tld"],
41 reject: ["instance.tld"],
42 followers_only: ["instance.tld"],
43 accept: ["instance.tld"],
44 avatar_removal: ["instance.tld"],
45 banner_removal: ["instance.tld"],
46 reject_deletes: ["instance.tld"]
47 ```
48
49 Is now
50
51
52 ```
53 config :pleroma, :mrf_simple,
54 media_removal: [{"instance.tld", "Reason for media removal"}],
55 media_nsfw: [{"instance.tld", "Reason for media nsfw"}],
56 federated_timeline_removal: [{"instance.tld", "Reason for federated timeline removal"}],
57 report_removal: [{"instance.tld", "Reason for report removal"}],
58 reject: [{"instance.tld", "Reason for reject"}],
59 followers_only: [{"instance.tld", "Reason for followers only"}],
60 accept: [{"instance.tld", "Reason for accept"}],
61 avatar_removal: [{"instance.tld", "Reason for avatar removal"}],
62 banner_removal: [{"instance.tld", "Reason for banner removal"}],
63 reject_deletes: [{"instance.tld", "Reason for reject deletes"}]
64 ```
65 """)
66
67 new_config =
68 Config.get([:mrf_simple])
69 |> Enum.map(fn {k, v} ->
70 {k,
71 Enum.map(v, fn
72 {instance, reason} -> {instance, reason}
73 instance -> {instance, ""}
74 end)}
75 end)
76
77 Config.put([:mrf_simple], new_config)
78
79 :error
80 else
81 :ok
82 end
83 end
84
85 def check_quarantined_instances_tuples do
86 has_strings = Config.get([:instance, :quarantined_instances], []) |> Enum.any?(&is_binary/1)
87
88 if has_strings do
89 Logger.warn("""
90 !!!DEPRECATION WARNING!!!
91 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
93 ```
94 config :pleroma, :instance,
95 quarantined_instances: ["instance.tld"]
96 ```
97
98 Is now
99
100
101 ```
102 config :pleroma, :instance,
103 quarantined_instances: [{"instance.tld", "Reason for quarantine"}]
104 ```
105 """)
106
107 new_config =
108 Config.get([:instance, :quarantined_instances])
109 |> Enum.map(fn
110 {instance, reason} -> {instance, reason}
111 instance -> {instance, ""}
112 end)
113
114 Config.put([:instance, :quarantined_instances], new_config)
115
116 :error
117 else
118 :ok
119 end
120 end
121
122 def check_transparency_exclusions_tuples do
123 has_strings = Config.get([:mrf, :transparency_exclusions]) |> Enum.any?(&is_binary/1)
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 [
174 check_hellthread_threshold(),
175 check_old_mrf_config(),
176 check_media_proxy_whitelist_config(),
177 check_welcome_message_config(),
178 check_activity_expiration_config(),
179 check_remote_ip_plug_name(),
180 check_uploders_s3_public_endpoint(),
181 check_quarantined_instances_tuples(),
182 check_transparency_exclusions_tuples(),
183 check_simple_policy_tuples()
184 ]
185 |> Enum.reduce(:ok, fn
186 :ok, :ok -> :ok
187 _, _ -> :error
188 end)
189 end
190
191 def check_welcome_message_config do
192 instance_config = Pleroma.Config.get([:instance])
193
194 use_old_config =
195 Keyword.has_key?(instance_config, :welcome_user_nickname) or
196 Keyword.has_key?(instance_config, :welcome_message)
197
198 if use_old_config do
199 Logger.error("""
200 !!!DEPRECATION WARNING!!!
201 Your config is using the old namespace for Welcome messages configuration. You need to convert to the new namespace. e.g.,
202 \n* `config :pleroma, :instance, welcome_user_nickname` and `config :pleroma, :instance, welcome_message` are now equal to:
203 \n* `config :pleroma, :welcome, direct_message: [enabled: true, sender_nickname: "NICKNAME", message: "Your welcome message"]`"
204 """)
205
206 :error
207 else
208 :ok
209 end
210 end
211
212 def check_old_mrf_config do
213 warning_preface = """
214 !!!DEPRECATION WARNING!!!
215 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 """
217
218 move_namespace_and_warn(@mrf_config_map, warning_preface)
219 end
220
221 @spec move_namespace_and_warn([config_map()], String.t()) :: :ok | nil
222 def move_namespace_and_warn(config_map, warning_preface) do
223 warning =
224 Enum.reduce(config_map, "", fn
225 {old, new, err_msg}, acc ->
226 old_config = Config.get(old)
227
228 if old_config do
229 Config.put(new, old_config)
230 acc <> err_msg
231 else
232 acc
233 end
234 end)
235
236 if warning == "" do
237 :ok
238 else
239 Logger.warn(warning_preface <> warning)
240 :error
241 end
242 end
243
244 @spec check_media_proxy_whitelist_config() :: :ok | nil
245 def check_media_proxy_whitelist_config do
246 whitelist = Config.get([:media_proxy, :whitelist])
247
248 if Enum.any?(whitelist, &(not String.starts_with?(&1, "http"))) do
249 Logger.warn("""
250 !!!DEPRECATION WARNING!!!
251 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.
252 """)
253
254 :error
255 else
256 :ok
257 end
258 end
259
260 @spec check_activity_expiration_config() :: :ok | nil
261 def check_activity_expiration_config do
262 warning_preface = """
263 !!!DEPRECATION WARNING!!!
264 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 """
266
267 move_namespace_and_warn(
268 [
269 {Pleroma.ActivityExpiration, Pleroma.Workers.PurgeExpiredActivity,
270 "\n* `config :pleroma, Pleroma.ActivityExpiration` is now `config :pleroma, Pleroma.Workers.PurgeExpiredActivity`"}
271 ],
272 warning_preface
273 )
274 end
275
276 @spec check_remote_ip_plug_name() :: :ok | nil
277 def check_remote_ip_plug_name do
278 warning_preface = """
279 !!!DEPRECATION WARNING!!!
280 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 """
282
283 move_namespace_and_warn(
284 [
285 {Pleroma.Plugs.RemoteIp, Pleroma.Web.Plugs.RemoteIp,
286 "\n* `config :pleroma, Pleroma.Plugs.RemoteIp` is now `config :pleroma, Pleroma.Web.Plugs.RemoteIp`"}
287 ],
288 warning_preface
289 )
290 end
291
292 @spec check_uploders_s3_public_endpoint() :: :ok | nil
293 def check_uploders_s3_public_endpoint do
294 s3_config = Pleroma.Config.get([Pleroma.Uploaders.S3])
295
296 use_old_config = Keyword.has_key?(s3_config, :public_endpoint)
297
298 if use_old_config do
299 Logger.error("""
300 !!!DEPRECATION WARNING!!!
301 Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket.\n
302 Please make the following change at your earliest convenience.\n
303 \n* `config :pleroma, Pleroma.Uploaders.S3, public_endpoint` is now equal to:
304 \n* `config :pleroma, Pleroma.Upload, base_url`
305 """)
306
307 :error
308 else
309 :ok
310 end
311 end
312 end