Compare commits

...

7 commits

Author SHA1 Message Date
Alex Gleason 2d1d5dfd6e Merge branch 'mrf-tuples-fix' into 'develop'
SimplePolicy reasons: handle legacy config

See merge request pleroma/pleroma!3615
2024-04-22 21:02:24 +00:00
lain 50af909c01 Merge branch 'pleroma-card-image-description' into 'develop'
Include image description in status media cards

See merge request pleroma/pleroma!4101
2024-04-19 07:39:05 +00:00
marcin mikołajczak 6f6bede900 Include image description in status media cards
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-04-19 10:20:31 +04:00
lain 87b8ac3ce6 Merge branch 'receiverworker-error-handling' into 'develop'
ReceiverWorker: Make sure non-{:ok, _} is returned as {:error, …}

See merge request pleroma/pleroma!4100
2024-04-19 06:04:44 +00:00
Haelwenn (lanodan) Monnier a299ddb10e
ReceiverWorker: Make sure non-{:ok, _} is returned as {:error, …}
Otherwise an error like `{:signature, {:error, {:error, :not_found}}}` ends up considered a success.
2024-04-17 07:43:47 +02:00
Alex Gleason acfded5ae8
MRF reasons: normalize config for backwards compatibility 2022-01-22 15:53:08 -06:00
Alex Gleason e72fd4ceb6
SimplePolicy reasons: handle legacy config 2022-01-22 14:32:55 -06:00
10 changed files with 73 additions and 5 deletions

View file

@ -0,0 +1 @@
Include image description in status media cards

View file

@ -0,0 +1 @@
ReceiverWorker: Make sure non-{:ok, _} is returned as {:error, …}

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.ActivityPub.MRF do
require Logger
import Pleroma.Web.Utils.Guards, only: [not_empty_string: 1]
@behaviour Pleroma.Web.ActivityPub.MRF.PipelineFiltering
@ -158,7 +159,20 @@ defmodule Pleroma.Web.ActivityPub.MRF do
@spec instance_list_from_tuples([{String.t(), String.t()}]) :: [String.t()]
def instance_list_from_tuples(list) do
Enum.map(list, fn {instance, _} -> instance end)
Enum.map(list, fn
{instance, _} -> instance
instance when is_binary(instance) -> instance
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

View file

@ -264,13 +264,14 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
mrf_simple_excluded =
Config.get(:mrf_simple)
|> Enum.map(fn {rule, instances} ->
instances = MRF.normalize_instance_list(instances)
{rule, Enum.reject(instances, fn {host, _} -> host in exclusions end)}
end)
mrf_simple =
mrf_simple_excluded
|> Enum.map(fn {rule, instances} ->
{rule, Enum.map(instances, fn {host, _} -> host end)}
{rule, MRF.instance_list_from_tuples(instances)}
end)
|> Map.new()

View file

@ -58,6 +58,10 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
format: :uri,
description: "Preview thumbnail"
},
image_description: %Schema{
type: :string,
description: "Alternate text that describes what is in the thumbnail"
},
title: %Schema{type: :string, description: "Title of linked resource"},
description: %Schema{type: :string, description: "Description of preview"}
}

View file

@ -589,6 +589,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
provider_url: page_url_data.scheme <> "://" <> page_url_data.host,
url: page_url,
image: image_url,
image_description: rich_media["image:alt"] || "",
title: rich_media["title"] || "",
description: rich_media["description"] || "",
pleroma: %{

View file

@ -52,7 +52,8 @@ defmodule Pleroma.Workers.ReceiverWorker do
{:error, {:reject, reason}} -> {:cancel, reason}
{:signature, false} -> {:cancel, :invalid_signature}
{:error, {:error, reason = "Object has been deleted"}} -> {:cancel, reason}
e -> e
{:error, _} = e -> e
e -> {:error, e}
end
end
end

View file

@ -81,11 +81,27 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
assert MRF.instance_list_from_tuples(list) == expected
end
test "it handles legacy config" do
list = [{"some.tld", "a reason"}, "other.tld"]
expected = ["some.tld", "other.tld"]
assert MRF.instance_list_from_tuples(list) == expected
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
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 = %{
mrf_policies: ["NoOpPolicy", "HashtagPolicy"],
@ -116,6 +132,32 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
{:ok, ^expected} = MRF.describe()
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
test "config_descriptions/0" do

View file

@ -1717,6 +1717,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
card_data = %{
"image" => "http://ia.media-imdb.com/images/rock.jpg",
"image_description" => "",
"provider_name" => "example.com",
"provider_url" => "https://example.com",
"title" => "The Rock",
@ -1770,6 +1771,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
"title" => "Pleroma",
"description" => "",
"image" => nil,
"image_description" => "",
"provider_name" => "example.com",
"provider_url" => "https://example.com",
"url" => "https://example.com/ogp-missing-data",

View file

@ -773,6 +773,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
page_url = "http://example.com"
card = %{
"image:alt" => "Example image description",
url: page_url,
site_name: "Example site name",
title: "Example website",
@ -780,7 +781,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
description: "Example description"
}
%{provider_name: "example.com"} =
%{provider_name: "example.com", image_description: "Example image description"} =
StatusView.render("card.json", %{page_url: page_url, rich_media: card})
end