logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

invite_operation.ex (4561B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ApiSpec.Admin.InviteOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. alias Pleroma.Web.ApiSpec.Schemas.ApiError
  8. import Pleroma.Web.ApiSpec.Helpers
  9. def open_api_operation(action) do
  10. operation = String.to_existing_atom("#{action}_operation")
  11. apply(__MODULE__, operation, [])
  12. end
  13. def index_operation do
  14. %Operation{
  15. tags: ["Invites"],
  16. summary: "Get a list of generated invites",
  17. operationId: "AdminAPI.InviteController.index",
  18. security: [%{"oAuth" => ["admin:read:invites"]}],
  19. parameters: admin_api_params(),
  20. responses: %{
  21. 200 =>
  22. Operation.response("Invites", "application/json", %Schema{
  23. type: :object,
  24. properties: %{
  25. invites: %Schema{type: :array, items: invite()}
  26. },
  27. example: %{
  28. "invites" => [
  29. %{
  30. "id" => 123,
  31. "token" => "kSQtDj_GNy2NZsL9AQDFIsHN5qdbguB6qRg3WHw6K1U=",
  32. "used" => true,
  33. "expires_at" => nil,
  34. "uses" => 0,
  35. "max_use" => nil,
  36. "invite_type" => "one_time"
  37. }
  38. ]
  39. }
  40. })
  41. }
  42. }
  43. end
  44. def create_operation do
  45. %Operation{
  46. tags: ["Invites"],
  47. summary: "Create an account registration invite token",
  48. operationId: "AdminAPI.InviteController.create",
  49. security: [%{"oAuth" => ["admin:write:invites"]}],
  50. parameters: admin_api_params(),
  51. requestBody:
  52. request_body("Parameters", %Schema{
  53. type: :object,
  54. properties: %{
  55. max_use: %Schema{type: :integer},
  56. expires_at: %Schema{type: :string, format: :date, example: "2020-04-20"}
  57. }
  58. }),
  59. responses: %{
  60. 200 => Operation.response("Invite", "application/json", invite())
  61. }
  62. }
  63. end
  64. def revoke_operation do
  65. %Operation{
  66. tags: ["Invites"],
  67. summary: "Revoke invite by token",
  68. operationId: "AdminAPI.InviteController.revoke",
  69. security: [%{"oAuth" => ["admin:write:invites"]}],
  70. parameters: admin_api_params(),
  71. requestBody:
  72. request_body(
  73. "Parameters",
  74. %Schema{
  75. type: :object,
  76. required: [:token],
  77. properties: %{
  78. token: %Schema{type: :string}
  79. }
  80. },
  81. required: true
  82. ),
  83. responses: %{
  84. 200 => Operation.response("Invite", "application/json", invite()),
  85. 400 => Operation.response("Bad Request", "application/json", ApiError),
  86. 404 => Operation.response("Not Found", "application/json", ApiError)
  87. }
  88. }
  89. end
  90. def email_operation do
  91. %Operation{
  92. tags: ["Invites"],
  93. summary: "Sends registration invite via email",
  94. operationId: "AdminAPI.InviteController.email",
  95. security: [%{"oAuth" => ["admin:write:invites"]}],
  96. parameters: admin_api_params(),
  97. requestBody:
  98. request_body(
  99. "Parameters",
  100. %Schema{
  101. type: :object,
  102. required: [:email],
  103. properties: %{
  104. email: %Schema{type: :string, format: :email},
  105. name: %Schema{type: :string}
  106. }
  107. },
  108. required: true
  109. ),
  110. responses: %{
  111. 204 => no_content_response(),
  112. 400 => Operation.response("Bad Request", "application/json", ApiError),
  113. 403 => Operation.response("Forbidden", "application/json", ApiError)
  114. }
  115. }
  116. end
  117. defp invite do
  118. %Schema{
  119. title: "Invite",
  120. type: :object,
  121. properties: %{
  122. id: %Schema{type: :integer},
  123. token: %Schema{type: :string},
  124. used: %Schema{type: :boolean},
  125. expires_at: %Schema{type: :string, format: :date, nullable: true},
  126. uses: %Schema{type: :integer},
  127. max_use: %Schema{type: :integer, nullable: true},
  128. invite_type: %Schema{
  129. type: :string,
  130. enum: ["one_time", "reusable", "date_limited", "reusable_date_limited"]
  131. }
  132. },
  133. example: %{
  134. "id" => 123,
  135. "token" => "kSQtDj_GNy2NZsL9AQDFIsHN5qdbguB6qRg3WHw6K1U=",
  136. "used" => true,
  137. "expires_at" => nil,
  138. "uses" => 0,
  139. "max_use" => nil,
  140. "invite_type" => "one_time"
  141. }
  142. }
  143. end
  144. end