logo

pleroma

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

domain_block_operation.ex (2708B)


  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.DomainBlockOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. import Pleroma.Web.ApiSpec.Helpers
  8. def open_api_operation(action) do
  9. operation = String.to_existing_atom("#{action}_operation")
  10. apply(__MODULE__, operation, [])
  11. end
  12. def index_operation do
  13. %Operation{
  14. tags: ["Domain blocks"],
  15. summary: "Retrieve a list of blocked domains",
  16. security: [%{"oAuth" => ["follow", "read:blocks"]}],
  17. operationId: "DomainBlockController.index",
  18. responses: %{
  19. 200 =>
  20. Operation.response("Domain blocks", "application/json", %Schema{
  21. description: "Response schema for domain blocks",
  22. type: :array,
  23. items: %Schema{type: :string},
  24. example: ["google.com", "facebook.com"]
  25. })
  26. }
  27. }
  28. end
  29. # Supporting domain query parameter is deprecated in Mastodon API
  30. def create_operation do
  31. %Operation{
  32. tags: ["Domain blocks"],
  33. summary: "Block a domain",
  34. description: """
  35. Block a domain to:
  36. - hide all public posts from it
  37. - hide all notifications from it
  38. - remove all followers from it
  39. - prevent following new users from it (but does not remove existing follows)
  40. """,
  41. operationId: "DomainBlockController.create",
  42. requestBody: domain_block_request(),
  43. parameters: [Operation.parameter(:domain, :query, %Schema{type: :string}, "Domain name")],
  44. security: [%{"oAuth" => ["follow", "write:blocks"]}],
  45. responses: %{200 => empty_object_response()}
  46. }
  47. end
  48. # Supporting domain query parameter is deprecated in Mastodon API
  49. def delete_operation do
  50. %Operation{
  51. tags: ["Domain blocks"],
  52. summary: "Unblock a domain",
  53. description: "Remove a domain block, if it exists in the user's array of blocked domains.",
  54. operationId: "DomainBlockController.delete",
  55. requestBody: domain_block_request(),
  56. parameters: [Operation.parameter(:domain, :query, %Schema{type: :string}, "Domain name")],
  57. security: [%{"oAuth" => ["follow", "write:blocks"]}],
  58. responses: %{
  59. 200 => Operation.response("Empty object", "application/json", %Schema{type: :object})
  60. }
  61. }
  62. end
  63. defp domain_block_request do
  64. request_body(
  65. "Parameters",
  66. %Schema{
  67. type: :object,
  68. properties: %{
  69. domain: %Schema{type: :string}
  70. }
  71. },
  72. required: false,
  73. example: %{
  74. "domain" => "facebook.com"
  75. }
  76. )
  77. end
  78. end