logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

status_controller.ex (2119B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.AdminAPI.StatusController do
  5. use Pleroma.Web, :controller
  6. alias Pleroma.Activity
  7. alias Pleroma.ModerationLog
  8. alias Pleroma.Web.ActivityPub.ActivityPub
  9. alias Pleroma.Web.CommonAPI
  10. alias Pleroma.Web.MastodonAPI
  11. alias Pleroma.Web.Plugs.OAuthScopesPlug
  12. require Logger
  13. plug(Pleroma.Web.ApiSpec.CastAndValidate)
  14. plug(OAuthScopesPlug, %{scopes: ["admin:read:statuses"]} when action in [:index, :show])
  15. plug(
  16. OAuthScopesPlug,
  17. %{scopes: ["admin:write:statuses"]} when action in [:update, :delete]
  18. )
  19. action_fallback(Pleroma.Web.AdminAPI.FallbackController)
  20. defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.StatusOperation
  21. def index(%{assigns: %{user: _admin}} = conn, params) do
  22. activities =
  23. ActivityPub.fetch_statuses(nil, %{
  24. godmode: params.godmode,
  25. local_only: params.local_only,
  26. limit: params.page_size,
  27. offset: (params.page - 1) * params.page_size,
  28. exclude_reblogs: not params.with_reblogs
  29. })
  30. render(conn, "index.json", activities: activities, as: :activity)
  31. end
  32. def show(conn, %{id: id}) do
  33. with %Activity{} = activity <- Activity.get_by_id(id) do
  34. render(conn, "show.json", %{activity: activity})
  35. else
  36. nil -> {:error, :not_found}
  37. end
  38. end
  39. def update(%{assigns: %{user: admin}, body_params: params} = conn, %{id: id}) do
  40. with {:ok, activity} <- CommonAPI.update_activity_scope(id, params) do
  41. ModerationLog.insert_log(%{
  42. action: "status_update",
  43. actor: admin,
  44. subject: activity,
  45. sensitive: params[:sensitive],
  46. visibility: params[:visibility]
  47. })
  48. conn
  49. |> put_view(MastodonAPI.StatusView)
  50. |> render("show.json", %{activity: activity})
  51. end
  52. end
  53. def delete(%{assigns: %{user: user}} = conn, %{id: id}) do
  54. with {:ok, %Activity{}} <- CommonAPI.delete(id, user) do
  55. json(conn, %{})
  56. end
  57. end
  58. end