From 2b341627da5d592bdedc66a331409f5228ab28cf Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Mon, 25 Nov 2019 00:04:29 +0900 Subject: [PATCH] Admin API: Render whole status in grouped reports --- CHANGELOG.md | 1 + lib/pleroma/web/activity_pub/utils.ex | 23 ++++++++++++++++++----- lib/pleroma/web/admin_api/views/report_view.ex | 8 +++++++- test/web/admin_api/admin_api_controller_test.exs | 16 +++++----------- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bd835a3d..443e5f3c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Mastodon API: `pleroma.thread_muted` to the Status entity - Mastodon API: Mark the direct conversation as read for the author when they send a new direct message - Mastodon API, streaming: Add `pleroma.direct_conversation_id` to the `conversation` stream event payload. +- Admin API: Render whole status in grouped reports ### Added diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index c45662359..277ca3c7c 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -822,20 +822,33 @@ defmodule Pleroma.Web.ActivityPub.Utils do reports = get_reports_by_status_id(activity["id"]) max_date = Enum.max_by(reports, &NaiveDateTime.from_iso8601!(&1.data["published"])) actors = Enum.map(reports, & &1.user_actor) + {deleted, status} = get_status_data(activity) %{ date: max_date.data["published"], account: activity["actor"], - status: %{ - id: activity["id"], - content: activity["content"], - published: activity["published"] - }, + status: status, + status_deleted: deleted, actors: Enum.uniq(actors), reports: reports } end + defp get_status_data(activity) do + case Activity.get_by_ap_id(activity["id"]) do + %Activity{} = act -> + {false, act} + + _ -> + {true, + %{ + id: activity["id"], + content: activity["content"], + published: activity["published"] + }} + end + end + def get_reports_by_status_id(ap_id) do from(a in Activity, where: fragment("(?)->>'type' = 'Flag'", a.data), diff --git a/lib/pleroma/web/admin_api/views/report_view.ex b/lib/pleroma/web/admin_api/views/report_view.ex index ca88595c7..0ba94def9 100644 --- a/lib/pleroma/web/admin_api/views/report_view.ex +++ b/lib/pleroma/web/admin_api/views/report_view.ex @@ -45,10 +45,16 @@ defmodule Pleroma.Web.AdminAPI.ReportView do def render("index_grouped.json", %{groups: groups}) do reports = Enum.map(groups, fn group -> + status = + if group[:status_deleted], + do: group[:status], + else: StatusView.render("show.json", %{activity: group[:status]}) + %{ date: group[:date], account: group[:account], - status: group[:status], + status: status, + status_deleted: status_deleted, actors: Enum.map(group[:actors], &merge_account_views/1), reports: group[:reports] diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 3a4c4d65c..ea1b4c48c 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -15,6 +15,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do alias Pleroma.UserInviteToken alias Pleroma.Web.ActivityPub.Relay alias Pleroma.Web.CommonAPI + alias Pleroma.Web.MastodonAPI.StatusView alias Pleroma.Web.MediaProxy import Pleroma.Factory @@ -1616,14 +1617,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do assert length(response["reports"]) == 3 - first_group = - Enum.find(response["reports"], &(&1["status"]["id"] == first_status.data["id"])) + first_group = Enum.find(response["reports"], &(&1["status"]["id"] == first_status.id)) - second_group = - Enum.find(response["reports"], &(&1["status"]["id"] == second_status.data["id"])) + second_group = Enum.find(response["reports"], &(&1["status"]["id"] == second_status.id)) - third_group = - Enum.find(response["reports"], &(&1["status"]["id"] == third_status.data["id"])) + third_group = Enum.find(response["reports"], &(&1["status"]["id"] == third_status.id)) assert length(first_group["reports"]) == 3 assert length(second_group["reports"]) == 2 @@ -1634,11 +1632,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do NaiveDateTime.from_iso8601!(act.data["published"]) end).data["published"] - assert first_group["status"] == %{ - "id" => first_status.data["id"], - "content" => first_status.object.data["content"], - "published" => first_status.object.data["published"] - } + assert first_group["status"] == StatusView.render("show.json", %{activity: first_status}) assert first_group["account"]["id"] == target_user.id