mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-06-01 08:28:06 +00:00
MRF reasons: normalize config for backwards compatibility
This commit is contained in:
parent
e72fd4ceb6
commit
acfded5ae8
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF do
|
defmodule Pleroma.Web.ActivityPub.MRF do
|
||||||
require Logger
|
require Logger
|
||||||
|
import Pleroma.Web.Utils.Guards, only: [not_empty_string: 1]
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.PipelineFiltering
|
@behaviour Pleroma.Web.ActivityPub.MRF.PipelineFiltering
|
||||||
|
|
||||||
|
@ -110,6 +111,16 @@ defmodule Pleroma.Web.ActivityPub.MRF do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec normalize_instance_list(list()) :: [{String.t(), String.t()}]
|
||||||
|
def normalize_instance_list(list) do
|
||||||
|
Enum.map(list, fn
|
||||||
|
{host, reason} when not_empty_string(host) and not_empty_string(reason) -> {host, reason}
|
||||||
|
{host, _reason} when not_empty_string(host) -> {host, ""}
|
||||||
|
host when not_empty_string(host) -> {host, ""}
|
||||||
|
value -> raise "Invalid MRF config: #{inspect(value)}"
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
def describe(policies) do
|
def describe(policies) do
|
||||||
{:ok, policy_configs} =
|
{:ok, policy_configs} =
|
||||||
policies
|
policies
|
||||||
|
|
|
@ -263,13 +263,14 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
|
||||||
mrf_simple_excluded =
|
mrf_simple_excluded =
|
||||||
Config.get(:mrf_simple)
|
Config.get(:mrf_simple)
|
||||||
|> Enum.map(fn {rule, instances} ->
|
|> Enum.map(fn {rule, instances} ->
|
||||||
|
instances = MRF.normalize_instance_list(instances)
|
||||||
{rule, Enum.reject(instances, fn {host, _} -> host in exclusions end)}
|
{rule, Enum.reject(instances, fn {host, _} -> host in exclusions end)}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
mrf_simple =
|
mrf_simple =
|
||||||
mrf_simple_excluded
|
mrf_simple_excluded
|
||||||
|> Enum.map(fn {rule, instances} ->
|
|> Enum.map(fn {rule, instances} ->
|
||||||
{rule, Enum.map(instances, fn {host, _} -> host end)}
|
{rule, MRF.instance_list_from_tuples(instances)}
|
||||||
end)
|
end)
|
||||||
|> Map.new()
|
|> Map.new()
|
||||||
|
|
||||||
|
|
|
@ -79,9 +79,18 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "normalize_instance_list/1" do
|
||||||
|
test "returns a list of tuples" do
|
||||||
|
list = [{"some.tld", "a reason"}, "other.tld"]
|
||||||
|
expected = [{"some.tld", "a reason"}, {"other.tld", ""}]
|
||||||
|
|
||||||
|
assert MRF.normalize_instance_list(list) == expected
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "describe/0" do
|
describe "describe/0" do
|
||||||
test "it works as expected with noop policy" do
|
test "it works as expected with noop policy" do
|
||||||
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.NoOpPolicy])
|
clear_config([:mrf, :policies], [MRF.NoOpPolicy])
|
||||||
|
|
||||||
expected = %{
|
expected = %{
|
||||||
mrf_policies: ["NoOpPolicy", "HashtagPolicy"],
|
mrf_policies: ["NoOpPolicy", "HashtagPolicy"],
|
||||||
|
@ -112,6 +121,32 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
||||||
|
|
||||||
{:ok, ^expected} = MRF.describe()
|
{:ok, ^expected} = MRF.describe()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it works as expected with SimplePolicy" do
|
||||||
|
clear_config([:mrf, :policies], [MRF.SimplePolicy])
|
||||||
|
clear_config([:mrf_simple, :reject], [{"lain.com", "2kool4skool"}, "othersite.xyz"])
|
||||||
|
|
||||||
|
expected = %{
|
||||||
|
exclusions: false,
|
||||||
|
mrf_hashtag: %{federated_timeline_removal: [], reject: [], sensitive: ["nsfw"]},
|
||||||
|
mrf_policies: ["SimplePolicy", "HashtagPolicy"],
|
||||||
|
mrf_simple: %{
|
||||||
|
accept: [],
|
||||||
|
avatar_removal: [],
|
||||||
|
banner_removal: [],
|
||||||
|
federated_timeline_removal: [],
|
||||||
|
followers_only: [],
|
||||||
|
media_nsfw: [],
|
||||||
|
media_removal: [],
|
||||||
|
reject: ["lain.com", "othersite.xyz"],
|
||||||
|
reject_deletes: [],
|
||||||
|
report_removal: []
|
||||||
|
},
|
||||||
|
mrf_simple_info: %{reject: %{"lain.com" => %{"reason" => "2kool4skool"}}}
|
||||||
|
}
|
||||||
|
|
||||||
|
{:ok, ^expected} = MRF.describe()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "config_descriptions/0" do
|
test "config_descriptions/0" do
|
||||||
|
|
Loading…
Reference in a new issue