Fix report api
This commit is contained in:
parent
a69e9ae2ef
commit
0e0c316c76
@ -695,6 +695,11 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||||||
Enum.map(statuses || [], &build_flag_object/1)
|
Enum.map(statuses || [], &build_flag_object/1)
|
||||||
end
|
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
|
defp build_flag_object(%Object{data: data}) do
|
||||||
actor = User.get_by_ap_id(data["actor"])
|
actor = User.get_by_ap_id(data["actor"])
|
||||||
id = data["id"]
|
id = data["id"]
|
||||||
|
@ -18,10 +18,12 @@ defmodule Pleroma.Web.AdminAPI.Report do
|
|||||||
|> Enum.reject(&is_nil(&1))
|
|> Enum.reject(&is_nil(&1))
|
||||||
|> Enum.map(fn
|
|> Enum.map(fn
|
||||||
act when is_map(act) ->
|
act when is_map(act) ->
|
||||||
Activity.get_by_ap_id_with_object(act["id"]) || make_fake_activity(act, user)
|
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) ->
|
act when is_binary(act) ->
|
||||||
Activity.get_by_ap_id_with_object(act)
|
Activity.get_create_by_object_ap_id_with_object(act) ||
|
||||||
|
Activity.get_by_ap_id_with_object(act)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
%{report: report, user: user, account: account, statuses: statuses}
|
%{report: report, user: user, account: account, statuses: statuses}
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|
defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|
||||||
use Pleroma.Web.ConnCase, async: true
|
use Pleroma.Web.ConnCase, async: true
|
||||||
|
|
||||||
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Repo
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
@ -27,6 +29,41 @@ defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|
|||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
end
|
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", %{
|
test "submit a report with statuses and comment", %{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
target_user: target_user,
|
target_user: target_user,
|
||||||
|
Loading…
Reference in New Issue
Block a user