From 744b34709db9c11767a9bc57fe0bb21c96e826c7 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 30 Dec 2020 14:22:48 -0600 Subject: [PATCH 1/3] Do not reverse order of reports. We want newest ones sorted to the top. --- lib/pleroma/web/admin_api/views/report_view.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/pleroma/web/admin_api/views/report_view.ex b/lib/pleroma/web/admin_api/views/report_view.ex index 535556370..da949e306 100644 --- a/lib/pleroma/web/admin_api/views/report_view.ex +++ b/lib/pleroma/web/admin_api/views/report_view.ex @@ -19,8 +19,7 @@ defmodule Pleroma.Web.AdminAPI.ReportView do reports: reports[:items] |> Enum.map(&Report.extract_report_info/1) - |> Enum.map(&render(__MODULE__, "show.json", &1)) - |> Enum.reverse(), + |> Enum.map(&render(__MODULE__, "show.json", &1)), total: reports[:total] } end From e4791258d4483cd9dad6016ec453e6ca7ea10d73 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 31 Dec 2020 10:53:18 -0600 Subject: [PATCH 2/3] Ensure newest report is returned first in the list --- .../web/admin_api/views/report_view_test.exs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/pleroma/web/admin_api/views/report_view_test.exs b/test/pleroma/web/admin_api/views/report_view_test.exs index ff3453208..3914751b5 100644 --- a/test/pleroma/web/admin_api/views/report_view_test.exs +++ b/test/pleroma/web/admin_api/views/report_view_test.exs @@ -143,4 +143,29 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do assert %{} = ReportView.render("show.json", Report.extract_report_info(activity)) end + + test "reports are ordered newest first" do + user = insert(:user) + other_user = insert(:user) + + {:ok, report1} = + CommonAPI.report(user, %{ + account_id: other_user.id, + comment: "first report" + }) + + {:ok, report2} = + CommonAPI.report(user, %{ + account_id: other_user.id, + comment: "second report" + }) + + %{reports: rendered} = + ReportView.render("index.json", + reports: Pleroma.Web.ActivityPub.Utils.get_reports(%{}, 1, 50) + ) + + assert report2.id == rendered |> Enum.at(0) |> Map.get(:id) + assert report1.id == rendered |> Enum.at(1) |> Map.get(:id) + end end From 83d97ab98e99a16d0ba25a57df1be182dfb9b938 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 31 Dec 2020 13:15:44 -0600 Subject: [PATCH 3/3] Document reports ordering change --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1604ab3a..77959c415 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - **Breaking:** Changed `mix pleroma.user toggle_confirmed` to `mix pleroma.user confirm` - Search: When using Postgres 11+, Pleroma will use the `websearch_to_tsvector` function to parse search queries. - Emoji: Support the full Unicode 13.1 set of Emoji for reactions, plus regional indicators. +- Admin API: Reports now ordered by newest ### Added