Admin API: Render whole status in grouped reports
authorMaxim Filippov <colixer@gmail.com>
Sun, 24 Nov 2019 15:04:29 +0000 (00:04 +0900)
committerMaxim Filippov <colixer@gmail.com>
Sun, 24 Nov 2019 15:04:29 +0000 (00:04 +0900)
CHANGELOG.md
lib/pleroma/web/activity_pub/utils.ex
lib/pleroma/web/admin_api/views/report_view.ex
test/web/admin_api/admin_api_controller_test.exs

index 6bd835a3da592d27b776ccb772ca484454d967b7..443e5f3c3b6e3aeab59efde60dc5c0a630dab72e 100644 (file)
@@ -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
 </details>
 
 ### Added
index c456623596b372c91084c06adde6ffb259592579..277ca3c7cfe32826550d2a776288efdc652aeb2b 100644 (file)
@@ -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),
index ca88595c722054c4cb1155aca19aea52c5bb1584..0ba94def9a6d73f4177d3ea983ac79009a4e2bc4 100644 (file)
@@ -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]
index 3a4c4d65c9e118bc9426798f7041354b4c2e8606..ea1b4c48cc098344fe273e4a097062997847f156 100644 (file)
@@ -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