Fix report api

This commit is contained in:
tusooa 2022-11-20 00:35:52 -05:00
parent a69e9ae2ef
commit 0e0c316c76
No known key found for this signature in database
GPG Key ID: 7B467EDE43A08224
3 changed files with 46 additions and 2 deletions

View File

@ -695,6 +695,11 @@ defmodule Pleroma.Web.ActivityPub.Utils do
Enum.map(statuses || [], &build_flag_object/1)
end
defp build_flag_object(%Activity{} = activity) do
object = Object.normalize(activity, fetch: false)
build_flag_object(object)
end
defp build_flag_object(%Object{data: data}) do
actor = User.get_by_ap_id(data["actor"])
id = data["id"]

View File

@ -18,9 +18,11 @@ defmodule Pleroma.Web.AdminAPI.Report do
|> Enum.reject(&is_nil(&1))
|> Enum.map(fn
act when is_map(act) ->
Activity.get_create_by_object_ap_id_with_object(act["id"]) ||
Activity.get_by_ap_id_with_object(act["id"]) || make_fake_activity(act, user)
act when is_binary(act) ->
Activity.get_create_by_object_ap_id_with_object(act) ||
Activity.get_by_ap_id_with_object(act)
end)

View File

@ -5,6 +5,8 @@
defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
use Pleroma.Web.ConnCase, async: true
alias Pleroma.Activity
alias Pleroma.Repo
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
@ -27,6 +29,41 @@ defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|> json_response_and_validate_schema(200)
end
test "submit a report with a fake Create", %{
conn: conn
} do
target_user = insert(:user)
note = insert(:note, user: target_user)
activity_params = %{
"object" => note.data["id"],
"actor" => note.data["actor"],
"to" => note.data["to"] || [],
"cc" => note.data["cc"] || [],
"type" => "Create"
}
{:ok, fake_activity} =
Repo.insert(%Activity{
data: activity_params,
recipients: activity_params["to"] ++ activity_params["cc"],
local: true,
actor: activity_params["actor"]
})
assert %{"action_taken" => false, "id" => _} =
conn
|> put_req_header("content-type", "application/json")
|> post("/api/v1/reports", %{
"account_id" => target_user.id,
"status_ids" => [fake_activity.id],
"comment" => "bad status!",
"forward" => "false"
})
|> json_response_and_validate_schema(200)
end
test "submit a report with statuses and comment", %{
conn: conn,
target_user: target_user,