mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-25 15:39:19 +00:00
added total
to the instance adminAPI endpoint
This commit is contained in:
parent
6806c03e85
commit
d4158e8bf0
|
@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- **Breaking:** AdminAPI changed User field `approval_pending` to `is_approved`
|
- **Breaking:** AdminAPI changed User field `approval_pending` to `is_approved`
|
||||||
- **Breaking**: AdminAPI changed User field `deactivated` to `is_active`
|
- **Breaking**: AdminAPI changed User field `deactivated` to `is_active`
|
||||||
- **Breaking:** AdminAPI `GET /api/pleroma/admin/users/:nickname_or_id/statuses` changed response format and added the number of total users posts.
|
- **Breaking:** AdminAPI `GET /api/pleroma/admin/users/:nickname_or_id/statuses` changed response format and added the number of total users posts.
|
||||||
|
- **Breaking:** AdminAPI `GET /api/pleroma/admin/instances/:instance/statuses` changed response format and added the number of total users posts.
|
||||||
- Admin API: Reports now ordered by newest
|
- Admin API: Reports now ordered by newest
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
|
@ -311,7 +311,18 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
||||||
- *optional* `with_reblogs`: `true`/`false` – allows to see reblogs (default is false)
|
- *optional* `with_reblogs`: `true`/`false` – allows to see reblogs (default is false)
|
||||||
- Response:
|
- Response:
|
||||||
- On failure: `Not found`
|
- On failure: `Not found`
|
||||||
- On success: JSON array of instance's latest statuses
|
- On success: JSON, where:
|
||||||
|
- `total`: total count of the statuses for the instance
|
||||||
|
- `activities`: list of the statuses for the instance
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"total" : 1,
|
||||||
|
"activities": [
|
||||||
|
// activities list
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## `GET /api/pleroma/admin/statuses`
|
## `GET /api/pleroma/admin/statuses`
|
||||||
|
|
||||||
|
|
|
@ -632,7 +632,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
|> fetch_activities(params, pagination_type)
|
|> fetch_activities(params, pagination_type)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fetch_statuses(reading_user, %{total: true} = params) do
|
||||||
|
result = fetch_activities_for_reading_user(reading_user, params)
|
||||||
|
Keyword.put(result, :items, Enum.reverse(result[:items]))
|
||||||
|
end
|
||||||
|
|
||||||
def fetch_statuses(reading_user, params) do
|
def fetch_statuses(reading_user, params) do
|
||||||
|
reading_user
|
||||||
|
|> fetch_activities_for_reading_user(params)
|
||||||
|
|> Enum.reverse()
|
||||||
|
end
|
||||||
|
|
||||||
|
defp fetch_activities_for_reading_user(reading_user, params) do
|
||||||
params = Map.put(params, :type, ["Create", "Announce"])
|
params = Map.put(params, :type, ["Create", "Announce"])
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
@ -641,7 +652,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
}
|
}
|
||||||
|> user_activities_recipients()
|
|> user_activities_recipients()
|
||||||
|> fetch_activities(params, :offset)
|
|> fetch_activities(params, :offset)
|
||||||
|> Enum.reverse()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp user_activities_recipients(%{godmode: true}), do: []
|
defp user_activities_recipients(%{godmode: true}), do: []
|
||||||
|
|
|
@ -85,17 +85,18 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
||||||
with_reblogs = params["with_reblogs"] == "true" || params["with_reblogs"] == true
|
with_reblogs = params["with_reblogs"] == "true" || params["with_reblogs"] == true
|
||||||
{page, page_size} = page_params(params)
|
{page, page_size} = page_params(params)
|
||||||
|
|
||||||
activities =
|
result =
|
||||||
ActivityPub.fetch_statuses(nil, %{
|
ActivityPub.fetch_statuses(nil, %{
|
||||||
instance: instance,
|
instance: instance,
|
||||||
limit: page_size,
|
limit: page_size,
|
||||||
offset: (page - 1) * page_size,
|
offset: (page - 1) * page_size,
|
||||||
exclude_reblogs: not with_reblogs
|
exclude_reblogs: not with_reblogs,
|
||||||
|
total: true
|
||||||
})
|
})
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_view(AdminAPI.StatusView)
|
|> put_view(AdminAPI.StatusView)
|
||||||
|> render("index.json", %{activities: activities, as: :activity})
|
|> render("index.json", %{total: result[:total], activities: result[:items], as: :activity})
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_user_statuses(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname} = params) do
|
def list_user_statuses(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname} = params) do
|
||||||
|
|
|
@ -864,33 +864,30 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
||||||
insert_pair(:note_activity, user: user)
|
insert_pair(:note_activity, user: user)
|
||||||
activity = insert(:note_activity, user: user2)
|
activity = insert(:note_activity, user: user2)
|
||||||
|
|
||||||
ret_conn = get(conn, "/api/pleroma/admin/instances/archae.me/statuses")
|
%{"total" => 2, "activities" => activities} =
|
||||||
|
conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
|
||||||
|
|
||||||
response = json_response(ret_conn, 200)
|
assert length(activities) == 2
|
||||||
|
|
||||||
assert length(response) == 2
|
%{"total" => 1, "activities" => [_]} =
|
||||||
|
conn |> get("/api/pleroma/admin/instances/test.com/statuses") |> json_response(200)
|
||||||
|
|
||||||
ret_conn = get(conn, "/api/pleroma/admin/instances/test.com/statuses")
|
%{"total" => 0, "activities" => []} =
|
||||||
|
conn |> get("/api/pleroma/admin/instances/nonexistent.com/statuses") |> json_response(200)
|
||||||
response = json_response(ret_conn, 200)
|
|
||||||
|
|
||||||
assert length(response) == 1
|
|
||||||
|
|
||||||
ret_conn = get(conn, "/api/pleroma/admin/instances/nonexistent.com/statuses")
|
|
||||||
|
|
||||||
response = json_response(ret_conn, 200)
|
|
||||||
|
|
||||||
assert Enum.empty?(response)
|
|
||||||
|
|
||||||
CommonAPI.repeat(activity.id, user)
|
CommonAPI.repeat(activity.id, user)
|
||||||
|
|
||||||
ret_conn = get(conn, "/api/pleroma/admin/instances/archae.me/statuses")
|
%{"total" => 2, "activities" => activities} =
|
||||||
response = json_response(ret_conn, 200)
|
conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
|
||||||
assert length(response) == 2
|
|
||||||
|
|
||||||
ret_conn = get(conn, "/api/pleroma/admin/instances/archae.me/statuses?with_reblogs=true")
|
assert length(activities) == 2
|
||||||
response = json_response(ret_conn, 200)
|
|
||||||
assert length(response) == 3
|
%{"total" => 3, "activities" => activities} =
|
||||||
|
conn
|
||||||
|
|> get("/api/pleroma/admin/instances/archae.me/statuses?with_reblogs=true")
|
||||||
|
|> json_response(200)
|
||||||
|
|
||||||
|
assert length(activities) == 3
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue