1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.PleromaAPI.ReportController do
6 use Pleroma.Web, :controller
9 alias Pleroma.Web.ActivityPub.Utils
10 alias Pleroma.Web.AdminAPI.Report
12 action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
13 plug(Pleroma.Web.ApiSpec.CastAndValidate)
14 plug(Pleroma.Web.Plugs.OAuthScopesPlug, %{scopes: ["read:reports"]})
16 defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaReportOperation
18 @doc "GET /api/v0/pleroma/reports"
19 def index(%{assigns: %{user: user}, body_params: params} = conn, _) do
22 |> Map.put(:actor_id, user.ap_id)
24 reports = Utils.get_reports(params, Map.get(params, :page, 1), Map.get(params, :size, 20))
26 render(conn, "index.json", %{reports: reports, for: user})
29 @doc "GET /api/v0/pleroma/reports/:id"
30 def show(%{assigns: %{user: user}} = conn, %{id: id}) do
31 with %Activity{} = report <- Activity.get_report(id),
32 true <- report.actor == user.ap_id,
33 %{} = report_info <- Report.extract_report_info(report) do
34 render(conn, "show.json", Map.put(report_info, :for, user))