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