2020-05-20 14:00:41 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.AdminAPI.StatusController do
|
|
|
|
use Pleroma.Web, :controller
|
|
|
|
|
|
|
|
alias Pleroma.Activity
|
|
|
|
alias Pleroma.ModerationLog
|
|
|
|
alias Pleroma.Plugs.OAuthScopesPlug
|
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
alias Pleroma.Web.MastodonAPI
|
|
|
|
|
|
|
|
require Logger
|
|
|
|
|
2020-05-21 10:03:38 +00:00
|
|
|
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
2020-05-20 14:00:41 +00:00
|
|
|
plug(OAuthScopesPlug, %{scopes: ["read:statuses"], admin: true} when action in [:index, :show])
|
|
|
|
|
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
|
|
|
%{scopes: ["write:statuses"], admin: true} when action in [:update, :delete]
|
|
|
|
)
|
|
|
|
|
|
|
|
action_fallback(Pleroma.Web.AdminAPI.FallbackController)
|
|
|
|
|
2020-05-21 10:03:38 +00:00
|
|
|
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.StatusOperation
|
2020-05-20 14:00:41 +00:00
|
|
|
|
2020-05-21 10:03:38 +00:00
|
|
|
def index(%{assigns: %{user: _admin}} = conn, params) do
|
2020-05-20 14:00:41 +00:00
|
|
|
activities =
|
|
|
|
ActivityPub.fetch_statuses(nil, %{
|
2020-05-21 10:03:38 +00:00
|
|
|
"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
|
2020-05-20 14:00:41 +00:00
|
|
|
})
|
|
|
|
|
2020-05-21 10:03:38 +00:00
|
|
|
render(conn, "index.json", activities: activities, as: :activity)
|
2020-05-20 14:00:41 +00:00
|
|
|
end
|
|
|
|
|
2020-05-21 10:03:38 +00:00
|
|
|
def show(conn, %{id: id}) do
|
2020-05-20 14:00:41 +00:00
|
|
|
with %Activity{} = activity <- Activity.get_by_id(id) do
|
|
|
|
conn
|
|
|
|
|> put_view(MastodonAPI.StatusView)
|
|
|
|
|> render("show.json", %{activity: activity})
|
|
|
|
else
|
|
|
|
nil -> {:error, :not_found}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-21 10:03:38 +00:00
|
|
|
def update(%{assigns: %{user: admin}, body_params: params} = conn, %{id: id}) do
|
2020-05-20 14:00:41 +00:00
|
|
|
with {:ok, activity} <- CommonAPI.update_activity_scope(id, params) do
|
|
|
|
ModerationLog.insert_log(%{
|
|
|
|
action: "status_update",
|
|
|
|
actor: admin,
|
|
|
|
subject: activity,
|
2020-05-21 10:03:38 +00:00
|
|
|
sensitive: params[:sensitive],
|
2020-05-20 14:00:41 +00:00
|
|
|
visibility: params[:visibility]
|
|
|
|
})
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> put_view(MastodonAPI.StatusView)
|
|
|
|
|> render("show.json", %{activity: activity})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-21 10:03:38 +00:00
|
|
|
def delete(%{assigns: %{user: user}} = conn, %{id: id}) do
|
2020-05-20 14:00:41 +00:00
|
|
|
with {:ok, %Activity{}} <- CommonAPI.delete(id, user) do
|
|
|
|
ModerationLog.insert_log(%{
|
|
|
|
action: "status_delete",
|
|
|
|
actor: user,
|
|
|
|
subject_id: id
|
|
|
|
})
|
|
|
|
|
|
|
|
json(conn, %{})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|