Merge branch '2317-old-reset-tokens' into 'develop'
[akkoma] / lib / pleroma / web / api_spec / operations / domain_block_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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: "Fetch domain blocks",
19 description: "View domains the user has blocked.",
20 security: [%{"oAuth" => ["follow", "read:blocks"]}],
21 operationId: "DomainBlockController.index",
22 responses: %{
23 200 =>
24 Operation.response("Domain blocks", "application/json", %Schema{
25 description: "Response schema for domain blocks",
26 type: :array,
27 items: %Schema{type: :string},
28 example: ["google.com", "facebook.com"]
29 })
30 }
31 }
32 end
33
34 # Supporting domain query parameter is deprecated in Mastodon API
35 def create_operation do
36 %Operation{
37 tags: ["domain_blocks"],
38 summary: "Block a domain",
39 description: """
40 Block a domain to:
41
42 - hide all public posts from it
43 - hide all notifications from it
44 - remove all followers from it
45 - prevent following new users from it (but does not remove existing follows)
46 """,
47 operationId: "DomainBlockController.create",
48 requestBody: domain_block_request(),
49 parameters: [Operation.parameter(:domain, :query, %Schema{type: :string}, "Domain name")],
50 security: [%{"oAuth" => ["follow", "write:blocks"]}],
51 responses: %{200 => empty_object_response()}
52 }
53 end
54
55 # Supporting domain query parameter is deprecated in Mastodon API
56 def delete_operation do
57 %Operation{
58 tags: ["domain_blocks"],
59 summary: "Unblock a domain",
60 description: "Remove a domain block, if it exists in the user's array of blocked domains.",
61 operationId: "DomainBlockController.delete",
62 requestBody: domain_block_request(),
63 parameters: [Operation.parameter(:domain, :query, %Schema{type: :string}, "Domain name")],
64 security: [%{"oAuth" => ["follow", "write:blocks"]}],
65 responses: %{
66 200 => Operation.response("Empty object", "application/json", %Schema{type: :object})
67 }
68 }
69 end
70
71 defp domain_block_request do
72 request_body(
73 "Parameters",
74 %Schema{
75 type: :object,
76 properties: %{
77 domain: %Schema{type: :string}
78 }
79 },
80 required: false,
81 example: %{
82 "domain" => "facebook.com"
83 }
84 )
85 end
86 end