Merge branch 'update/oban' into 'develop'
[akkoma] / lib / pleroma / web / api_spec / operations / admin / status_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.Admin.StatusOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.Account
9 alias Pleroma.Web.ApiSpec.Schemas.ApiError
10 alias Pleroma.Web.ApiSpec.Schemas.FlakeID
11 alias Pleroma.Web.ApiSpec.Schemas.Status
12 alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
13
14 import Pleroma.Web.ApiSpec.Helpers
15 import Pleroma.Web.ApiSpec.StatusOperation, only: [id_param: 0]
16
17 def open_api_operation(action) do
18 operation = String.to_existing_atom("#{action}_operation")
19 apply(__MODULE__, operation, [])
20 end
21
22 def index_operation do
23 %Operation{
24 tags: ["Admin", "Statuses"],
25 operationId: "AdminAPI.StatusController.index",
26 security: [%{"oAuth" => ["read:statuses"]}],
27 parameters: [
28 Operation.parameter(
29 :godmode,
30 :query,
31 %Schema{type: :boolean, default: false},
32 "Allows to see private statuses"
33 ),
34 Operation.parameter(
35 :local_only,
36 :query,
37 %Schema{type: :boolean, default: false},
38 "Excludes remote statuses"
39 ),
40 Operation.parameter(
41 :with_reblogs,
42 :query,
43 %Schema{type: :boolean, default: false},
44 "Allows to see reblogs"
45 ),
46 Operation.parameter(
47 :page,
48 :query,
49 %Schema{type: :integer, default: 1},
50 "Page"
51 ),
52 Operation.parameter(
53 :page_size,
54 :query,
55 %Schema{type: :integer, default: 50},
56 "Number of statuses to return"
57 )
58 | admin_api_params()
59 ],
60 responses: %{
61 200 =>
62 Operation.response("Array of statuses", "application/json", %Schema{
63 type: :array,
64 items: status()
65 })
66 }
67 }
68 end
69
70 def show_operation do
71 %Operation{
72 tags: ["Admin", "Statuses"],
73 summary: "Show Status",
74 operationId: "AdminAPI.StatusController.show",
75 parameters: [id_param() | admin_api_params()],
76 security: [%{"oAuth" => ["read:statuses"]}],
77 responses: %{
78 200 => Operation.response("Status", "application/json", status()),
79 404 => Operation.response("Not Found", "application/json", ApiError)
80 }
81 }
82 end
83
84 def update_operation do
85 %Operation{
86 tags: ["Admin", "Statuses"],
87 summary: "Change the scope of an individual reported status",
88 operationId: "AdminAPI.StatusController.update",
89 parameters: [id_param() | admin_api_params()],
90 security: [%{"oAuth" => ["write:statuses"]}],
91 requestBody: request_body("Parameters", update_request(), required: true),
92 responses: %{
93 200 => Operation.response("Status", "application/json", Status),
94 400 => Operation.response("Error", "application/json", ApiError)
95 }
96 }
97 end
98
99 def delete_operation do
100 %Operation{
101 tags: ["Admin", "Statuses"],
102 summary: "Delete an individual reported status",
103 operationId: "AdminAPI.StatusController.delete",
104 parameters: [id_param() | admin_api_params()],
105 security: [%{"oAuth" => ["write:statuses"]}],
106 responses: %{
107 200 => empty_object_response(),
108 404 => Operation.response("Not Found", "application/json", ApiError)
109 }
110 }
111 end
112
113 defp status do
114 %Schema{
115 anyOf: [
116 Status,
117 %Schema{
118 type: :object,
119 properties: %{
120 account: %Schema{allOf: [Account, admin_account()]}
121 }
122 }
123 ]
124 }
125 end
126
127 def admin_account do
128 %Schema{
129 type: :object,
130 properties: %{
131 id: FlakeID,
132 avatar: %Schema{type: :string},
133 nickname: %Schema{type: :string},
134 display_name: %Schema{type: :string},
135 deactivated: %Schema{type: :boolean},
136 local: %Schema{type: :boolean},
137 roles: %Schema{
138 type: :object,
139 properties: %{
140 admin: %Schema{type: :boolean},
141 moderator: %Schema{type: :boolean}
142 }
143 },
144 tags: %Schema{type: :string},
145 is_confirmed: %Schema{type: :string}
146 }
147 }
148 end
149
150 defp update_request do
151 %Schema{
152 type: :object,
153 properties: %{
154 sensitive: %Schema{
155 type: :boolean,
156 description: "Mark status and attached media as sensitive?"
157 },
158 visibility: VisibilityScope
159 },
160 example: %{
161 "visibility" => "private",
162 "sensitive" => "false"
163 }
164 }
165 end
166 end