From 2b341627da5d592bdedc66a331409f5228ab28cf Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Mon, 25 Nov 2019 00:04:29 +0900 Subject: [PATCH 1/7] Admin API: Render whole status in grouped reports --- CHANGELOG.md | 1 + lib/pleroma/web/activity_pub/utils.ex | 23 +++++++++++++++---- .../web/admin_api/views/report_view.ex | 8 ++++++- .../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 @@ def parse_report_group(activity) 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 @@ def render("show.json", %{report: report, user: user, account: account, statuses 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 @@ test "returns reports grouped by status", %{ 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 @@ test "returns reports grouped by status", %{ 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 From 40059c9b1e404412da103aaf74333bec364d3099 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Mon, 25 Nov 2019 00:05:52 +0900 Subject: [PATCH 2/7] Typo --- lib/pleroma/web/admin_api/views/report_view.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/admin_api/views/report_view.ex b/lib/pleroma/web/admin_api/views/report_view.ex index 0ba94def9..45ce75272 100644 --- a/lib/pleroma/web/admin_api/views/report_view.ex +++ b/lib/pleroma/web/admin_api/views/report_view.ex @@ -54,7 +54,7 @@ def render("index_grouped.json", %{groups: groups}) do date: group[:date], account: group[:account], status: status, - status_deleted: status_deleted, + status_deleted: group[:status_deleted], actors: Enum.map(group[:actors], &merge_account_views/1), reports: group[:reports] From 1364d303f8e4dcd4d9f7913d4755c58b0f4b87ef Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Mon, 25 Nov 2019 01:39:35 +0900 Subject: [PATCH 3/7] AdminAPI: Fix grouped reports for closed/resolved reports --- lib/pleroma/web/activity_pub/utils.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 277ca3c7c..9e460b604 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -852,7 +852,8 @@ defp get_status_data(activity) do def get_reports_by_status_id(ap_id) do from(a in Activity, where: fragment("(?)->>'type' = 'Flag'", a.data), - where: fragment("(?)->'object' @> ?", a.data, ^[%{id: ap_id}]) + where: fragment("(?)->'object' @> ?", a.data, ^[%{id: ap_id}]), + or_where: fragment("(?)->'object' @> ?", a.data, ^[ap_id]) ) |> Activity.with_preloaded_user_actor() |> Repo.all() From b3b4e5ca805780f278b6239973d6d497b1697fbd Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Fri, 22 Nov 2019 13:35:21 +0900 Subject: [PATCH 4/7] AdminAPI: Grouped reports old/new fix If some status received reports both in the "new" format and "old" format it was considered reports on two different statuses (in the context of grouped reports) --- CHANGELOG.md | 1 + lib/pleroma/web/activity_pub/utils.ex | 78 ++++++++++++++------------- test/web/activity_pub/utils_test.exs | 43 --------------- 3 files changed, 41 insertions(+), 81 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 443e5f3c3..60512c6b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Mastodon API: Fix private and direct statuses not being filtered out from the public timeline for an authenticated user (`GET /api/v1/timelines/public`) - Mastodon API: Inability to get some local users by nickname in `/api/v1/accounts/:id_or_nickname` +- AdminAPI: If some status received reports both in the "new" format and "old" format it was considered reports on two different statuses (in the context of grouped reports) ## [1.1.6] - 2019-11-19 diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 9e460b604..718e3328d 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -788,36 +788,6 @@ def get_reports(params, page, page_size) do ActivityPub.fetch_activities([], params, :offset) end - @spec get_reports_grouped_by_status(%{required(:activity) => String.t()}) :: %{ - required(:groups) => [ - %{ - required(:date) => String.t(), - required(:account) => %{}, - required(:status) => %{}, - required(:actors) => [%User{}], - required(:reports) => [%Activity{}] - } - ], - required(:total) => integer - } - def get_reports_grouped_by_status(groups) do - parsed_groups = - groups - |> Enum.map(fn entry -> - activity = - case Jason.decode(entry.activity) do - {:ok, activity} -> activity - _ -> build_flag_object(entry.activity) - end - - parse_report_group(activity) - end) - - %{ - groups: parsed_groups - } - end - def parse_report_group(activity) do reports = get_reports_by_status_id(activity["id"]) max_date = Enum.max_by(reports, &NaiveDateTime.from_iso8601!(&1.data["published"])) @@ -859,6 +829,32 @@ def get_reports_by_status_id(ap_id) do |> Repo.all() end + @spec get_reports_grouped_by_status(%{required(:activity) => String.t()}) :: %{ + required(:groups) => [ + %{ + required(:date) => String.t(), + required(:account) => %{}, + required(:status) => %{}, + required(:actors) => [%User{}], + required(:reports) => [%Activity{}] + } + ], + required(:total) => integer + } + def get_reports_grouped_by_status(activity_ids) do + parsed_groups = + activity_ids + |> Enum.map(fn id -> + id + |> build_flag_object() + |> parse_report_group() + end) + + %{ + groups: parsed_groups + } + end + @spec get_reported_activities() :: [ %{ required(:activity) => String.t(), @@ -866,17 +862,23 @@ def get_reports_by_status_id(ap_id) do } ] def get_reported_activities do - from(a in Activity, - where: fragment("(?)->>'type' = 'Flag'", a.data), + reported_activities_query = + from(a in Activity, + where: fragment("(?)->>'type' = 'Flag'", a.data), + select: %{ + activity: fragment("jsonb_array_elements((? #- '{object,0}')->'object')", a.data) + }, + group_by: fragment("activity") + ) + + from(a in subquery(reported_activities_query), + distinct: true, select: %{ - date: fragment("max(?->>'published') date", a.data), - activity: - fragment("jsonb_array_elements_text((? #- '{object,0}')->'object') activity", a.data) - }, - group_by: fragment("activity"), - order_by: fragment("date DESC") + id: fragment("COALESCE(?->>'id'::text, ? #>> '{}')", a.activity, a.activity) + } ) |> Repo.all() + |> Enum.map(& &1.id) end def update_report_state(%Activity{} = activity, state) diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs index 1feb076ba..586eb1d2f 100644 --- a/test/web/activity_pub/utils_test.exs +++ b/test/web/activity_pub/utils_test.exs @@ -636,47 +636,4 @@ test "removes actor from announcements" do assert updated_object.data["announcement_count"] == 1 end end - - describe "get_reports_grouped_by_status/1" do - setup do - [reporter, target_user] = insert_pair(:user) - first_status = insert(:note_activity, user: target_user) - second_status = insert(:note_activity, user: target_user) - - CommonAPI.report(reporter, %{ - "account_id" => target_user.id, - "comment" => "I feel offended", - "status_ids" => [first_status.id] - }) - - CommonAPI.report(reporter, %{ - "account_id" => target_user.id, - "comment" => "I feel offended2", - "status_ids" => [second_status.id] - }) - - data = [%{activity: first_status.data["id"]}, %{activity: second_status.data["id"]}] - - {:ok, - %{ - first_status: first_status, - second_status: second_status, - data: data - }} - end - - test "works for deprecated reports format", %{ - first_status: first_status, - second_status: second_status, - data: data - } do - groups = Utils.get_reports_grouped_by_status(data).groups - - first_group = Enum.find(groups, &(&1.status.id == first_status.data["id"])) - second_group = Enum.find(groups, &(&1.status.id == second_status.data["id"])) - - assert first_group.status.id == first_status.data["id"] - assert second_group.status.id == second_status.data["id"] - end - end end From 5869a43fe722c878fca1d87816cd1437f2bb49fe Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Tue, 26 Nov 2019 01:06:54 +0900 Subject: [PATCH 5/7] Fix tests --- test/support/helpers.ex | 17 +++++++++++++++++ .../admin_api/admin_api_controller_test.exs | 19 +++++++------------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/test/support/helpers.ex b/test/support/helpers.ex index ce39dd9d8..af2b2eddf 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -75,6 +75,23 @@ def render_json(view, template, assigns) do |> Poison.decode!() end + def stringify_keys(nil), do: nil + + def stringify_keys(key) when key in [true, false], do: key + def stringify_keys(key) when is_atom(key), do: Atom.to_string(key) + + def stringify_keys(map) when is_map(map) do + map + |> Enum.map(fn {k, v} -> {stringify_keys(k), stringify_keys(v)} end) + |> Enum.into(%{}) + end + + def stringify_keys([head | rest] = list) when is_list(list) do + [stringify_keys(head) | stringify_keys(rest)] + end + + def stringify_keys(key), do: key + defmacro guards_config(config_path) do quote do initial_setting = Pleroma.Config.get(config_path) diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 12dba7773..c6ff1a065 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -1654,9 +1654,10 @@ test "returns reports grouped by status", %{ NaiveDateTime.from_iso8601!(act.data["published"]) end).data["published"] - assert first_group["status"] == StatusView.render("show.json", %{activity: first_status}) + assert first_group["status"] == + stringify_keys(StatusView.render("show.json", %{activity: first_status})) - assert first_group["account"]["id"] == target_user.id + assert(first_group["account"]["id"] == target_user.id) assert length(first_group["actors"]) == 1 assert hd(first_group["actors"])["id"] == reporter.id @@ -1669,11 +1670,8 @@ test "returns reports grouped by status", %{ NaiveDateTime.from_iso8601!(act.data["published"]) end).data["published"] - assert second_group["status"] == %{ - "id" => second_status.data["id"], - "content" => second_status.object.data["content"], - "published" => second_status.object.data["published"] - } + assert second_group["status"] == + stringify_keys(StatusView.render("show.json", %{activity: second_status})) assert second_group["account"]["id"] == target_user.id @@ -1688,11 +1686,8 @@ test "returns reports grouped by status", %{ NaiveDateTime.from_iso8601!(act.data["published"]) end).data["published"] - assert third_group["status"] == %{ - "id" => third_status.data["id"], - "content" => third_status.object.data["content"], - "published" => third_status.object.data["published"] - } + assert third_group["status"] == + stringify_keys(StatusView.render("show.json", %{activity: third_status})) assert third_group["account"]["id"] == target_user.id From 5135656f579954cf786011b539934c7150e0d0bc Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Wed, 27 Nov 2019 22:54:12 +0900 Subject: [PATCH 6/7] Handle reopened reports with deleted statuses --- lib/pleroma/web/activity_pub/utils.ex | 50 ++++++++------- .../web/admin_api/views/report_view.ex | 11 ++-- .../admin_api/admin_api_controller_test.exs | 64 ++++++++++++++++++- 3 files changed, 93 insertions(+), 32 deletions(-) diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 962f02a05..d91abf7b3 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -722,16 +722,22 @@ defp build_flag_object(act) when is_map(act) or is_binary(act) do act when is_binary(act) -> act end - activity = Activity.get_by_ap_id_with_object(id) - actor = User.get_by_ap_id(activity.object.data["actor"]) + case Activity.get_by_ap_id_with_object(id) do + %Activity{} = activity -> + %{ + "type" => "Note", + "id" => activity.data["id"], + "content" => activity.object.data["content"], + "published" => activity.object.data["published"], + "actor" => + AccountView.render("show.json", %{ + user: User.get_by_ap_id(activity.object.data["actor"]) + }) + } - %{ - "type" => "Note", - "id" => activity.data["id"], - "content" => activity.object.data["content"], - "published" => activity.object.data["published"], - "actor" => AccountView.render("show.json", %{user: actor}) - } + _ -> + %{"id" => id, "deleted" => true} + end end defp build_flag_object(_), do: [] @@ -792,30 +798,27 @@ def parse_report_group(activity) 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) + status = get_status_data(activity) %{ date: max_date.data["published"], account: activity["actor"], 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} + defp get_status_data(status) do + case status["deleted"] do + true -> + %{ + "id" => status["id"], + "deleted" => true + } _ -> - {true, - %{ - id: activity["id"], - content: activity["content"], - published: activity["published"] - }} + Activity.get_by_ap_id(status["id"]) end end @@ -829,7 +832,7 @@ def get_reports_by_status_id(ap_id) do |> Repo.all() end - @spec get_reports_grouped_by_status(%{required(:activity) => String.t()}) :: %{ + @spec get_reports_grouped_by_status([String.t()]) :: %{ required(:groups) => [ %{ required(:date) => String.t(), @@ -838,8 +841,7 @@ def get_reports_by_status_id(ap_id) do required(:actors) => [%User{}], required(:reports) => [%Activity{}] } - ], - required(:total) => integer + ] } def get_reports_grouped_by_status(activity_ids) do parsed_groups = diff --git a/lib/pleroma/web/admin_api/views/report_view.ex b/lib/pleroma/web/admin_api/views/report_view.ex index 45ce75272..13602efd9 100644 --- a/lib/pleroma/web/admin_api/views/report_view.ex +++ b/lib/pleroma/web/admin_api/views/report_view.ex @@ -4,6 +4,7 @@ defmodule Pleroma.Web.AdminAPI.ReportView do use Pleroma.Web, :view + alias Pleroma.Activity alias Pleroma.HTML alias Pleroma.User alias Pleroma.Web.AdminAPI.Report @@ -46,15 +47,15 @@ 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]}) + case group.status do + %Activity{} = activity -> StatusView.render("show.json", %{activity: activity}) + _ -> group.status + end %{ date: group[:date], account: group[:account], - status: status, - status_deleted: group[:status_deleted], + status: Map.put_new(status, "deleted", false), 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 c6ff1a065..a69fadcdc 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -1613,6 +1613,7 @@ test "returns 403 when requested by anonymous" do first_status: Activity.get_by_ap_id_with_object(first_status.data["id"]), second_status: Activity.get_by_ap_id_with_object(second_status.data["id"]), third_status: Activity.get_by_ap_id_with_object(third_status.data["id"]), + first_report: first_report, first_status_reports: [first_report, second_report, third_report], second_status_reports: [first_report, second_report], third_status_reports: [first_report], @@ -1655,7 +1656,11 @@ test "returns reports grouped by status", %{ end).data["published"] assert first_group["status"] == - stringify_keys(StatusView.render("show.json", %{activity: first_status})) + Map.put( + stringify_keys(StatusView.render("show.json", %{activity: first_status})), + "deleted", + false + ) assert(first_group["account"]["id"] == target_user.id) @@ -1671,7 +1676,11 @@ test "returns reports grouped by status", %{ end).data["published"] assert second_group["status"] == - stringify_keys(StatusView.render("show.json", %{activity: second_status})) + Map.put( + stringify_keys(StatusView.render("show.json", %{activity: second_status})), + "deleted", + false + ) assert second_group["account"]["id"] == target_user.id @@ -1687,7 +1696,11 @@ test "returns reports grouped by status", %{ end).data["published"] assert third_group["status"] == - stringify_keys(StatusView.render("show.json", %{activity: third_status})) + Map.put( + stringify_keys(StatusView.render("show.json", %{activity: third_status})), + "deleted", + false + ) assert third_group["account"]["id"] == target_user.id @@ -1697,6 +1710,51 @@ test "returns reports grouped by status", %{ assert Enum.map(third_group["reports"], & &1["id"]) -- Enum.map(third_status_reports, & &1.id) == [] end + + test "reopened report renders status data", %{ + conn: conn, + first_report: first_report, + first_status: first_status + } do + {:ok, _} = CommonAPI.update_report_state(first_report.id, "resolved") + + response = + conn + |> get("/api/pleroma/admin/grouped_reports") + |> json_response(:ok) + + first_group = Enum.find(response["reports"], &(&1["status"]["id"] == first_status.id)) + + assert first_group["status"] == + Map.put( + stringify_keys(StatusView.render("show.json", %{activity: first_status})), + "deleted", + false + ) + end + + test "reopened report does not render status data if status has been deleted", %{ + conn: conn, + first_report: first_report, + first_status: first_status, + target_user: target_user + } do + {:ok, _} = CommonAPI.update_report_state(first_report.id, "resolved") + {:ok, _} = CommonAPI.delete(first_status.id, target_user) + + refute Activity.get_by_ap_id(first_status.id) + + response = + conn + |> get("/api/pleroma/admin/grouped_reports") + |> json_response(:ok) + + assert Enum.find(response["reports"], &(&1["status"]["deleted"] == true))["status"][ + "deleted" + ] == true + + assert length(Enum.filter(response["reports"], &(&1["status"]["deleted"] == false))) == 2 + end end describe "POST /api/pleroma/admin/reports/:id/respond" do From fcabcab4430b0aa075243bf98630d67c79f3ef9b Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Thu, 28 Nov 2019 00:09:00 +0900 Subject: [PATCH 7/7] Fetch account from report, not from status (it might be deleted) --- lib/pleroma/web/activity_pub/utils.ex | 9 ++++++++- .../web/admin_api/admin_api_controller.ex | 4 ++-- .../admin_api/admin_api_controller_test.exs | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index d91abf7b3..2ca805c09 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -798,11 +798,18 @@ def parse_report_group(activity) 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) + [%{data: %{"object" => [account_id | _]}} | _] = reports + + account = + AccountView.render("show.json", %{ + user: User.get_by_ap_id(account_id) + }) + status = get_status_data(activity) %{ date: max_date.data["published"], - account: activity["actor"], + account: account, status: status, actors: Enum.uniq(actors), reports: reports diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 24fdc3c82..b003d1f35 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -647,11 +647,11 @@ def list_reports(conn, params) do end def list_grouped_reports(conn, _params) do - reports = Utils.get_reported_activities() + statuses = Utils.get_reported_activities() conn |> put_view(ReportView) - |> render("index_grouped.json", Utils.get_reports_grouped_by_status(reports)) + |> render("index_grouped.json", Utils.get_reports_grouped_by_status(statuses)) end def report_show(conn, %{"id" => id}) do diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index a69fadcdc..108baad91 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -1755,6 +1755,25 @@ test "reopened report does not render status data if status has been deleted", % assert length(Enum.filter(response["reports"], &(&1["status"]["deleted"] == false))) == 2 end + + test "account not empty if status was deleted", %{ + conn: conn, + first_report: first_report, + first_status: first_status, + target_user: target_user + } do + {:ok, _} = CommonAPI.update_report_state(first_report.id, "resolved") + {:ok, _} = CommonAPI.delete(first_status.id, target_user) + + refute Activity.get_by_ap_id(first_status.id) + + response = + conn + |> get("/api/pleroma/admin/grouped_reports") + |> json_response(:ok) + + assert Enum.find(response["reports"], &(&1["status"]["deleted"] == true))["account"] + end end describe "POST /api/pleroma/admin/reports/:id/respond" do