logo

pleroma

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

config_operation.ex (4422B)


  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.ConfigOperation 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 show_operation do
  14. %Operation{
  15. tags: ["Instance configuration"],
  16. summary: "Retrieve instance configuration",
  17. operationId: "AdminAPI.ConfigController.show",
  18. parameters: [
  19. Operation.parameter(
  20. :only_db,
  21. :query,
  22. %Schema{type: :boolean, default: false},
  23. "Get only saved in database settings"
  24. )
  25. | admin_api_params()
  26. ],
  27. security: [%{"oAuth" => ["admin:read"]}],
  28. responses: %{
  29. 200 => Operation.response("Config", "application/json", config_response()),
  30. 400 => Operation.response("Bad Request", "application/json", ApiError)
  31. }
  32. }
  33. end
  34. def update_operation do
  35. %Operation{
  36. tags: ["Instance configuration"],
  37. summary: "Update instance configuration",
  38. operationId: "AdminAPI.ConfigController.update",
  39. security: [%{"oAuth" => ["admin:write"]}],
  40. parameters: admin_api_params(),
  41. requestBody:
  42. request_body("Parameters", %Schema{
  43. type: :object,
  44. properties: %{
  45. configs: %Schema{
  46. type: :array,
  47. items: %Schema{
  48. type: :object,
  49. properties: %{
  50. group: %Schema{type: :string},
  51. key: %Schema{type: :string},
  52. value: any(),
  53. delete: %Schema{type: :boolean},
  54. subkeys: %Schema{type: :array, items: %Schema{type: :string}}
  55. }
  56. }
  57. }
  58. }
  59. }),
  60. responses: %{
  61. 200 => Operation.response("Config", "application/json", config_response()),
  62. 400 => Operation.response("Bad Request", "application/json", ApiError)
  63. }
  64. }
  65. end
  66. def descriptions_operation do
  67. %Operation{
  68. tags: ["Instance configuration"],
  69. summary: "Retrieve config description",
  70. operationId: "AdminAPI.ConfigController.descriptions",
  71. security: [%{"oAuth" => ["admin:read"]}],
  72. parameters: admin_api_params(),
  73. responses: %{
  74. 200 =>
  75. Operation.response("Config Descriptions", "application/json", %Schema{
  76. type: :array,
  77. items: %Schema{
  78. type: :object,
  79. properties: %{
  80. group: %Schema{type: :string},
  81. key: %Schema{type: :string},
  82. type: %Schema{oneOf: [%Schema{type: :string}, %Schema{type: :array}]},
  83. description: %Schema{type: :string},
  84. children: %Schema{
  85. type: :array,
  86. items: %Schema{
  87. type: :object,
  88. properties: %{
  89. key: %Schema{type: :string},
  90. type: %Schema{oneOf: [%Schema{type: :string}, %Schema{type: :array}]},
  91. description: %Schema{type: :string},
  92. suggestions: %Schema{type: :array}
  93. }
  94. }
  95. }
  96. }
  97. }
  98. }),
  99. 400 => Operation.response("Bad Request", "application/json", ApiError)
  100. }
  101. }
  102. end
  103. defp any do
  104. %Schema{
  105. oneOf: [
  106. %Schema{type: :array},
  107. %Schema{type: :object},
  108. %Schema{type: :string},
  109. %Schema{type: :integer},
  110. %Schema{type: :boolean}
  111. ]
  112. }
  113. end
  114. defp config_response do
  115. %Schema{
  116. type: :object,
  117. properties: %{
  118. configs: %Schema{
  119. type: :array,
  120. items: %Schema{
  121. type: :object,
  122. properties: %{
  123. group: %Schema{type: :string},
  124. key: %Schema{type: :string},
  125. value: any()
  126. }
  127. }
  128. },
  129. need_reboot: %Schema{
  130. type: :boolean,
  131. description:
  132. "If `need_reboot` is `true`, instance must be restarted, so reboot time settings can take effect"
  133. }
  134. }
  135. }
  136. end
  137. end