logo

pleroma

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

user_import_operation.ex (2414B)


  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.UserImportOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. alias Pleroma.Web.ApiSpec.Schemas.ApiError
  8. import Pleroma.Web.ApiSpec.Helpers
  9. @spec open_api_operation(atom) :: Operation.t()
  10. def open_api_operation(action) do
  11. operation = String.to_existing_atom("#{action}_operation")
  12. apply(__MODULE__, operation, [])
  13. end
  14. def follow_operation do
  15. %Operation{
  16. tags: ["Data import"],
  17. summary: "Import follows",
  18. operationId: "UserImportController.follow",
  19. requestBody: request_body("Parameters", import_request(), required: true),
  20. responses: %{
  21. 200 => ok_response(),
  22. 403 => Operation.response("Error", "application/json", ApiError),
  23. 500 => Operation.response("Error", "application/json", ApiError)
  24. },
  25. security: [%{"oAuth" => ["write:follow"]}]
  26. }
  27. end
  28. def blocks_operation do
  29. %Operation{
  30. tags: ["Data import"],
  31. summary: "Import blocks",
  32. operationId: "UserImportController.blocks",
  33. requestBody: request_body("Parameters", import_request(), required: true),
  34. responses: %{
  35. 200 => ok_response(),
  36. 500 => Operation.response("Error", "application/json", ApiError)
  37. },
  38. security: [%{"oAuth" => ["write:blocks"]}]
  39. }
  40. end
  41. def mutes_operation do
  42. %Operation{
  43. tags: ["Data import"],
  44. summary: "Import mutes",
  45. operationId: "UserImportController.mutes",
  46. requestBody: request_body("Parameters", import_request(), required: true),
  47. responses: %{
  48. 200 => ok_response(),
  49. 500 => Operation.response("Error", "application/json", ApiError)
  50. },
  51. security: [%{"oAuth" => ["write:mutes"]}]
  52. }
  53. end
  54. defp import_request do
  55. %Schema{
  56. type: :object,
  57. required: [:list],
  58. properties: %{
  59. list: %Schema{
  60. description:
  61. "STRING or FILE containing a whitespace-separated list of accounts to import.",
  62. anyOf: [
  63. %Schema{type: :string, format: :binary},
  64. %Schema{type: :string}
  65. ]
  66. }
  67. }
  68. }
  69. end
  70. defp ok_response do
  71. Operation.response("Ok", "application/json", %Schema{type: :string, example: "ok"})
  72. end
  73. end