1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.Admin.ReportOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.Account
9 alias Pleroma.Web.ApiSpec.Schemas.ApiError
10 alias Pleroma.Web.ApiSpec.Schemas.FlakeID
11 alias Pleroma.Web.ApiSpec.Schemas.Status
13 import Pleroma.Web.ApiSpec.Helpers
15 def open_api_operation(action) do
16 operation = String.to_existing_atom("#{action}_operation")
17 apply(__MODULE__, operation, [])
20 def index_operation do
22 tags: ["Admin", "Reports"],
23 summary: "Get a list of reports",
24 operationId: "AdminAPI.ReportController.index",
25 security: [%{"oAuth" => ["read:reports"]}],
31 "Filter by report state"
36 %Schema{type: :integer},
37 "The number of records to retrieve"
42 %Schema{type: :integer, default: 1},
48 %Schema{type: :integer, default: 50},
49 "Number number of log entries per page"
54 Operation.response("Response", "application/json", %Schema{
57 total: %Schema{type: :integer},
64 403 => Operation.response("Forbidden", "application/json", ApiError)
71 tags: ["Admin", "Reports"],
72 summary: "Get an individual report",
73 operationId: "AdminAPI.ReportController.show",
74 parameters: [id_param()],
75 security: [%{"oAuth" => ["read:reports"]}],
77 200 => Operation.response("Report", "application/json", report()),
78 404 => Operation.response("Not Found", "application/json", ApiError)
83 def update_operation do
85 tags: ["Admin", "Reports"],
86 summary: "Change the state of one or multiple reports",
87 operationId: "AdminAPI.ReportController.update",
88 security: [%{"oAuth" => ["write:reports"]}],
89 requestBody: request_body("Parameters", update_request(), required: true),
91 204 => no_content_response(),
92 400 => Operation.response("Bad Request", "application/json", update_400_response()),
93 403 => Operation.response("Forbidden", "application/json", ApiError)
98 def notes_create_operation do
100 tags: ["Admin", "Reports"],
101 summary: "Create report note",
102 operationId: "AdminAPI.ReportController.notes_create",
103 parameters: [id_param()],
105 request_body("Parameters", %Schema{
108 content: %Schema{type: :string, description: "The message"}
111 security: [%{"oAuth" => ["write:reports"]}],
113 204 => no_content_response(),
114 404 => Operation.response("Not Found", "application/json", ApiError)
119 def notes_delete_operation do
121 tags: ["Admin", "Reports"],
122 summary: "Delete report note",
123 operationId: "AdminAPI.ReportController.notes_delete",
125 Operation.parameter(:report_id, :path, :string, "Report ID"),
126 Operation.parameter(:id, :path, :string, "Note ID")
128 security: [%{"oAuth" => ["write:reports"]}],
130 204 => no_content_response(),
131 404 => Operation.response("Not Found", "application/json", ApiError)
137 %Schema{type: :string, enum: ["open", "closed", "resolved"]}
141 Operation.parameter(:id, :path, FlakeID, "Report ID",
142 example: "9umDrYheeY451cQnEe",
152 state: report_state(),
153 account: account_admin(),
154 actor: account_admin(),
155 content: %Schema{type: :string},
156 created_at: %Schema{type: :string, format: :"date-time"},
157 statuses: %Schema{type: :array, items: Status},
163 id: %Schema{type: :integer},
165 content: %Schema{type: :string},
166 inserted_at: %Schema{type: :string, format: :"date-time"}
174 defp account_admin do
177 description: "Account view for admins",
180 Map.merge(Account.schema().properties, %{
181 nickname: %Schema{type: :string},
182 deactivated: %Schema{type: :boolean},
183 local: %Schema{type: :boolean},
187 admin: %Schema{type: :boolean},
188 moderator: %Schema{type: :boolean}
191 confirmation_pending: %Schema{type: :boolean}
196 defp update_request do
199 required: [:reports],
206 id: %Schema{allOf: [FlakeID], description: "Required, report ID"},
210 "Required, the new state. Valid values are `open`, `closed` and `resolved`"
216 %{"id" => "123", "state" => "closed"},
217 %{"id" => "1337", "state" => "resolved"}
225 defp update_400_response do
231 id: %Schema{allOf: [FlakeID], description: "Report ID"},
232 error: %Schema{type: :string, description: "Error message"}