Merge branch 'strip-fix' into 'develop'

Strip fix

See merge request pleroma/pleroma!3981
This commit is contained in:
lain 2023-11-27 15:30:13 +00:00
commit 2b839197a9
3 changed files with 42 additions and 3 deletions

View file

@ -0,0 +1 @@
Fix #strip_report_status_data

View file

@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
alias Ecto.UUID alias Ecto.UUID
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Config alias Pleroma.Config
alias Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectID
alias Pleroma.Maps alias Pleroma.Maps
alias Pleroma.Notification alias Pleroma.Notification
alias Pleroma.Object alias Pleroma.Object
@ -852,9 +853,11 @@ defmodule Pleroma.Web.ActivityPub.Utils do
[actor | reported_activities] = activity.data["object"] [actor | reported_activities] = activity.data["object"]
stripped_activities = stripped_activities =
Enum.map(reported_activities, fn Enum.reduce(reported_activities, [], fn act, acc ->
act when is_map(act) -> act["id"] case ObjectID.cast(act) do
act when is_binary(act) -> act {:ok, act} -> [act | acc]
_ -> acc
end
end) end)
new_data = put_in(activity.data, ["object"], [actor | stripped_activities]) new_data = put_in(activity.data, ["object"], [actor | stripped_activities])

View file

@ -16,6 +16,41 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
require Pleroma.Constants require Pleroma.Constants
describe "strip_report_status_data/1" do
test "does not break on issues with the reported activites" do
reporter = insert(:user)
target_account = insert(:user)
{:ok, activity} = CommonAPI.post(target_account, %{status: "foobar"})
context = Utils.generate_context_id()
content = "foobar"
post_id = activity.data["id"]
res =
Utils.make_flag_data(
%{
actor: reporter,
context: context,
account: target_account,
statuses: [%{"id" => post_id}],
content: content
},
%{}
)
res =
res
|> Map.put("object", res["object"] ++ [nil, 1, 5, "123"])
{:ok, activity} = Pleroma.Web.ActivityPub.ActivityPub.insert(res)
[user_id, object | _] = activity.data["object"]
{:ok, stripped} = Utils.strip_report_status_data(activity)
assert stripped.data["object"] == [user_id, object["id"]]
end
end
describe "fetch the latest Follow" do describe "fetch the latest Follow" do
test "fetches the latest Follow activity" do test "fetches the latest Follow activity" do
%Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity) %Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity)