Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into feature/delete...
[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 items: %Schema{type: :string},
41 description: "Array of Statuses to attach to the report, for context"
42 },
43 comment: %Schema{
44 type: :string,
45 description: "Reason for the report"
46 },
47 forward: %Schema{
48 type: :boolean,
49 default: false,
50 description:
51 "If the account is remote, should the report be forwarded to the remote admin?"
52 }
53 },
54 required: [:account_id],
55 example: %{
56 "account_id" => "123",
57 "status_ids" => ["1337"],
58 "comment" => "bad status!",
59 "forward" => "false"
60 }
61 }
62 end
63
64 defp create_response do
65 %Schema{
66 title: "ReportResponse",
67 type: :object,
68 properties: %{
69 id: %Schema{type: :string, description: "Report ID"},
70 action_taken: %Schema{type: :boolean, description: "Is action taken?"}
71 },
72 example: %{
73 "id" => "123",
74 "action_taken" => false
75 }
76 }
77 end
78 end