diff options
Diffstat (limited to 'lib/pleroma')
4 files changed, 89 insertions, 9 deletions
diff --git a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex index 839ac1a8d..1970f96f7 100644 --- a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex @@ -81,16 +81,18 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do action_fallback(AdminAPI.FallbackController) + defp truthy_param?(value), do: value in ["true", true] + def list_instance_statuses(conn, %{"instance" => instance} = params) do - with_reblogs = params["with_reblogs"] == "true" || params["with_reblogs"] == true {page, page_size} = page_params(params) result = ActivityPub.fetch_statuses(nil, %{ instance: instance, limit: page_size, + godmode: truthy_param?(params["godmode"]), offset: (page - 1) * page_size, - exclude_reblogs: not with_reblogs, + exclude_reblogs: not truthy_param?(params["with_reblogs"]), total: true }) @@ -100,9 +102,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do end def list_user_statuses(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname} = params) do - with_reblogs = params["with_reblogs"] == "true" || params["with_reblogs"] == true - godmode = params["godmode"] == "true" || params["godmode"] == true - with %User{} = user <- User.get_cached_by_nickname_or_id(nickname, for: admin) do {page, page_size} = page_params(params) @@ -110,8 +109,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do ActivityPub.fetch_user_activities(user, nil, %{ limit: page_size, offset: (page - 1) * page_size, - godmode: godmode, - exclude_reblogs: not with_reblogs, + godmode: truthy_param?(params["godmode"]), + exclude_reblogs: not truthy_param?(params["with_reblogs"]), pagination_type: :offset, total: true }) diff --git a/lib/pleroma/web/admin_api/controllers/status_controller.ex b/lib/pleroma/web/admin_api/controllers/status_controller.ex index 7058def82..4e8dbf77b 100644 --- a/lib/pleroma/web/admin_api/controllers/status_controller.ex +++ b/lib/pleroma/web/admin_api/controllers/status_controller.ex @@ -15,7 +15,11 @@ defmodule Pleroma.Web.AdminAPI.StatusController do require Logger plug(Pleroma.Web.ApiSpec.CastAndValidate) - plug(OAuthScopesPlug, %{scopes: ["admin:read:statuses"]} when action in [:index, :show]) + + plug( + OAuthScopesPlug, + %{scopes: ["admin:read:statuses"]} when action in [:index, :index2, :show] + ) plug( OAuthScopesPlug, @@ -39,6 +43,20 @@ defmodule Pleroma.Web.AdminAPI.StatusController do render(conn, "index.json", activities: activities, as: :activity) end + def index2(%{assigns: %{user: _admin}} = conn, params) do + result = + ActivityPub.fetch_statuses(nil, %{ + godmode: params.godmode, + local_only: params.local_only, + limit: params.page_size, + offset: (params.page - 1) * params.page_size, + exclude_reblogs: not params.with_reblogs, + total: true + }) + + render(conn, "index.json", %{total: result[:total], activities: result[:items], as: :activity}) + end + def show(conn, %{id: id}) do with %Activity{} = activity <- Activity.get_by_id(id) do render(conn, "show.json", %{activity: activity}) diff --git a/lib/pleroma/web/api_spec/operations/admin/status_operation.ex b/lib/pleroma/web/api_spec/operations/admin/status_operation.ex index d25ab5247..3943a5235 100644 --- a/lib/pleroma/web/api_spec/operations/admin/status_operation.ex +++ b/lib/pleroma/web/api_spec/operations/admin/status_operation.ex @@ -22,8 +22,10 @@ defmodule Pleroma.Web.ApiSpec.Admin.StatusOperation do def index_operation do %Operation{ tags: ["Status administration"], + description: + "Use [/api/v2/pleroma/admin/statuses](#operation/AdminAPI.StatusController.index2) to get response with `total` field.", operationId: "AdminAPI.StatusController.index", - summary: "Get all statuses", + summary: "Get all statuses (without total)", security: [%{"oAuth" => ["admin:read:statuses"]}], parameters: [ Operation.parameter( @@ -68,6 +70,61 @@ defmodule Pleroma.Web.ApiSpec.Admin.StatusOperation do } end + def index2_operation do + %Operation{ + tags: ["Status administration"], + operationId: "AdminAPI.StatusController.index2", + summary: "Get all statuses", + security: [%{"oAuth" => ["admin:read:statuses"]}], + parameters: [ + Operation.parameter( + :godmode, + :query, + %Schema{type: :boolean, default: false}, + "Allows to see private statuses" + ), + Operation.parameter( + :local_only, + :query, + %Schema{type: :boolean, default: false}, + "Excludes remote statuses" + ), + Operation.parameter( + :with_reblogs, + :query, + %Schema{type: :boolean, default: false}, + "Allows to see reblogs" + ), + Operation.parameter( + :page, + :query, + %Schema{type: :integer, default: 1}, + "Page" + ), + Operation.parameter( + :page_size, + :query, + %Schema{type: :integer, default: 50}, + "Number of statuses to return" + ) + | admin_api_params() + ], + responses: %{ + 200 => + Operation.response("Response", "application/json", %Schema{ + type: :object, + properties: %{ + total: %Schema{type: :integer}, + reports: %Schema{ + type: :array, + items: status() + } + } + }) + } + } + end + def show_operation do %Operation{ tags: ["Status adminitration)"], diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index de24d31f4..0eeb095e1 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -155,6 +155,12 @@ defmodule Pleroma.Web.Router do post("/uploader_callback/:upload_path", UploaderController, :callback) end + scope "/api/v2/pleroma/admin", Pleroma.Web.AdminAPI do + pipe_through(:admin_api) + + get("/statuses", StatusController, :index2) + end + scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do pipe_through(:admin_api) |