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.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: ["Report managment"],
23 summary: "Retrieve a list of reports",
24 operationId: "AdminAPI.ReportController.index",
25 security: [%{"oAuth" => ["admin: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"
55 Operation.response("Response", "application/json", %Schema{
58 total: %Schema{type: :integer},
65 403 => Operation.response("Forbidden", "application/json", ApiError)
72 tags: ["Report managment"],
73 summary: "Retrieve a report",
74 operationId: "AdminAPI.ReportController.show",
75 parameters: [id_param() | admin_api_params()],
76 security: [%{"oAuth" => ["admin:read:reports"]}],
78 200 => Operation.response("Report", "application/json", report()),
79 404 => Operation.response("Not Found", "application/json", ApiError)
84 def update_operation do
86 tags: ["Report managment"],
87 summary: "Change state of specified reports",
88 operationId: "AdminAPI.ReportController.update",
89 security: [%{"oAuth" => ["admin:write:reports"]}],
90 parameters: admin_api_params(),
91 requestBody: request_body("Parameters", update_request(), required: true),
93 204 => no_content_response(),
94 400 => Operation.response("Bad Request", "application/json", update_400_response()),
95 403 => Operation.response("Forbidden", "application/json", ApiError)
100 def notes_create_operation do
102 tags: ["Report managment"],
103 summary: "Add a note to the report",
104 operationId: "AdminAPI.ReportController.notes_create",
105 parameters: [id_param() | admin_api_params()],
107 request_body("Parameters", %Schema{
110 content: %Schema{type: :string, description: "The message"}
113 security: [%{"oAuth" => ["admin:write:reports"]}],
115 204 => no_content_response(),
116 404 => Operation.response("Not Found", "application/json", ApiError)
121 def notes_delete_operation do
123 tags: ["Report managment"],
124 summary: "Delete note attached to the report",
125 operationId: "AdminAPI.ReportController.notes_delete",
127 Operation.parameter(:report_id, :path, :string, "Report ID"),
128 Operation.parameter(:id, :path, :string, "Note ID")
131 security: [%{"oAuth" => ["admin:write:reports"]}],
133 204 => no_content_response(),
134 404 => Operation.response("Not Found", "application/json", ApiError)
140 %Schema{type: :string, enum: ["open", "closed", "resolved"]}
144 Operation.parameter(:id, :path, FlakeID, "Report ID",
145 example: "9umDrYheeY451cQnEe",
155 state: report_state(),
156 account: account_admin(),
157 actor: account_admin(),
158 content: %Schema{type: :string},
159 created_at: %Schema{type: :string, format: :"date-time"},
160 statuses: %Schema{type: :array, items: Status},
166 id: %Schema{type: :integer},
168 content: %Schema{type: :string},
169 inserted_at: %Schema{type: :string, format: :"date-time"}
177 defp account_admin do
180 description: "Account view for admins",
183 Map.merge(Account.schema().properties, %{
184 nickname: %Schema{type: :string},
185 is_active: %Schema{type: :boolean},
186 local: %Schema{type: :boolean},
190 admin: %Schema{type: :boolean},
191 moderator: %Schema{type: :boolean}
194 is_confirmed: %Schema{type: :boolean}
199 defp update_request do
202 required: [:reports],
209 id: %Schema{allOf: [FlakeID], description: "Required, report ID"},
213 "Required, the new state. Valid values are `open`, `closed` and `resolved`"
219 %{"id" => "123", "state" => "closed"},
220 %{"id" => "1337", "state" => "resolved"}
228 defp update_400_response do
234 id: %Schema{allOf: [FlakeID], description: "Report ID"},
235 error: %Schema{type: :string, description: "Error message"}