InstanceView: Omit comment if it's empty
This commit is contained in:
parent
656c4368d3
commit
e91bb2144d
2 changed files with 24 additions and 3 deletions
|
|
@ -123,12 +123,17 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
||||||
host in exclusions or not Map.has_key?(@block_severities, rule)
|
host in exclusions or not Map.has_key?(@block_severities, rule)
|
||||||
end)
|
end)
|
||||||
|> Enum.map(fn {host, reason} ->
|
|> Enum.map(fn {host, reason} ->
|
||||||
%{
|
domain_block = %{
|
||||||
domain: host,
|
domain: host,
|
||||||
digest: :crypto.hash(:sha256, host) |> Base.encode16(case: :lower),
|
digest: :crypto.hash(:sha256, host) |> Base.encode16(case: :lower),
|
||||||
severity: Map.get(@block_severities, rule),
|
severity: Map.get(@block_severities, rule)
|
||||||
comment: reason
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if not_empty_string(reason) do
|
||||||
|
Map.put(domain_block, :comment, reason)
|
||||||
|
else
|
||||||
|
domain_block
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|> List.flatten()
|
|> List.flatten()
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,22 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
||||||
] == json_response_and_validate_schema(conn, 200)
|
] == json_response_and_validate_schema(conn, 200)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "omits comment field if comment is empty", %{conn: conn} do
|
||||||
|
clear_config([:mrf_simple, :reject], ["fediverse.pl"])
|
||||||
|
|
||||||
|
conn = get(conn, "/api/v1/instance/domain_blocks")
|
||||||
|
|
||||||
|
assert [
|
||||||
|
%{
|
||||||
|
"digest" => "55e3f44aefe7eb022d3b1daaf7396cabf7f181bf6093c8ea841e30c9fc7d8226",
|
||||||
|
"domain" => "fediverse.pl",
|
||||||
|
"severity" => "suspend"
|
||||||
|
} = domain_block
|
||||||
|
] = json_response_and_validate_schema(conn, 200)
|
||||||
|
|
||||||
|
refute Map.has_key?(domain_block, "comment")
|
||||||
|
end
|
||||||
|
|
||||||
test "returns empty array if mrf transparency is disabled", %{conn: conn} do
|
test "returns empty array if mrf transparency is disabled", %{conn: conn} do
|
||||||
clear_config([:mrf, :transparency], false)
|
clear_config([:mrf, :transparency], false)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue