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.InviteOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.ApiError
10 import Pleroma.Web.ApiSpec.Helpers
12 def open_api_operation(action) do
13 operation = String.to_existing_atom("#{action}_operation")
14 apply(__MODULE__, operation, [])
17 def index_operation do
19 tags: ["Admin", "Invites"],
20 summary: "Get a list of generated invites",
21 operationId: "AdminAPI.InviteController.index",
22 security: [%{"oAuth" => ["read:invites"]}],
23 parameters: admin_api_params(),
26 Operation.response("Invites", "application/json", %Schema{
29 invites: %Schema{type: :array, items: invite()}
35 "token" => "kSQtDj_GNy2NZsL9AQDFIsHN5qdbguB6qRg3WHw6K1U=",
40 "invite_type" => "one_time"
49 def create_operation do
51 tags: ["Admin", "Invites"],
52 summary: "Create an account registration invite token",
53 operationId: "AdminAPI.InviteController.create",
54 security: [%{"oAuth" => ["write:invites"]}],
55 parameters: admin_api_params(),
57 request_body("Parameters", %Schema{
60 max_use: %Schema{type: :integer},
61 expires_at: %Schema{type: :string, format: :date, example: "2020-04-20"}
65 200 => Operation.response("Invite", "application/json", invite())
70 def revoke_operation do
72 tags: ["Admin", "Invites"],
73 summary: "Revoke invite by token",
74 operationId: "AdminAPI.InviteController.revoke",
75 security: [%{"oAuth" => ["write:invites"]}],
76 parameters: admin_api_params(),
84 token: %Schema{type: :string}
90 200 => Operation.response("Invite", "application/json", invite()),
91 400 => Operation.response("Bad Request", "application/json", ApiError),
92 404 => Operation.response("Not Found", "application/json", ApiError)
97 def email_operation do
99 tags: ["Admin", "Invites"],
100 summary: "Sends registration invite via email",
101 operationId: "AdminAPI.InviteController.email",
102 security: [%{"oAuth" => ["write:invites"]}],
103 parameters: admin_api_params(),
111 email: %Schema{type: :string, format: :email},
112 name: %Schema{type: :string}
118 204 => no_content_response(),
119 400 => Operation.response("Bad Request", "application/json", ApiError),
120 403 => Operation.response("Forbidden", "application/json", ApiError)
130 id: %Schema{type: :integer},
131 token: %Schema{type: :string},
132 used: %Schema{type: :boolean},
133 expires_at: %Schema{type: :string, format: :date, nullable: true},
134 uses: %Schema{type: :integer},
135 max_use: %Schema{type: :integer, nullable: true},
136 invite_type: %Schema{
138 enum: ["one_time", "reusable", "date_limited", "reusable_date_limited"]
143 "token" => "kSQtDj_GNy2NZsL9AQDFIsHN5qdbguB6qRg3WHw6K1U=",
148 "invite_type" => "one_time"