First
[anni] / lib / pleroma / web / api_spec / operations / report_operation.ex
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
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   alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
11
12   def open_api_operation(action) do
13     operation = String.to_existing_atom("#{action}_operation")
14     apply(__MODULE__, operation, [])
15   end
16
17   def create_operation do
18     %Operation{
19       tags: ["Reports"],
20       summary: "File a report",
21       description: "Report problematic users to your moderators",
22       operationId: "ReportController.create",
23       security: [%{"oAuth" => ["follow", "write:reports"]}],
24       requestBody: Helpers.request_body("Parameters", create_request(), required: true),
25       responses: %{
26         200 => Operation.response("Report", "application/json", create_response()),
27         400 => Operation.response("Report", "application/json", ApiError)
28       }
29     }
30   end
31
32   defp create_request do
33     %Schema{
34       title: "ReportCreateRequest",
35       description: "POST body for creating a report",
36       type: :object,
37       properties: %{
38         account_id: %Schema{type: :string, description: "ID of the account to report"},
39         status_ids: %Schema{
40           type: :array,
41           nullable: true,
42           items: %Schema{type: :string},
43           description: "Array of Statuses to attach to the report, for context"
44         },
45         comment: %Schema{
46           type: :string,
47           nullable: true,
48           description: "Reason for the report"
49         },
50         forward: %Schema{
51           allOf: [BooleanLike],
52           nullable: true,
53           default: false,
54           description:
55             "If the account is remote, should the report be forwarded to the remote admin?"
56         }
57       },
58       required: [:account_id],
59       example: %{
60         "account_id" => "123",
61         "status_ids" => ["1337"],
62         "comment" => "bad status!",
63         "forward" => "false"
64       }
65     }
66   end
67
68   defp create_response do
69     %Schema{
70       title: "ReportResponse",
71       type: :object,
72       properties: %{
73         id: %Schema{type: :string, description: "Report ID"},
74         action_taken: %Schema{type: :boolean, description: "Is action taken?"}
75       },
76       example: %{
77         "id" => "123",
78         "action_taken" => false
79       }
80     }
81   end
82 end