2020-05-26 11:13:39 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 07:49:20 +01:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-05-26 11:13:39 +02:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-05-26 13:21:33 +02:00
|
|
|
defmodule Pleroma.Web.ApiSpec.Admin.InviteOperation do
|
2020-05-26 11:13:39 +02:00
|
|
|
alias OpenApiSpex.Operation
|
|
|
|
alias OpenApiSpex.Schema
|
|
|
|
alias Pleroma.Web.ApiSpec.Schemas.ApiError
|
|
|
|
|
|
|
|
import Pleroma.Web.ApiSpec.Helpers
|
|
|
|
|
|
|
|
def open_api_operation(action) do
|
|
|
|
operation = String.to_existing_atom("#{action}_operation")
|
|
|
|
apply(__MODULE__, operation, [])
|
|
|
|
end
|
|
|
|
|
|
|
|
def index_operation do
|
|
|
|
%Operation{
|
2021-02-03 13:38:59 +01:00
|
|
|
tags: ["Invites"],
|
2020-05-26 13:02:51 +02:00
|
|
|
summary: "Get a list of generated invites",
|
2020-05-26 13:21:33 +02:00
|
|
|
operationId: "AdminAPI.InviteController.index",
|
2020-05-26 13:02:51 +02:00
|
|
|
security: [%{"oAuth" => ["read:invites"]}],
|
2020-07-14 18:31:05 +02:00
|
|
|
parameters: admin_api_params(),
|
2020-05-26 11:13:39 +02:00
|
|
|
responses: %{
|
|
|
|
200 =>
|
2020-05-27 12:42:21 +02:00
|
|
|
Operation.response("Invites", "application/json", %Schema{
|
2020-05-26 13:02:51 +02:00
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
invites: %Schema{type: :array, items: invite()}
|
|
|
|
},
|
|
|
|
example: %{
|
|
|
|
"invites" => [
|
|
|
|
%{
|
|
|
|
"id" => 123,
|
|
|
|
"token" => "kSQtDj_GNy2NZsL9AQDFIsHN5qdbguB6qRg3WHw6K1U=",
|
|
|
|
"used" => true,
|
|
|
|
"expires_at" => nil,
|
|
|
|
"uses" => 0,
|
|
|
|
"max_use" => nil,
|
|
|
|
"invite_type" => "one_time"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2020-05-26 11:13:39 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-05-26 13:02:51 +02:00
|
|
|
def create_operation do
|
2020-05-26 11:13:39 +02:00
|
|
|
%Operation{
|
2021-02-03 13:38:59 +01:00
|
|
|
tags: ["Invites"],
|
2020-05-26 13:02:51 +02:00
|
|
|
summary: "Create an account registration invite token",
|
2020-05-26 13:21:33 +02:00
|
|
|
operationId: "AdminAPI.InviteController.create",
|
2020-05-26 13:02:51 +02:00
|
|
|
security: [%{"oAuth" => ["write:invites"]}],
|
2020-07-14 18:31:05 +02:00
|
|
|
parameters: admin_api_params(),
|
2020-05-26 13:02:51 +02:00
|
|
|
requestBody:
|
|
|
|
request_body("Parameters", %Schema{
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
max_use: %Schema{type: :integer},
|
|
|
|
expires_at: %Schema{type: :string, format: :date, example: "2020-04-20"}
|
|
|
|
}
|
|
|
|
}),
|
2020-05-26 11:13:39 +02:00
|
|
|
responses: %{
|
2020-05-26 13:02:51 +02:00
|
|
|
200 => Operation.response("Invite", "application/json", invite())
|
2020-05-26 11:13:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-05-26 13:02:51 +02:00
|
|
|
def revoke_operation do
|
2020-05-26 11:13:39 +02:00
|
|
|
%Operation{
|
2021-02-03 13:38:59 +01:00
|
|
|
tags: ["Invites"],
|
2020-05-26 13:02:51 +02:00
|
|
|
summary: "Revoke invite by token",
|
2020-05-26 13:21:33 +02:00
|
|
|
operationId: "AdminAPI.InviteController.revoke",
|
2020-05-26 13:02:51 +02:00
|
|
|
security: [%{"oAuth" => ["write:invites"]}],
|
2020-07-14 18:31:05 +02:00
|
|
|
parameters: admin_api_params(),
|
2020-05-26 13:02:51 +02:00
|
|
|
requestBody:
|
|
|
|
request_body(
|
|
|
|
"Parameters",
|
|
|
|
%Schema{
|
|
|
|
type: :object,
|
|
|
|
required: [:token],
|
|
|
|
properties: %{
|
|
|
|
token: %Schema{type: :string}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
required: true
|
|
|
|
),
|
2020-05-26 11:13:39 +02:00
|
|
|
responses: %{
|
2020-05-26 13:02:51 +02:00
|
|
|
200 => Operation.response("Invite", "application/json", invite()),
|
|
|
|
400 => Operation.response("Bad Request", "application/json", ApiError),
|
|
|
|
404 => Operation.response("Not Found", "application/json", ApiError)
|
2020-05-26 11:13:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-05-26 13:02:51 +02:00
|
|
|
def email_operation do
|
2020-05-26 11:13:39 +02:00
|
|
|
%Operation{
|
2021-02-03 13:38:59 +01:00
|
|
|
tags: ["Invites"],
|
2020-05-26 13:02:51 +02:00
|
|
|
summary: "Sends registration invite via email",
|
2020-05-26 13:21:33 +02:00
|
|
|
operationId: "AdminAPI.InviteController.email",
|
2020-05-26 13:02:51 +02:00
|
|
|
security: [%{"oAuth" => ["write:invites"]}],
|
2020-07-14 18:31:05 +02:00
|
|
|
parameters: admin_api_params(),
|
2020-05-26 13:02:51 +02:00
|
|
|
requestBody:
|
|
|
|
request_body(
|
|
|
|
"Parameters",
|
|
|
|
%Schema{
|
|
|
|
type: :object,
|
|
|
|
required: [:email],
|
|
|
|
properties: %{
|
|
|
|
email: %Schema{type: :string, format: :email},
|
|
|
|
name: %Schema{type: :string}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
required: true
|
|
|
|
),
|
2020-05-26 11:13:39 +02:00
|
|
|
responses: %{
|
2020-05-26 13:02:51 +02:00
|
|
|
204 => no_content_response(),
|
|
|
|
400 => Operation.response("Bad Request", "application/json", ApiError),
|
|
|
|
403 => Operation.response("Forbidden", "application/json", ApiError)
|
2020-05-26 11:13:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-05-26 13:02:51 +02:00
|
|
|
defp invite do
|
2020-05-26 11:13:39 +02:00
|
|
|
%Schema{
|
2020-05-26 13:02:51 +02:00
|
|
|
title: "Invite",
|
2020-05-26 11:13:39 +02:00
|
|
|
type: :object,
|
|
|
|
properties: %{
|
2020-05-26 13:02:51 +02:00
|
|
|
id: %Schema{type: :integer},
|
|
|
|
token: %Schema{type: :string},
|
|
|
|
used: %Schema{type: :boolean},
|
|
|
|
expires_at: %Schema{type: :string, format: :date, nullable: true},
|
|
|
|
uses: %Schema{type: :integer},
|
|
|
|
max_use: %Schema{type: :integer, nullable: true},
|
|
|
|
invite_type: %Schema{
|
|
|
|
type: :string,
|
|
|
|
enum: ["one_time", "reusable", "date_limited", "reusable_date_limited"]
|
|
|
|
}
|
2020-05-26 11:13:39 +02:00
|
|
|
},
|
|
|
|
example: %{
|
2020-05-26 13:02:51 +02:00
|
|
|
"id" => 123,
|
|
|
|
"token" => "kSQtDj_GNy2NZsL9AQDFIsHN5qdbguB6qRg3WHw6K1U=",
|
|
|
|
"used" => true,
|
|
|
|
"expires_at" => nil,
|
|
|
|
"uses" => 0,
|
|
|
|
"max_use" => nil,
|
|
|
|
"invite_type" => "one_time"
|
2020-05-26 11:13:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|