Browse Source

Return total for reports

object-id-column
Maxim Filippov 4 years ago
parent
commit
af746fa4a8
5 changed files with 15 additions and 6 deletions
  1. +2
    -1
      CHANGELOG.md
  2. +1
    -0
      docs/api/admin_api.md
  3. +2
    -4
      lib/pleroma/web/admin_api/admin_api_controller.ex
  4. +2
    -1
      lib/pleroma/web/admin_api/views/report_view.ex
  5. +8
    -0
      test/web/admin_api/admin_api_controller_test.exs

+ 2
- 1
CHANGELOG.md View File

@@ -21,7 +21,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Mastodon API: Unsubscribe followers when they unfollow a user
- AdminAPI: Add "godmode" while fetching user statuses (i.e. admin can see private statuses)
- Improve digest email template
– Pagination: (optional) return `total` alongside with `items` when paginating
- Pagination: (optional) return `total` alongside with `items` when paginating
- Admin API: Return `total` when querying for reports

### Fixed
- Following from Osada


+ 1
- 0
docs/api/admin_api.md View File

@@ -313,6 +313,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret

```json
{
"total" : 1,
"reports": [
{
"account": {


+ 2
- 4
lib/pleroma/web/admin_api/admin_api_controller.ex View File

@@ -442,11 +442,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
params
|> Map.put("type", "Flag")
|> Map.put("skip_preload", true)
|> Map.put("total", true)

reports =
[]
|> ActivityPub.fetch_activities(params)
|> Enum.reverse()
reports = ActivityPub.fetch_activities([], params)

conn
|> put_view(ReportView)


+ 2
- 1
lib/pleroma/web/admin_api/views/report_view.ex View File

@@ -12,7 +12,8 @@ defmodule Pleroma.Web.AdminAPI.ReportView do

def render("index.json", %{reports: reports}) do
%{
reports: render_many(reports, __MODULE__, "show.json", as: :report)
reports: render_many(reports[:items], __MODULE__, "show.json", as: :report),
total: reports[:total]
}
end



+ 8
- 0
test/web/admin_api/admin_api_controller_test.exs View File

@@ -1309,6 +1309,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|> json_response(:ok)

assert Enum.empty?(response["reports"])
assert response["total"] == 0
end

test "returns reports", %{conn: conn} do
@@ -1331,6 +1332,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do

assert length(response["reports"]) == 1
assert report["id"] == report_id

assert response["total"] == 1
end

test "returns reports with specified state", %{conn: conn} do
@@ -1364,6 +1367,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert length(response["reports"]) == 1
assert open_report["id"] == first_report_id

assert response["total"] == 1

response =
conn
|> get("/api/pleroma/admin/reports", %{
@@ -1376,6 +1381,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert length(response["reports"]) == 1
assert closed_report["id"] == second_report_id

assert response["total"] == 1

response =
conn
|> get("/api/pleroma/admin/reports", %{
@@ -1384,6 +1391,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|> json_response(:ok)

assert Enum.empty?(response["reports"])
assert response["total"] == 0
end

test "returns 403 when requested by a non-admin" do


Loading…
Cancel
Save