logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

twitter_util_operation.ex (13963B)


  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. defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. alias Pleroma.Web.ApiSpec.Schemas.ApiError
  8. alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
  9. import Pleroma.Web.ApiSpec.Helpers
  10. def open_api_operation(action) do
  11. operation = String.to_existing_atom("#{action}_operation")
  12. apply(__MODULE__, operation, [])
  13. end
  14. def emoji_operation do
  15. %Operation{
  16. tags: ["Custom emojis"],
  17. summary: "List all custom emojis",
  18. operationId: "UtilController.emoji",
  19. parameters: [],
  20. responses: %{
  21. 200 =>
  22. Operation.response("List", "application/json", %Schema{
  23. type: :object,
  24. additionalProperties: %Schema{
  25. type: :object,
  26. properties: %{
  27. image_url: %Schema{type: :string},
  28. tags: %Schema{type: :array, items: %Schema{type: :string}}
  29. },
  30. extensions: %{"x-additionalPropertiesName": "Emoji name"}
  31. },
  32. example: %{
  33. "firefox" => %{
  34. "image_url" => "/emoji/firefox.png",
  35. "tag" => ["Fun"]
  36. }
  37. }
  38. })
  39. }
  40. }
  41. end
  42. def frontend_configurations_operation do
  43. %Operation{
  44. tags: ["Others"],
  45. summary: "Dump frontend configurations",
  46. operationId: "UtilController.frontend_configurations",
  47. parameters: [],
  48. responses: %{
  49. 200 =>
  50. Operation.response("List", "application/json", %Schema{
  51. type: :object,
  52. additionalProperties: %Schema{
  53. type: :object,
  54. description:
  55. "Opaque object representing the instance-wide configuration for the frontend",
  56. extensions: %{"x-additionalPropertiesName": "Frontend name"}
  57. }
  58. })
  59. }
  60. }
  61. end
  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. defp change_password_request do
  81. %Schema{
  82. title: "ChangePasswordRequest",
  83. description: "POST body for changing the account's password",
  84. type: :object,
  85. required: [:password, :new_password, :new_password_confirmation],
  86. properties: %{
  87. password: %Schema{type: :string, description: "Current password"},
  88. new_password: %Schema{type: :string, description: "New password"},
  89. new_password_confirmation: %Schema{
  90. type: :string,
  91. description: "New password, confirmation"
  92. }
  93. }
  94. }
  95. end
  96. def change_email_operation do
  97. %Operation{
  98. tags: ["Account credentials"],
  99. summary: "Change account email",
  100. security: [%{"oAuth" => ["write:accounts"]}],
  101. operationId: "UtilController.change_email",
  102. requestBody: request_body("Parameters", change_email_request(), required: true),
  103. responses: %{
  104. 200 =>
  105. Operation.response("Success", "application/json", %Schema{
  106. type: :object,
  107. properties: %{status: %Schema{type: :string, example: "success"}}
  108. }),
  109. 400 => Operation.response("Error", "application/json", ApiError),
  110. 403 => Operation.response("Error", "application/json", ApiError)
  111. }
  112. }
  113. end
  114. defp change_email_request do
  115. %Schema{
  116. title: "ChangeEmailRequest",
  117. description: "POST body for changing the account's email",
  118. type: :object,
  119. required: [:email, :password],
  120. properties: %{
  121. email: %Schema{
  122. type: :string,
  123. description: "New email. Set to blank to remove the user's email."
  124. },
  125. password: %Schema{type: :string, description: "Current password"}
  126. }
  127. }
  128. end
  129. def update_notification_settings_operation do
  130. %Operation{
  131. tags: ["Settings"],
  132. summary: "Update Notification Settings",
  133. security: [%{"oAuth" => ["write:accounts"]}],
  134. operationId: "UtilController.update_notification_settings",
  135. parameters: [
  136. Operation.parameter(
  137. :block_from_strangers,
  138. :query,
  139. BooleanLike.schema(),
  140. "blocks notifications from accounts you do not follow"
  141. ),
  142. Operation.parameter(
  143. :hide_notification_contents,
  144. :query,
  145. BooleanLike.schema(),
  146. "removes the contents of a message from the push notification"
  147. )
  148. ],
  149. requestBody: nil,
  150. responses: %{
  151. 200 =>
  152. Operation.response("Success", "application/json", %Schema{
  153. type: :object,
  154. properties: %{status: %Schema{type: :string, example: "success"}}
  155. }),
  156. 400 => Operation.response("Error", "application/json", ApiError)
  157. }
  158. }
  159. end
  160. def disable_account_operation do
  161. %Operation{
  162. tags: ["Account credentials"],
  163. summary: "Disable Account",
  164. security: [%{"oAuth" => ["write:accounts"]}],
  165. operationId: "UtilController.disable_account",
  166. parameters: [
  167. Operation.parameter(:password, :query, :string, "Password")
  168. ],
  169. responses: %{
  170. 200 =>
  171. Operation.response("Success", "application/json", %Schema{
  172. type: :object,
  173. properties: %{status: %Schema{type: :string, example: "success"}}
  174. }),
  175. 403 => Operation.response("Error", "application/json", ApiError)
  176. }
  177. }
  178. end
  179. def delete_account_operation do
  180. %Operation{
  181. tags: ["Account credentials"],
  182. summary: "Delete Account",
  183. security: [%{"oAuth" => ["write:accounts"]}],
  184. operationId: "UtilController.delete_account",
  185. parameters: [
  186. Operation.parameter(:password, :query, :string, "Password")
  187. ],
  188. requestBody: request_body("Parameters", delete_account_request(), required: false),
  189. responses: %{
  190. 200 =>
  191. Operation.response("Success", "application/json", %Schema{
  192. type: :object,
  193. properties: %{status: %Schema{type: :string, example: "success"}}
  194. }),
  195. 403 => Operation.response("Error", "application/json", ApiError)
  196. }
  197. }
  198. end
  199. def captcha_operation do
  200. %Operation{
  201. summary: "Get a captcha",
  202. operationId: "UtilController.captcha",
  203. tags: ["Others"],
  204. parameters: [],
  205. responses: %{
  206. 200 => Operation.response("Success", "application/json", %Schema{type: :object})
  207. }
  208. }
  209. end
  210. def move_account_operation do
  211. %Operation{
  212. tags: ["Account credentials"],
  213. summary: "Move account",
  214. security: [%{"oAuth" => ["write:accounts"]}],
  215. operationId: "UtilController.move_account",
  216. requestBody: request_body("Parameters", move_account_request(), required: true),
  217. responses: %{
  218. 200 =>
  219. Operation.response("Success", "application/json", %Schema{
  220. type: :object,
  221. properties: %{status: %Schema{type: :string, example: "success"}}
  222. }),
  223. 400 => Operation.response("Error", "application/json", ApiError),
  224. 403 => Operation.response("Error", "application/json", ApiError),
  225. 404 => Operation.response("Error", "application/json", ApiError)
  226. }
  227. }
  228. end
  229. defp move_account_request do
  230. %Schema{
  231. title: "MoveAccountRequest",
  232. description: "POST body for moving the account",
  233. type: :object,
  234. required: [:password, :target_account],
  235. properties: %{
  236. password: %Schema{type: :string, description: "Current password"},
  237. target_account: %Schema{
  238. type: :string,
  239. description: "The nickname of the target account to move to"
  240. }
  241. }
  242. }
  243. end
  244. def list_aliases_operation do
  245. %Operation{
  246. tags: ["Account credentials"],
  247. summary: "List account aliases",
  248. security: [%{"oAuth" => ["read:accounts"]}],
  249. operationId: "UtilController.list_aliases",
  250. responses: %{
  251. 200 =>
  252. Operation.response("Success", "application/json", %Schema{
  253. type: :object,
  254. properties: %{
  255. aliases: %Schema{
  256. type: :array,
  257. items: %Schema{type: :string},
  258. example: ["foo@example.org"]
  259. }
  260. }
  261. }),
  262. 400 => Operation.response("Error", "application/json", ApiError),
  263. 403 => Operation.response("Error", "application/json", ApiError)
  264. }
  265. }
  266. end
  267. def add_alias_operation do
  268. %Operation{
  269. tags: ["Account credentials"],
  270. summary: "Add an alias to this account",
  271. security: [%{"oAuth" => ["write:accounts"]}],
  272. operationId: "UtilController.add_alias",
  273. requestBody: request_body("Parameters", add_alias_request(), required: true),
  274. responses: %{
  275. 200 =>
  276. Operation.response("Success", "application/json", %Schema{
  277. type: :object,
  278. properties: %{
  279. status: %Schema{
  280. type: :string,
  281. example: "success"
  282. }
  283. }
  284. }),
  285. 400 => Operation.response("Error", "application/json", ApiError),
  286. 403 => Operation.response("Error", "application/json", ApiError),
  287. 404 => Operation.response("Error", "application/json", ApiError)
  288. }
  289. }
  290. end
  291. defp add_alias_request do
  292. %Schema{
  293. title: "AddAliasRequest",
  294. description: "PUT body for adding aliases",
  295. type: :object,
  296. required: [:alias],
  297. properties: %{
  298. alias: %Schema{
  299. type: :string,
  300. description: "The nickname of the account to add to aliases"
  301. }
  302. }
  303. }
  304. end
  305. def delete_alias_operation do
  306. %Operation{
  307. tags: ["Account credentials"],
  308. summary: "Delete an alias from this account",
  309. security: [%{"oAuth" => ["write:accounts"]}],
  310. operationId: "UtilController.delete_alias",
  311. requestBody: request_body("Parameters", delete_alias_request(), required: true),
  312. responses: %{
  313. 200 =>
  314. Operation.response("Success", "application/json", %Schema{
  315. type: :object,
  316. properties: %{
  317. status: %Schema{
  318. type: :string,
  319. example: "success"
  320. }
  321. }
  322. }),
  323. 400 => Operation.response("Error", "application/json", ApiError),
  324. 403 => Operation.response("Error", "application/json", ApiError),
  325. 404 => Operation.response("Error", "application/json", ApiError)
  326. }
  327. }
  328. end
  329. defp delete_alias_request do
  330. %Schema{
  331. title: "DeleteAliasRequest",
  332. description: "PUT body for deleting aliases",
  333. type: :object,
  334. required: [:alias],
  335. properties: %{
  336. alias: %Schema{
  337. type: :string,
  338. description: "The nickname of the account to delete from aliases"
  339. }
  340. }
  341. }
  342. end
  343. def healthcheck_operation do
  344. %Operation{
  345. tags: ["Others"],
  346. summary: "Quick status check on the instance",
  347. security: [%{"oAuth" => ["write:accounts"]}],
  348. operationId: "UtilController.healthcheck",
  349. parameters: [],
  350. responses: %{
  351. 200 => Operation.response("Healthy", "application/json", %Schema{type: :object}),
  352. 503 =>
  353. Operation.response("Disabled or Unhealthy", "application/json", %Schema{type: :object})
  354. }
  355. }
  356. end
  357. def remote_subscribe_operation do
  358. %Operation{
  359. tags: ["Remote interaction"],
  360. summary: "Remote Subscribe",
  361. operationId: "UtilController.remote_subscribe",
  362. parameters: [],
  363. responses: %{200 => Operation.response("Web Page", "test/html", %Schema{type: :string})}
  364. }
  365. end
  366. def remote_interaction_operation do
  367. %Operation{
  368. tags: ["Remote interaction"],
  369. summary: "Remote interaction",
  370. operationId: "UtilController.remote_interaction",
  371. requestBody: request_body("Parameters", remote_interaction_request(), required: true),
  372. responses: %{
  373. 200 =>
  374. Operation.response("Remote interaction URL", "application/json", %Schema{type: :object})
  375. }
  376. }
  377. end
  378. defp remote_interaction_request do
  379. %Schema{
  380. title: "RemoteInteractionRequest",
  381. description: "POST body for remote interaction",
  382. type: :object,
  383. required: [:ap_id, :profile],
  384. properties: %{
  385. ap_id: %Schema{type: :string, description: "Profile or status ActivityPub ID"},
  386. profile: %Schema{type: :string, description: "Remote profile webfinger"}
  387. }
  388. }
  389. end
  390. def show_subscribe_form_operation do
  391. %Operation{
  392. tags: ["Remote interaction"],
  393. summary: "Show remote subscribe form",
  394. operationId: "UtilController.show_subscribe_form",
  395. parameters: [],
  396. responses: %{200 => Operation.response("Web Page", "test/html", %Schema{type: :string})}
  397. }
  398. end
  399. defp delete_account_request do
  400. %Schema{
  401. title: "AccountDeleteRequest",
  402. description: "POST body for deleting one's own account",
  403. type: :object,
  404. properties: %{
  405. password: %Schema{
  406. type: :string,
  407. description: "The user's own password for confirmation.",
  408. format: :password
  409. }
  410. },
  411. example: %{
  412. "password" => "prettyp0ony1313"
  413. }
  414. }
  415. end
  416. end