logo

pleroma

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

report_operation.ex (2703B)


  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.ReportOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. alias Pleroma.Web.ApiSpec.Helpers
  8. alias Pleroma.Web.ApiSpec.Schemas.ApiError
  9. alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
  10. def open_api_operation(action) do
  11. operation = String.to_existing_atom("#{action}_operation")
  12. apply(__MODULE__, operation, [])
  13. end
  14. def create_operation do
  15. %Operation{
  16. tags: ["Reports"],
  17. summary: "File a report",
  18. description: "Report problematic users to your moderators",
  19. operationId: "ReportController.create",
  20. security: [%{"oAuth" => ["follow", "write:reports"]}],
  21. requestBody: Helpers.request_body("Parameters", create_request(), required: true),
  22. responses: %{
  23. 200 => Operation.response("Report", "application/json", create_response()),
  24. 400 => Operation.response("Report", "application/json", ApiError)
  25. }
  26. }
  27. end
  28. defp create_request do
  29. %Schema{
  30. title: "ReportCreateRequest",
  31. description: "POST body for creating a report",
  32. type: :object,
  33. properties: %{
  34. account_id: %Schema{type: :string, description: "ID of the account to report"},
  35. status_ids: %Schema{
  36. type: :array,
  37. nullable: true,
  38. items: %Schema{type: :string},
  39. description: "Array of Statuses to attach to the report, for context"
  40. },
  41. comment: %Schema{
  42. type: :string,
  43. nullable: true,
  44. description: "Reason for the report"
  45. },
  46. forward: %Schema{
  47. allOf: [BooleanLike],
  48. nullable: true,
  49. default: false,
  50. description:
  51. "If the account is remote, should the report be forwarded to the remote admin?"
  52. },
  53. rule_ids: %Schema{
  54. type: :array,
  55. nullable: true,
  56. items: %Schema{type: :string},
  57. description: "Array of rules"
  58. }
  59. },
  60. required: [:account_id],
  61. example: %{
  62. "account_id" => "123",
  63. "status_ids" => ["1337"],
  64. "comment" => "bad status!",
  65. "forward" => "false",
  66. "rule_ids" => ["3"]
  67. }
  68. }
  69. end
  70. defp create_response do
  71. %Schema{
  72. title: "ReportResponse",
  73. type: :object,
  74. properties: %{
  75. id: %Schema{type: :string, description: "Report ID"},
  76. action_taken: %Schema{type: :boolean, description: "Is action taken?"}
  77. },
  78. example: %{
  79. "id" => "123",
  80. "action_taken" => false
  81. }
  82. }
  83. end
  84. end