TwitterAPI: Make change_password require body params instead of query
[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 parameters: [
105 Operation.parameter(:password, :query, :string, "Current password", required: true),
106 Operation.parameter(:email, :query, :string, "New email", required: true)
107 ],
108 requestBody: nil,
109 responses: %{
110 200 =>
111 Operation.response("Success", "application/json", %Schema{
112 type: :object,
113 properties: %{status: %Schema{type: :string, example: "success"}}
114 }),
115 400 => Operation.response("Error", "application/json", ApiError),
116 403 => Operation.response("Error", "application/json", ApiError)
117 }
118 }
119 end
120
121 def update_notificaton_settings_operation do
122 %Operation{
123 tags: ["Accounts"],
124 summary: "Update Notification Settings",
125 security: [%{"oAuth" => ["write:accounts"]}],
126 operationId: "UtilController.update_notificaton_settings",
127 parameters: [
128 Operation.parameter(
129 :block_from_strangers,
130 :query,
131 BooleanLike,
132 "blocks notifications from accounts you do not follow"
133 ),
134 Operation.parameter(
135 :hide_notification_contents,
136 :query,
137 BooleanLike,
138 "removes the contents of a message from the push notification"
139 )
140 ],
141 requestBody: nil,
142 responses: %{
143 200 =>
144 Operation.response("Success", "application/json", %Schema{
145 type: :object,
146 properties: %{status: %Schema{type: :string, example: "success"}}
147 }),
148 400 => Operation.response("Error", "application/json", ApiError)
149 }
150 }
151 end
152
153 def disable_account_operation do
154 %Operation{
155 tags: ["Account credentials"],
156 summary: "Disable Account",
157 security: [%{"oAuth" => ["write:accounts"]}],
158 operationId: "UtilController.disable_account",
159 parameters: [
160 Operation.parameter(:password, :query, :string, "Password")
161 ],
162 responses: %{
163 200 =>
164 Operation.response("Success", "application/json", %Schema{
165 type: :object,
166 properties: %{status: %Schema{type: :string, example: "success"}}
167 }),
168 403 => Operation.response("Error", "application/json", ApiError)
169 }
170 }
171 end
172
173 def delete_account_operation do
174 %Operation{
175 tags: ["Account credentials"],
176 summary: "Delete Account",
177 security: [%{"oAuth" => ["write:accounts"]}],
178 operationId: "UtilController.delete_account",
179 parameters: [
180 Operation.parameter(:password, :query, :string, "Password")
181 ],
182 responses: %{
183 200 =>
184 Operation.response("Success", "application/json", %Schema{
185 type: :object,
186 properties: %{status: %Schema{type: :string, example: "success"}}
187 }),
188 403 => Operation.response("Error", "application/json", ApiError)
189 }
190 }
191 end
192
193 def captcha_operation do
194 %Operation{
195 summary: "Get a captcha",
196 operationId: "UtilController.captcha",
197 parameters: [],
198 responses: %{
199 200 => Operation.response("Success", "application/json", %Schema{type: :object})
200 }
201 }
202 end
203
204 def healthcheck_operation do
205 %Operation{
206 tags: ["Accounts"],
207 summary: "Quick status check on the instance",
208 security: [%{"oAuth" => ["write:accounts"]}],
209 operationId: "UtilController.healthcheck",
210 parameters: [],
211 responses: %{
212 200 => Operation.response("Healthy", "application/json", %Schema{type: :object}),
213 503 =>
214 Operation.response("Disabled or Unhealthy", "application/json", %Schema{type: :object})
215 }
216 }
217 end
218
219 def remote_subscribe_operation do
220 %Operation{
221 tags: ["Accounts"],
222 summary: "Remote Subscribe",
223 operationId: "UtilController.remote_subscribe",
224 parameters: [],
225 responses: %{200 => Operation.response("Web Page", "test/html", %Schema{type: :string})}
226 }
227 end
228 end