2020-05-20 14:00:41 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-05-20 14:00:41 +00:00
|
|
|
# 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.Web.ActivityPub.ActivityPub
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
alias Pleroma.Web.MastodonAPI
|
2020-06-24 10:07:47 +00:00
|
|
|
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
2020-05-20 14:00:41 +00:00
|
|
|
|
|
|
|
require Logger
|
|
|
|
|
2020-05-21 10:03:38 +00:00
|
|
|
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
2021-02-17 18:37:23 +00:00
|
|
|
plug(OAuthScopesPlug, %{scopes: ["admin:read:statuses"]} when action in [:index, :show])
|
2020-05-20 14:00:41 +00:00
|
|
|
|
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
2021-02-17 18:37:23 +00:00
|
|
|
%{scopes: ["admin:write:statuses"]} when action in [:update, :delete]
|
2020-05-20 14:00:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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-06-04 17:33:16 +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
|
2020-06-02 15:07:17 +00:00
|
|
|
render(conn, "show.json", %{activity: activity})
|
2020-05-20 14:00:41 +00:00
|
|
|
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
|