Improve readability

This commit is contained in:
Egor Kislitsyn 2021-02-04 17:23:21 +04:00 committed by Haelwenn (lanodan) Monnier
parent ee26f2c91b
commit ad09bdb376
No known key found for this signature in database
GPG Key ID: D5B7A8E43C997DEE
6 changed files with 33 additions and 29 deletions

View File

@ -23,7 +23,7 @@ defmodule Pleroma.Config.DeprecationWarnings do
def check_simple_policy_tuples do def check_simple_policy_tuples do
has_strings = has_strings =
Config.get([:mrf_simple]) Config.get([:mrf_simple])
|> Enum.any?(fn {_, v} -> Enum.any?(v, fn e -> is_binary(e) end) end) |> Enum.any?(fn {_, v} -> Enum.any?(v, &is_binary/1) end)
if has_strings do if has_strings do
Logger.warn(""" Logger.warn("""
@ -81,8 +81,7 @@ def check_simple_policy_tuples do
end end
def check_quarantined_instances_tuples do def check_quarantined_instances_tuples do
has_strings = has_strings = Config.get([:instance, :quarantined_instances]) |> Enum.any?(&is_binary/1)
Config.get([:instance, :quarantined_instances]) |> Enum.any?(fn e -> is_binary(e) end)
if has_strings do if has_strings do
Logger.warn(""" Logger.warn("""
@ -119,8 +118,7 @@ def check_quarantined_instances_tuples do
end end
def check_transparency_exclusions_tuples do def check_transparency_exclusions_tuples do
has_strings = has_strings = Config.get([:mrf, :transparency_exclusions]) |> Enum.any?(&is_binary/1)
Config.get([:mrf, :transparency_exclusions]) |> Enum.any?(fn e -> is_binary(e) end)
if has_strings do if has_strings do
Logger.warn(""" Logger.warn("""

View File

@ -47,7 +47,7 @@ def filter(object), do: {:ok, object}
@impl true @impl true
def describe, def describe,
do: {:ok, %{mrf_rejectnonpublic: Config.get(:mrf_rejectnonpublic) |> Enum.into(%{})}} do: {:ok, %{mrf_rejectnonpublic: Config.get(:mrf_rejectnonpublic) |> Map.new()}}
@impl true @impl true
def config_description do def config_description do

View File

@ -262,14 +262,16 @@ def describe do
mrf_simple_excluded = mrf_simple_excluded =
Config.get(:mrf_simple) Config.get(:mrf_simple)
|> Enum.map(fn {k, v} -> {k, Enum.reject(v, fn {v, _} -> v in exclusions end)} end) |> Enum.map(fn {rule, instances} ->
{rule, Enum.reject(instances, fn {host, _} -> host in exclusions end)}
end)
mrf_simple = mrf_simple =
mrf_simple_excluded mrf_simple_excluded
|> Enum.map(fn {k, v} -> |> Enum.map(fn {rule, instances} ->
{k, Enum.map(v, fn {instance, _} -> instance end)} {rule, Enum.map(instances, fn {host, _} -> host end)}
end) end)
|> Enum.into(%{}) |> Map.new()
# This is for backwards compatibility. We originally didn't sent # This is for backwards compatibility. We originally didn't sent
# extra info like a reason why an instance was rejected/quarantined/etc. # extra info like a reason why an instance was rejected/quarantined/etc.
@ -277,12 +279,19 @@ def describe do
# to add an extra "info" key. # to add an extra "info" key.
mrf_simple_info = mrf_simple_info =
mrf_simple_excluded mrf_simple_excluded
|> Enum.map(fn {k, v} -> {k, Enum.reject(v, fn {_, reason} -> reason == "" end)} end) |> Enum.map(fn {rule, instances} ->
|> Enum.reject(fn {_, v} -> v == [] end) {rule, Enum.reject(instances, fn {_, reason} -> reason == "" end)}
|> Enum.map(fn {k, l} ->
{k, l |> Enum.map(fn {i, r} -> {i, %{"reason" => r}} end) |> Enum.into(%{})}
end) end)
|> Enum.into(%{}) |> Enum.reject(fn {_, instances} -> instances == [] end)
|> Enum.map(fn {rule, instances} ->
instances =
instances
|> Enum.map(fn {host, reason} -> {host, %{"reason" => reason}} end)
|> Map.new()
{rule, instances}
end)
|> Map.new()
{:ok, %{mrf_simple: mrf_simple, mrf_simple_info: mrf_simple_info}} {:ok, %{mrf_simple: mrf_simple, mrf_simple_info: mrf_simple_info}}
end end

View File

@ -37,7 +37,7 @@ def filter(object), do: {:ok, object}
def describe do def describe do
mrf_user_allowlist = mrf_user_allowlist =
Config.get([:mrf_user_allowlist], []) Config.get([:mrf_user_allowlist], [])
|> Enum.into(%{}, fn {k, v} -> {k, length(v)} end) |> Map.new(fn {k, v} -> {k, length(v)} end)
{:ok, %{mrf_user_allowlist: mrf_user_allowlist}} {:ok, %{mrf_user_allowlist: mrf_user_allowlist}}
end end

View File

@ -39,7 +39,7 @@ def filter(message), do: {:ok, message}
@impl true @impl true
def describe, def describe,
do: {:ok, %{mrf_vocabulary: Pleroma.Config.get(:mrf_vocabulary) |> Enum.into(%{})}} do: {:ok, %{mrf_vocabulary: Pleroma.Config.get(:mrf_vocabulary) |> Map.new()}}
@impl true @impl true
def config_description do def config_description do

View File

@ -95,22 +95,19 @@ def federation do
{:ok, data} = MRF.describe() {:ok, data} = MRF.describe()
data data
|> Map.merge(%{ |> Map.put(
quarantined_instances: :quarantined_instances,
quarantined Enum.map(quarantined, fn {instance, _reason} -> instance end)
|> Enum.map(fn {instance, _reason} -> instance end) )
})
# This is for backwards compatibility. We originally didn't sent # This is for backwards compatibility. We originally didn't sent
# extra info like a reason why an instance was rejected/quarantined/etc. # extra info like a reason why an instance was rejected/quarantined/etc.
# Because we didn't want to break backwards compatibility it was decided # Because we didn't want to break backwards compatibility it was decided
# to add an extra "info" key. # to add an extra "info" key.
|> Map.merge(%{ |> Map.put(:quarantined_instances_info, %{
quarantined_instances_info: %{ "quarantined_instances" =>
"quarantined_instances" => quarantined
quarantined |> Enum.map(fn {instance, reason} -> {instance, %{"reason" => reason}} end)
|> Enum.map(fn {instance, reason} -> {instance, %{"reason" => reason}} end) |> Map.new()
|> Enum.into(%{})
}
}) })
else else
%{} %{}