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"]}],
25 Operation.response("Invites", "application/json", %Schema{
28 invites: %Schema{type: :array, items: invite()}
34 "token" => "kSQtDj_GNy2NZsL9AQDFIsHN5qdbguB6qRg3WHw6K1U=",
39 "invite_type" => "one_time"
48 def create_operation do
50 tags: ["Admin", "Invites"],
51 summary: "Create an account registration invite token",
52 operationId: "AdminAPI.InviteController.create",
53 security: [%{"oAuth" => ["write:invites"]}],
55 request_body("Parameters", %Schema{
58 max_use: %Schema{type: :integer},
59 expires_at: %Schema{type: :string, format: :date, example: "2020-04-20"}
63 200 => Operation.response("Invite", "application/json", invite())
68 def revoke_operation do
70 tags: ["Admin", "Invites"],
71 summary: "Revoke invite by token",
72 operationId: "AdminAPI.InviteController.revoke",
73 security: [%{"oAuth" => ["write:invites"]}],
81 token: %Schema{type: :string}
87 200 => Operation.response("Invite", "application/json", invite()),
88 400 => Operation.response("Bad Request", "application/json", ApiError),
89 404 => Operation.response("Not Found", "application/json", ApiError)
94 def email_operation do
96 tags: ["Admin", "Invites"],
97 summary: "Sends registration invite via email",
98 operationId: "AdminAPI.InviteController.email",
99 security: [%{"oAuth" => ["write:invites"]}],
107 email: %Schema{type: :string, format: :email},
108 name: %Schema{type: :string}
114 204 => no_content_response(),
115 400 => Operation.response("Bad Request", "application/json", ApiError),
116 403 => Operation.response("Forbidden", "application/json", ApiError)
126 id: %Schema{type: :integer},
127 token: %Schema{type: :string},
128 used: %Schema{type: :boolean},
129 expires_at: %Schema{type: :string, format: :date, nullable: true},
130 uses: %Schema{type: :integer},
131 max_use: %Schema{type: :integer, nullable: true},
132 invite_type: %Schema{
134 enum: ["one_time", "reusable", "date_limited", "reusable_date_limited"]
139 "token" => "kSQtDj_GNy2NZsL9AQDFIsHN5qdbguB6qRg3WHw6K1U=",
144 "invite_type" => "one_time"