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