2a701066d409549e5fcdde77fcc04a0558cc7db9
[akkoma] / lib / pleroma / web / api_spec / operations / twitter_util_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.TwitterUtilOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.ApiError
9 alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
10
11 import Pleroma.Web.ApiSpec.Helpers
12
13 def open_api_operation(action) do
14 operation = String.to_existing_atom("#{action}_operation")
15 apply(__MODULE__, operation, [])
16 end
17
18 def emoji_operation do
19 %Operation{
20 tags: ["Emojis"],
21 summary: "List all custom emojis",
22 operationId: "UtilController.emoji",
23 parameters: [],
24 responses: %{
25 200 =>
26 Operation.response("List", "application/json", %Schema{
27 type: :object,
28 additionalProperties: %Schema{
29 type: :object,
30 properties: %{
31 image_url: %Schema{type: :string},
32 tags: %Schema{type: :array, items: %Schema{type: :string}}
33 }
34 },
35 example: %{
36 "firefox" => %{
37 "image_url" => "/emoji/firefox.png",
38 "tag" => ["Fun"]
39 }
40 }
41 })
42 }
43 }
44 end
45
46 def frontend_configurations_operation do
47 %Operation{
48 tags: ["Configuration"],
49 summary: "Dump frontend configurations",
50 operationId: "UtilController.frontend_configurations",
51 parameters: [],
52 responses: %{
53 200 =>
54 Operation.response("List", "application/json", %Schema{
55 type: :object,
56 additionalProperties: %Schema{type: :object}
57 })
58 }
59 }
60 end
61
62 def change_password_operation do
63 %Operation{
64 tags: ["Account credentials"],
65 summary: "Change account password",
66 security: [%{"oAuth" => ["write:accounts"]}],
67 operationId: "UtilController.change_password",
68 requestBody: request_body("Parameters", change_password_request(), required: true),
69 responses: %{
70 200 =>
71 Operation.response("Success", "application/json", %Schema{
72 type: :object,
73 properties: %{status: %Schema{type: :string, example: "success"}}
74 }),
75 400 => Operation.response("Error", "application/json", ApiError),
76 403 => Operation.response("Error", "application/json", ApiError)
77 }
78 }
79 end
80
81 defp change_password_request do
82 %Schema{
83 title: "ChangePasswordRequest",
84 description: "POST body for changing the account's passowrd",
85 type: :object,
86 required: [:password, :new_password, :new_password_confirmation],
87 properties: %{
88 password: %Schema{type: :string, description: "Current password"},
89 new_password: %Schema{type: :string, description: "New password"},
90 new_password_confirmation: %Schema{
91 type: :string,
92 description: "New password, confirmation"
93 }
94 }
95 }
96 end
97
98 def change_email_operation do
99 %Operation{
100 tags: ["Account credentials"],
101 summary: "Change account email",
102 security: [%{"oAuth" => ["write:accounts"]}],
103 operationId: "UtilController.change_email",
104 requestBody: request_body("Parameters", change_email_request(), required: true),
105 responses: %{
106 200 =>
107 Operation.response("Success", "application/json", %Schema{
108 type: :object,
109 properties: %{status: %Schema{type: :string, example: "success"}}
110 }),
111 400 => Operation.response("Error", "application/json", ApiError),
112 403 => Operation.response("Error", "application/json", ApiError)
113 }
114 }
115 end
116
117 defp change_email_request do
118 %Schema{
119 title: "ChangeEmailRequest",
120 description: "POST body for changing the account's email",
121 type: :object,
122 required: [:email, :password],
123 properties: %{
124 email: %Schema{
125 type: :string,
126 description: "New email. Set to blank to remove the user's email."
127 },
128 password: %Schema{type: :string, description: "Current password"}
129 }
130 }
131 end
132
133 def update_notificaton_settings_operation do
134 %Operation{
135 tags: ["Accounts"],
136 summary: "Update Notification Settings",
137 security: [%{"oAuth" => ["write:accounts"]}],
138 operationId: "UtilController.update_notificaton_settings",
139 parameters: [
140 Operation.parameter(
141 :block_from_strangers,
142 :query,
143 BooleanLike,
144 "blocks notifications from accounts you do not follow"
145 ),
146 Operation.parameter(
147 :hide_notification_contents,
148 :query,
149 BooleanLike,
150 "removes the contents of a message from the push notification"
151 )
152 ],
153 requestBody: nil,
154 responses: %{
155 200 =>
156 Operation.response("Success", "application/json", %Schema{
157 type: :object,
158 properties: %{status: %Schema{type: :string, example: "success"}}
159 }),
160 400 => Operation.response("Error", "application/json", ApiError)
161 }
162 }
163 end
164
165 def disable_account_operation do
166 %Operation{
167 tags: ["Account credentials"],
168 summary: "Disable Account",
169 security: [%{"oAuth" => ["write:accounts"]}],
170 operationId: "UtilController.disable_account",
171 parameters: [
172 Operation.parameter(:password, :query, :string, "Password")
173 ],
174 responses: %{
175 200 =>
176 Operation.response("Success", "application/json", %Schema{
177 type: :object,
178 properties: %{status: %Schema{type: :string, example: "success"}}
179 }),
180 403 => Operation.response("Error", "application/json", ApiError)
181 }
182 }
183 end
184
185 def delete_account_operation do
186 %Operation{
187 tags: ["Account credentials"],
188 summary: "Delete Account",
189 security: [%{"oAuth" => ["write:accounts"]}],
190 operationId: "UtilController.delete_account",
191 parameters: [
192 Operation.parameter(:password, :query, :string, "Password")
193 ],
194 requestBody: request_body("Parameters", delete_account_request(), required: false),
195 responses: %{
196 200 =>
197 Operation.response("Success", "application/json", %Schema{
198 type: :object,
199 properties: %{status: %Schema{type: :string, example: "success"}}
200 }),
201 403 => Operation.response("Error", "application/json", ApiError)
202 }
203 }
204 end
205
206 def captcha_operation do
207 %Operation{
208 summary: "Get a captcha",
209 operationId: "UtilController.captcha",
210 parameters: [],
211 responses: %{
212 200 => Operation.response("Success", "application/json", %Schema{type: :object})
213 }
214 }
215 end
216
217 def healthcheck_operation do
218 %Operation{
219 tags: ["Accounts"],
220 summary: "Quick status check on the instance",
221 security: [%{"oAuth" => ["write:accounts"]}],
222 operationId: "UtilController.healthcheck",
223 parameters: [],
224 responses: %{
225 200 => Operation.response("Healthy", "application/json", %Schema{type: :object}),
226 503 =>
227 Operation.response("Disabled or Unhealthy", "application/json", %Schema{type: :object})
228 }
229 }
230 end
231
232 def remote_subscribe_operation do
233 %Operation{
234 tags: ["Accounts"],
235 summary: "Remote Subscribe",
236 operationId: "UtilController.remote_subscribe",
237 parameters: [],
238 responses: %{200 => Operation.response("Web Page", "test/html", %Schema{type: :string})}
239 }
240 end
241
242 def remote_interaction_operation do
243 %Operation{
244 tags: ["Accounts"],
245 summary: "Remote interaction",
246 operationId: "UtilController.remote_interaction",
247 requestBody: request_body("Parameters", remote_interaction_request(), required: true),
248 responses: %{
249 200 =>
250 Operation.response("Remote interaction URL", "application/json", %Schema{type: :object})
251 }
252 }
253 end
254
255 defp remote_interaction_request do
256 %Schema{
257 title: "RemoteInteractionRequest",
258 description: "POST body for remote interaction",
259 type: :object,
260 required: [:ap_id, :profile],
261 properties: %{
262 ap_id: %Schema{type: :string, description: "Profile or status ActivityPub ID"},
263 profile: %Schema{type: :string, description: "Remote profile webfinger"}
264 }
265 }
266 end
267
268 defp delete_account_request do
269 %Schema{
270 title: "AccountDeleteRequest",
271 description: "POST body for deleting one's own account",
272 type: :object,
273 properties: %{
274 password: %Schema{
275 type: :string,
276 description: "The user's own password for confirmation.",
277 format: :password
278 }
279 },
280 example: %{
281 "password" => "prettyp0ony1313"
282 }
283 }
284 end
285 end