Merge remote-tracking branch 'remotes/origin/develop' into 2168-media-preview-proxy
[akkoma] / lib / pleroma / web / api_spec / operations / report_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.ReportOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Helpers
9 alias Pleroma.Web.ApiSpec.Schemas.ApiError
10
11 def open_api_operation(action) do
12 operation = String.to_existing_atom("#{action}_operation")
13 apply(__MODULE__, operation, [])
14 end
15
16 def create_operation do
17 %Operation{
18 tags: ["reports"],
19 summary: "File a report",
20 description: "Report problematic users to your moderators",
21 operationId: "ReportController.create",
22 security: [%{"oAuth" => ["follow", "write:reports"]}],
23 requestBody: Helpers.request_body("Parameters", create_request(), required: true),
24 responses: %{
25 200 => Operation.response("Report", "application/json", create_response()),
26 400 => Operation.response("Report", "application/json", ApiError)
27 }
28 }
29 end
30
31 defp create_request do
32 %Schema{
33 title: "ReportCreateRequest",
34 description: "POST body for creating a report",
35 type: :object,
36 properties: %{
37 account_id: %Schema{type: :string, description: "ID of the account to report"},
38 status_ids: %Schema{
39 type: :array,
40 nullable: true,
41 items: %Schema{type: :string},
42 description: "Array of Statuses to attach to the report, for context"
43 },
44 comment: %Schema{
45 type: :string,
46 nullable: true,
47 description: "Reason for the report"
48 },
49 forward: %Schema{
50 type: :boolean,
51 nullable: true,
52 default: false,
53 description:
54 "If the account is remote, should the report be forwarded to the remote admin?"
55 }
56 },
57 required: [:account_id],
58 example: %{
59 "account_id" => "123",
60 "status_ids" => ["1337"],
61 "comment" => "bad status!",
62 "forward" => "false"
63 }
64 }
65 end
66
67 defp create_response do
68 %Schema{
69 title: "ReportResponse",
70 type: :object,
71 properties: %{
72 id: %Schema{type: :string, description: "Report ID"},
73 action_taken: %Schema{type: :boolean, description: "Is action taken?"}
74 },
75 example: %{
76 "id" => "123",
77 "action_taken" => false
78 }
79 }
80 end
81 end