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.UserOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.ActorType
9 alias Pleroma.Web.ApiSpec.Schemas.ApiError
11 import Pleroma.Web.ApiSpec.Helpers
13 def open_api_operation(action) do
14 operation = String.to_existing_atom("#{action}_operation")
15 apply(__MODULE__, operation, [])
18 def index_operation do
20 tags: ["User administration"],
21 summary: "List users",
22 operationId: "AdminAPI.UserController.index",
23 security: [%{"oAuth" => ["admin:read:accounts"]}],
25 Operation.parameter(:filters, :query, :string, "Comma separated list of filters"),
26 Operation.parameter(:query, :query, :string, "Search users query"),
27 Operation.parameter(:name, :query, :string, "Search by display name"),
28 Operation.parameter(:email, :query, :string, "Search by email"),
29 Operation.parameter(:page, :query, :integer, "Page Number"),
30 Operation.parameter(:page_size, :query, :integer, "Number of users to return per page"),
34 %Schema{type: :array, items: ActorType},
35 "Filter by actor type"
40 %Schema{type: :array, items: %Schema{type: :string}},
53 users: %Schema{type: :array, items: user()},
54 count: %Schema{type: :integer},
55 page_size: %Schema{type: :integer}
59 403 => Operation.response("Forbidden", "application/json", ApiError)
64 def create_operation do
66 tags: ["User administration"],
67 summary: "Create a single or multiple users",
68 operationId: "AdminAPI.UserController.create",
69 security: [%{"oAuth" => ["admin:write:accounts"]}],
70 parameters: admin_api_params(),
75 description: "POST body for creating users",
83 nickname: %Schema{type: :string},
84 email: %Schema{type: :string},
85 password: %Schema{type: :string}
94 Operation.response("Response", "application/json", %Schema{
99 code: %Schema{type: :integer},
100 type: %Schema{type: :string},
104 email: %Schema{type: :string, format: :email},
105 nickname: %Schema{type: :string}
111 403 => Operation.response("Forbidden", "application/json", ApiError),
113 Operation.response("Conflict", "application/json", %Schema{
118 code: %Schema{type: :integer},
119 error: %Schema{type: :string},
120 type: %Schema{type: :string},
124 email: %Schema{type: :string, format: :email},
125 nickname: %Schema{type: :string}
135 def show_operation do
137 tags: ["User administration"],
138 summary: "Show user",
139 operationId: "AdminAPI.UserController.show",
140 security: [%{"oAuth" => ["admin:read:accounts"]}],
146 "User nickname or ID"
151 200 => Operation.response("Response", "application/json", user()),
152 403 => Operation.response("Forbidden", "application/json", ApiError),
153 404 => Operation.response("Not Found", "application/json", ApiError)
158 def follow_operation do
160 tags: ["User administration"],
162 operationId: "AdminAPI.UserController.follow",
163 security: [%{"oAuth" => ["admin:write:follows"]}],
164 parameters: admin_api_params(),
171 follower: %Schema{type: :string, description: "Follower nickname"},
172 followed: %Schema{type: :string, description: "Followed nickname"}
177 200 => Operation.response("Response", "application/json", %Schema{type: :string}),
178 403 => Operation.response("Forbidden", "application/json", ApiError)
183 def unfollow_operation do
185 tags: ["User administration"],
187 operationId: "AdminAPI.UserController.unfollow",
188 security: [%{"oAuth" => ["admin:write:follows"]}],
189 parameters: admin_api_params(),
196 follower: %Schema{type: :string, description: "Follower nickname"},
197 followed: %Schema{type: :string, description: "Followed nickname"}
202 200 => Operation.response("Response", "application/json", %Schema{type: :string}),
203 403 => Operation.response("Forbidden", "application/json", ApiError)
208 def approve_operation do
210 tags: ["User administration"],
211 summary: "Approve multiple users",
212 operationId: "AdminAPI.UserController.approve",
213 security: [%{"oAuth" => ["admin:write:accounts"]}],
214 parameters: admin_api_params(),
219 description: "POST body for approving multiple users",
224 items: %Schema{type: :string}
231 Operation.response("Response", "application/json", %Schema{
233 properties: %{user: %Schema{type: :array, items: user()}}
235 403 => Operation.response("Forbidden", "application/json", ApiError)
240 def suggest_operation do
242 tags: ["User administration"],
243 summary: "Suggest multiple users",
244 operationId: "AdminAPI.UserController.suggest",
245 security: [%{"oAuth" => ["admin:write:accounts"]}],
246 parameters: admin_api_params(),
251 description: "POST body for adding multiple suggested users",
256 items: %Schema{type: :string}
263 Operation.response("Response", "application/json", %Schema{
265 properties: %{user: %Schema{type: :array, items: user()}}
267 403 => Operation.response("Forbidden", "application/json", ApiError)
272 def unsuggest_operation do
274 tags: ["User administration"],
275 summary: "Unsuggest multiple users",
276 operationId: "AdminAPI.UserController.unsuggest",
277 security: [%{"oAuth" => ["admin:write:accounts"]}],
278 parameters: admin_api_params(),
283 description: "POST body for removing multiple suggested users",
288 items: %Schema{type: :string}
295 Operation.response("Response", "application/json", %Schema{
297 properties: %{user: %Schema{type: :array, items: user()}}
299 403 => Operation.response("Forbidden", "application/json", ApiError)
304 def toggle_activation_operation do
306 tags: ["User administration"],
307 summary: "Toggle user activation",
308 operationId: "AdminAPI.UserController.toggle_activation",
309 security: [%{"oAuth" => ["admin:write:accounts"]}],
311 Operation.parameter(:nickname, :path, :string, "User nickname")
315 200 => Operation.response("Response", "application/json", user()),
316 403 => Operation.response("Forbidden", "application/json", ApiError)
321 def activate_operation do
323 tags: ["User administration"],
324 summary: "Activate multiple users",
325 operationId: "AdminAPI.UserController.activate",
326 security: [%{"oAuth" => ["admin:write:accounts"]}],
327 parameters: admin_api_params(),
332 description: "POST body for deleting multiple users",
337 items: %Schema{type: :string}
344 Operation.response("Response", "application/json", %Schema{
346 properties: %{user: %Schema{type: :array, items: user()}}
348 403 => Operation.response("Forbidden", "application/json", ApiError)
353 def deactivate_operation do
355 tags: ["User administration"],
356 summary: "Deactivates multiple users",
357 operationId: "AdminAPI.UserController.deactivate",
358 security: [%{"oAuth" => ["admin:write:accounts"]}],
359 parameters: admin_api_params(),
364 description: "POST body for deleting multiple users",
369 items: %Schema{type: :string}
376 Operation.response("Response", "application/json", %Schema{
378 properties: %{user: %Schema{type: :array, items: user()}}
380 403 => Operation.response("Forbidden", "application/json", ApiError)
385 def delete_operation do
387 tags: ["User administration"],
388 summary: "Removes a single or multiple users",
389 operationId: "AdminAPI.UserController.delete",
390 security: [%{"oAuth" => ["admin:write:accounts"]}],
404 description: "POST body for deleting multiple users",
409 items: %Schema{type: :string}
416 Operation.response("Response", "application/json", %Schema{
417 description: "Array of nicknames",
419 items: %Schema{type: :string}
421 403 => Operation.response("Forbidden", "application/json", ApiError)
430 id: %Schema{type: :string},
431 email: %Schema{type: :string, format: :email},
432 avatar: %Schema{type: :string, format: :uri},
433 nickname: %Schema{type: :string},
434 display_name: %Schema{type: :string},
435 is_active: %Schema{type: :boolean},
436 local: %Schema{type: :boolean},
440 admin: %Schema{type: :boolean},
441 moderator: %Schema{type: :boolean}
444 tags: %Schema{type: :array, items: %Schema{type: :string}},
445 is_confirmed: %Schema{type: :boolean},
446 is_approved: %Schema{type: :boolean},
447 url: %Schema{type: :string, format: :uri},
448 registration_reason: %Schema{type: :string, nullable: true},
449 actor_type: %Schema{type: :string}