logo

pleroma

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

report_operation.ex (2505B)


  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. },
  54. required: [:account_id],
  55. example: %{
  56. "account_id" => "123",
  57. "status_ids" => ["1337"],
  58. "comment" => "bad status!",
  59. "forward" => "false"
  60. }
  61. }
  62. end
  63. defp create_response do
  64. %Schema{
  65. title: "ReportResponse",
  66. type: :object,
  67. properties: %{
  68. id: %Schema{type: :string, description: "Report ID"},
  69. action_taken: %Schema{type: :boolean, description: "Is action taken?"}
  70. },
  71. example: %{
  72. "id" => "123",
  73. "action_taken" => false
  74. }
  75. }
  76. end
  77. end