aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/admin_api/controllers
diff options
context:
space:
mode:
authorEgor Kislitsyn <egor@kislitsyn.com>2020-05-21 14:03:38 +0400
committerEgor Kislitsyn <egor@kislitsyn.com>2020-05-21 17:23:12 +0400
commit45d2c4157fc264dacdca0f17268d3a33f364801f (patch)
tree633f60c09dbba8611c213fcdb4c317e0d71cd7f6 /lib/pleroma/web/admin_api/controllers
parent9de9760aa696657400c762d46dced273c3475be4 (diff)
downloadpleroma-45d2c4157fc264dacdca0f17268d3a33f364801f.tar.gz
Add OpenAPI spec for AdminAPI.StatusController
Diffstat (limited to 'lib/pleroma/web/admin_api/controllers')
-rw-r--r--lib/pleroma/web/admin_api/controllers/fallback_controller.ex6
-rw-r--r--lib/pleroma/web/admin_api/controllers/status_controller.ex59
2 files changed, 16 insertions, 49 deletions
diff --git a/lib/pleroma/web/admin_api/controllers/fallback_controller.ex b/lib/pleroma/web/admin_api/controllers/fallback_controller.ex
index 9f7bb92ce..82965936d 100644
--- a/lib/pleroma/web/admin_api/controllers/fallback_controller.ex
+++ b/lib/pleroma/web/admin_api/controllers/fallback_controller.ex
@@ -8,13 +8,13 @@ defmodule Pleroma.Web.AdminAPI.FallbackController do
def call(conn, {:error, :not_found}) do
conn
|> put_status(:not_found)
- |> json(dgettext("errors", "Not found"))
+ |> json(%{error: dgettext("errors", "Not found")})
end
def call(conn, {:error, reason}) do
conn
|> put_status(:bad_request)
- |> json(reason)
+ |> json(%{error: reason})
end
def call(conn, {:param_cast, _}) do
@@ -26,6 +26,6 @@ defmodule Pleroma.Web.AdminAPI.FallbackController do
def call(conn, _) do
conn
|> put_status(:internal_server_error)
- |> json(dgettext("errors", "Something went wrong"))
+ |> json(%{error: dgettext("errors", "Something went wrong")})
end
end
diff --git a/lib/pleroma/web/admin_api/controllers/status_controller.ex b/lib/pleroma/web/admin_api/controllers/status_controller.ex
index 1e9763979..08cb9c10b 100644
--- a/lib/pleroma/web/admin_api/controllers/status_controller.ex
+++ b/lib/pleroma/web/admin_api/controllers/status_controller.ex
@@ -14,8 +14,7 @@ defmodule Pleroma.Web.AdminAPI.StatusController do
require Logger
- @users_page_size 50
-
+ plug(Pleroma.Web.ApiSpec.CastAndValidate)
plug(OAuthScopesPlug, %{scopes: ["read:statuses"], admin: true} when action in [:index, :show])
plug(
@@ -25,25 +24,22 @@ defmodule Pleroma.Web.AdminAPI.StatusController do
action_fallback(Pleroma.Web.AdminAPI.FallbackController)
- def index(%{assigns: %{user: _admin}} = conn, params) do
- godmode = params["godmode"] == "true" || params["godmode"] == true
- local_only = params["local_only"] == "true" || params["local_only"] == true
- with_reblogs = params["with_reblogs"] == "true" || params["with_reblogs"] == true
- {page, page_size} = page_params(params)
+ defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.StatusOperation
+ def index(%{assigns: %{user: _admin}} = conn, params) do
activities =
ActivityPub.fetch_statuses(nil, %{
- "godmode" => godmode,
- "local_only" => local_only,
- "limit" => page_size,
- "offset" => (page - 1) * page_size,
- "exclude_reblogs" => !with_reblogs && "true"
+ "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
})
- render(conn, "index.json", %{activities: activities, as: :activity})
+ render(conn, "index.json", activities: activities, as: :activity)
end
- def show(conn, %{"id" => id}) do
+ def show(conn, %{id: id}) do
with %Activity{} = activity <- Activity.get_by_id(id) do
conn
|> put_view(MastodonAPI.StatusView)
@@ -53,20 +49,13 @@ defmodule Pleroma.Web.AdminAPI.StatusController do
end
end
- def update(%{assigns: %{user: admin}} = conn, %{"id" => id} = params) do
- params =
- params
- |> Map.take(["sensitive", "visibility"])
- |> Map.new(fn {key, value} -> {String.to_existing_atom(key), value} end)
-
+ def update(%{assigns: %{user: admin}, body_params: params} = conn, %{id: id}) do
with {:ok, activity} <- CommonAPI.update_activity_scope(id, params) do
- {:ok, sensitive} = Ecto.Type.cast(:boolean, params[:sensitive])
-
ModerationLog.insert_log(%{
action: "status_update",
actor: admin,
subject: activity,
- sensitive: sensitive,
+ sensitive: params[:sensitive],
visibility: params[:visibility]
})
@@ -76,7 +65,7 @@ defmodule Pleroma.Web.AdminAPI.StatusController do
end
end
- def delete(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+ def delete(%{assigns: %{user: user}} = conn, %{id: id}) do
with {:ok, %Activity{}} <- CommonAPI.delete(id, user) do
ModerationLog.insert_log(%{
action: "status_delete",
@@ -87,26 +76,4 @@ defmodule Pleroma.Web.AdminAPI.StatusController do
json(conn, %{})
end
end
-
- defp page_params(params) do
- {get_page(params["page"]), get_page_size(params["page_size"])}
- end
-
- defp get_page(page_string) when is_nil(page_string), do: 1
-
- defp get_page(page_string) do
- case Integer.parse(page_string) do
- {page, _} -> page
- :error -> 1
- end
- end
-
- defp get_page_size(page_size_string) when is_nil(page_size_string), do: @users_page_size
-
- defp get_page_size(page_size_string) do
- case Integer.parse(page_size_string) do
- {page_size, _} -> page_size
- :error -> @users_page_size
- end
- end
end