Apply 1 suggestion(s) to 1 file(s)
[akkoma] / lib / pleroma / config / deprecation_warnings.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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()]
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 end
30 end
31
32 def mrf_user_allowlist do
33 config = Config.get(:mrf_user_allowlist)
34
35 if config && Enum.any?(config, fn {k, _} -> is_atom(k) end) do
36 rewritten =
37 Enum.reduce(Config.get(:mrf_user_allowlist), Map.new(), fn {k, v}, acc ->
38 Map.put(acc, to_string(k), v)
39 end)
40
41 Config.put(:mrf_user_allowlist, rewritten)
42
43 Logger.error("""
44 !!!DEPRECATION WARNING!!!
45 As of Pleroma 2.0.7, the `mrf_user_allowlist` setting changed of format.
46 Pleroma 2.1 will remove support for the old format. Please change your configuration to match this:
47
48 config :pleroma, :mrf_user_allowlist, #{inspect(rewritten, pretty: true)}
49 """)
50 end
51 end
52
53 def warn do
54 check_hellthread_threshold()
55 mrf_user_allowlist()
56 check_old_mrf_config()
57 check_media_proxy_whitelist_config()
58 check_welcome_message_config()
59 end
60
61 def check_welcome_message_config do
62 instance_config = Pleroma.Config.get([:instance])
63
64 use_old_config =
65 Keyword.has_key?(instance_config, :welcome_user_nickname) or
66 Keyword.has_key?(instance_config, :welcome_message)
67
68 if use_old_config do
69 Logger.error("""
70 !!!DEPRECATION WARNING!!!
71 Your config is using the old namespace for Welcome messages configuration. You need to change to the new namespace:
72 \n* `config :pleroma, :instance, welcome_user_nickname` is now `config :pleroma, :welcome, :direct_message, :sender_nickname`
73 \n* `config :pleroma, :instance, welcome_message` is now `config :pleroma, :welcome, :direct_message, :message`
74 """)
75 end
76 end
77
78 def check_old_mrf_config do
79 warning_preface = """
80 !!!DEPRECATION WARNING!!!
81 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:
82 """
83
84 move_namespace_and_warn(@mrf_config_map, warning_preface)
85 end
86
87 @spec move_namespace_and_warn([config_map()], String.t()) :: :ok | nil
88 def move_namespace_and_warn(config_map, warning_preface) do
89 warning =
90 Enum.reduce(config_map, "", fn
91 {old, new, err_msg}, acc ->
92 old_config = Config.get(old)
93
94 if old_config do
95 Config.put(new, old_config)
96 acc <> err_msg
97 else
98 acc
99 end
100 end)
101
102 if warning != "" do
103 Logger.warn(warning_preface <> warning)
104 end
105 end
106
107 @spec check_media_proxy_whitelist_config() :: :ok | nil
108 def check_media_proxy_whitelist_config do
109 whitelist = Config.get([:media_proxy, :whitelist])
110
111 if Enum.any?(whitelist, &(not String.starts_with?(&1, "http"))) do
112 Logger.warn("""
113 !!!DEPRECATION WARNING!!!
114 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.
115 """)
116 end
117 end
118 end