Merge branch 'fix/get_report_with_notes' into 'develop'

Permit fetching individual reports with notes preloaded

See merge request pleroma/pleroma!3118
This commit is contained in:
Haelwenn 2020-11-03 01:00:12 +00:00
commit 0d8cc0905a
3 changed files with 23 additions and 1 deletions

View file

@ -14,6 +14,7 @@ defmodule Pleroma.Activity do
alias Pleroma.ReportNote alias Pleroma.ReportNote
alias Pleroma.ThreadMute alias Pleroma.ThreadMute
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
import Ecto.Changeset import Ecto.Changeset
import Ecto.Query import Ecto.Query
@ -153,6 +154,18 @@ defmodule Pleroma.Activity do
def get_bookmark(_, _), do: nil def get_bookmark(_, _), do: nil
def get_report(activity_id) do
opts = %{
type: "Flag",
skip_preload: true,
preload_report_notes: true
}
ActivityPub.fetch_activities_query([], opts)
|> where(id: ^activity_id)
|> Repo.one()
end
def change(struct, params \\ %{}) do def change(struct, params \\ %{}) do
struct struct
|> cast(params, [:data, :recipients]) |> cast(params, [:data, :recipients])

View file

@ -38,7 +38,7 @@ defmodule Pleroma.Web.AdminAPI.ReportController do
end end
def show(conn, %{id: id}) do def show(conn, %{id: id}) do
with %Activity{} = report <- Activity.get_by_id(id) do with %Activity{} = report <- Activity.get_report(id) do
render(conn, "show.json", Report.extract_report_info(report)) render(conn, "show.json", Report.extract_report_info(report))
else else
_ -> {:error, :not_found} _ -> {:error, :not_found}

View file

@ -37,12 +37,21 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
status_ids: [activity.id] status_ids: [activity.id]
}) })
conn
|> put_req_header("content-type", "application/json")
|> post("/api/pleroma/admin/reports/#{report_id}/notes", %{
content: "this is an admin note"
})
response = response =
conn conn
|> get("/api/pleroma/admin/reports/#{report_id}") |> get("/api/pleroma/admin/reports/#{report_id}")
|> json_response_and_validate_schema(:ok) |> json_response_and_validate_schema(:ok)
assert response["id"] == report_id assert response["id"] == report_id
[notes] = response["notes"]
assert notes["content"] == "this is an admin note"
end end
test "returns 404 when report id is invalid", %{conn: conn} do test "returns 404 when report id is invalid", %{conn: conn} do