logo

pleroma

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

report_controller.ex (1447B)


  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.PleromaAPI.ReportController do
  5. use Pleroma.Web, :controller
  6. alias Pleroma.Activity
  7. alias Pleroma.Web.ActivityPub.Utils
  8. alias Pleroma.Web.AdminAPI.Report
  9. action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
  10. plug(Pleroma.Web.ApiSpec.CastAndValidate)
  11. plug(Pleroma.Web.Plugs.OAuthScopesPlug, %{scopes: ["read:reports"]})
  12. defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaReportOperation
  13. @doc "GET /api/v0/pleroma/reports"
  14. def index(%{assigns: %{user: user}, body_params: params} = conn, _) do
  15. params =
  16. params
  17. |> Map.put(:actor_id, user.ap_id)
  18. reports = Utils.get_reports(params, Map.get(params, :page, 1), Map.get(params, :size, 20))
  19. render(conn, "index.json", %{reports: reports, for: user})
  20. end
  21. @doc "GET /api/v0/pleroma/reports/:id"
  22. def show(%{assigns: %{user: user}} = conn, %{id: id}) do
  23. with %Activity{} = report <- Activity.get_report(id),
  24. true <- report.actor == user.ap_id,
  25. %{} = report_info <- Report.extract_report_info(report) do
  26. render(conn, "show.json", Map.put(report_info, :for, user))
  27. else
  28. false ->
  29. {:error, :not_found}
  30. nil ->
  31. {:error, :not_found}
  32. e ->
  33. {:error, inspect(e)}
  34. end
  35. end
  36. end