logo

pleroma

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

user_operation.ex (14052B)


  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.Admin.UserOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. alias Pleroma.Web.ApiSpec.Schemas.ActorType
  8. alias Pleroma.Web.ApiSpec.Schemas.ApiError
  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 index_operation do
  15. %Operation{
  16. tags: ["User administration"],
  17. summary: "List users",
  18. operationId: "AdminAPI.UserController.index",
  19. security: [%{"oAuth" => ["admin:read:accounts"]}],
  20. parameters: [
  21. Operation.parameter(:filters, :query, :string, "Comma separated list of filters"),
  22. Operation.parameter(:query, :query, :string, "Search users query"),
  23. Operation.parameter(:name, :query, :string, "Search by display name"),
  24. Operation.parameter(:email, :query, :string, "Search by email"),
  25. Operation.parameter(:page, :query, :integer, "Page Number"),
  26. Operation.parameter(:page_size, :query, :integer, "Number of users to return per page"),
  27. Operation.parameter(
  28. :actor_types,
  29. :query,
  30. %Schema{type: :array, items: ActorType},
  31. "Filter by actor type"
  32. ),
  33. Operation.parameter(
  34. :tags,
  35. :query,
  36. %Schema{type: :array, items: %Schema{type: :string}},
  37. "Filter by tags"
  38. )
  39. | admin_api_params()
  40. ],
  41. responses: %{
  42. 200 =>
  43. Operation.response(
  44. "Response",
  45. "application/json",
  46. %Schema{
  47. type: :object,
  48. properties: %{
  49. users: %Schema{type: :array, items: user()},
  50. count: %Schema{type: :integer},
  51. page_size: %Schema{type: :integer}
  52. }
  53. }
  54. ),
  55. 403 => Operation.response("Forbidden", "application/json", ApiError)
  56. }
  57. }
  58. end
  59. def create_operation do
  60. %Operation{
  61. tags: ["User administration"],
  62. summary: "Create a single or multiple users",
  63. operationId: "AdminAPI.UserController.create",
  64. security: [%{"oAuth" => ["admin:write:accounts"]}],
  65. parameters: admin_api_params(),
  66. requestBody:
  67. request_body(
  68. "Parameters",
  69. %Schema{
  70. description: "POST body for creating users",
  71. type: :object,
  72. properties: %{
  73. users: %Schema{
  74. type: :array,
  75. items: %Schema{
  76. type: :object,
  77. properties: %{
  78. nickname: %Schema{type: :string},
  79. email: %Schema{type: :string},
  80. password: %Schema{type: :string}
  81. }
  82. }
  83. }
  84. }
  85. }
  86. ),
  87. responses: %{
  88. 200 =>
  89. Operation.response("Response", "application/json", %Schema{
  90. type: :array,
  91. items: %Schema{
  92. type: :object,
  93. properties: %{
  94. code: %Schema{type: :integer},
  95. type: %Schema{type: :string},
  96. data: %Schema{
  97. type: :object,
  98. properties: %{
  99. email: %Schema{type: :string, format: :email},
  100. nickname: %Schema{type: :string}
  101. }
  102. }
  103. }
  104. }
  105. }),
  106. 403 => Operation.response("Forbidden", "application/json", ApiError),
  107. 409 =>
  108. Operation.response("Conflict", "application/json", %Schema{
  109. type: :array,
  110. items: %Schema{
  111. type: :object,
  112. properties: %{
  113. code: %Schema{type: :integer},
  114. error: %Schema{type: :string},
  115. type: %Schema{type: :string},
  116. data: %Schema{
  117. type: :object,
  118. properties: %{
  119. email: %Schema{type: :string, format: :email},
  120. nickname: %Schema{type: :string}
  121. }
  122. }
  123. }
  124. }
  125. })
  126. }
  127. }
  128. end
  129. def show_operation do
  130. %Operation{
  131. tags: ["User administration"],
  132. summary: "Show user",
  133. operationId: "AdminAPI.UserController.show",
  134. security: [%{"oAuth" => ["admin:read:accounts"]}],
  135. parameters: [
  136. Operation.parameter(
  137. :nickname,
  138. :path,
  139. :string,
  140. "User nickname or ID"
  141. )
  142. | admin_api_params()
  143. ],
  144. responses: %{
  145. 200 => Operation.response("Response", "application/json", user()),
  146. 403 => Operation.response("Forbidden", "application/json", ApiError),
  147. 404 => Operation.response("Not Found", "application/json", ApiError)
  148. }
  149. }
  150. end
  151. def follow_operation do
  152. %Operation{
  153. tags: ["User administration"],
  154. summary: "Follow",
  155. operationId: "AdminAPI.UserController.follow",
  156. security: [%{"oAuth" => ["admin:write:follows"]}],
  157. parameters: admin_api_params(),
  158. requestBody:
  159. request_body(
  160. "Parameters",
  161. %Schema{
  162. type: :object,
  163. properties: %{
  164. follower: %Schema{type: :string, description: "Follower nickname"},
  165. followed: %Schema{type: :string, description: "Followed nickname"}
  166. }
  167. }
  168. ),
  169. responses: %{
  170. 200 => Operation.response("Response", "application/json", %Schema{type: :string}),
  171. 403 => Operation.response("Forbidden", "application/json", ApiError)
  172. }
  173. }
  174. end
  175. def unfollow_operation do
  176. %Operation{
  177. tags: ["User administration"],
  178. summary: "Unfollow",
  179. operationId: "AdminAPI.UserController.unfollow",
  180. security: [%{"oAuth" => ["admin:write:follows"]}],
  181. parameters: admin_api_params(),
  182. requestBody:
  183. request_body(
  184. "Parameters",
  185. %Schema{
  186. type: :object,
  187. properties: %{
  188. follower: %Schema{type: :string, description: "Follower nickname"},
  189. followed: %Schema{type: :string, description: "Followed nickname"}
  190. }
  191. }
  192. ),
  193. responses: %{
  194. 200 => Operation.response("Response", "application/json", %Schema{type: :string}),
  195. 403 => Operation.response("Forbidden", "application/json", ApiError)
  196. }
  197. }
  198. end
  199. def approve_operation do
  200. %Operation{
  201. tags: ["User administration"],
  202. summary: "Approve multiple users",
  203. operationId: "AdminAPI.UserController.approve",
  204. security: [%{"oAuth" => ["admin:write:accounts"]}],
  205. parameters: admin_api_params(),
  206. requestBody:
  207. request_body(
  208. "Parameters",
  209. %Schema{
  210. description: "POST body for approving multiple users",
  211. type: :object,
  212. properties: %{
  213. nicknames: %Schema{
  214. type: :array,
  215. items: %Schema{type: :string}
  216. }
  217. }
  218. }
  219. ),
  220. responses: %{
  221. 200 =>
  222. Operation.response("Response", "application/json", %Schema{
  223. type: :object,
  224. properties: %{user: %Schema{type: :array, items: user()}}
  225. }),
  226. 403 => Operation.response("Forbidden", "application/json", ApiError)
  227. }
  228. }
  229. end
  230. def suggest_operation do
  231. %Operation{
  232. tags: ["User administration"],
  233. summary: "Suggest multiple users",
  234. operationId: "AdminAPI.UserController.suggest",
  235. security: [%{"oAuth" => ["admin:write:accounts"]}],
  236. parameters: admin_api_params(),
  237. requestBody:
  238. request_body(
  239. "Parameters",
  240. %Schema{
  241. description: "POST body for adding multiple suggested users",
  242. type: :object,
  243. properties: %{
  244. nicknames: %Schema{
  245. type: :array,
  246. items: %Schema{type: :string}
  247. }
  248. }
  249. }
  250. ),
  251. responses: %{
  252. 200 =>
  253. Operation.response("Response", "application/json", %Schema{
  254. type: :object,
  255. properties: %{user: %Schema{type: :array, items: user()}}
  256. }),
  257. 403 => Operation.response("Forbidden", "application/json", ApiError)
  258. }
  259. }
  260. end
  261. def unsuggest_operation do
  262. %Operation{
  263. tags: ["User administration"],
  264. summary: "Unsuggest multiple users",
  265. operationId: "AdminAPI.UserController.unsuggest",
  266. security: [%{"oAuth" => ["admin:write:accounts"]}],
  267. parameters: admin_api_params(),
  268. requestBody:
  269. request_body(
  270. "Parameters",
  271. %Schema{
  272. description: "POST body for removing multiple suggested users",
  273. type: :object,
  274. properties: %{
  275. nicknames: %Schema{
  276. type: :array,
  277. items: %Schema{type: :string}
  278. }
  279. }
  280. }
  281. ),
  282. responses: %{
  283. 200 =>
  284. Operation.response("Response", "application/json", %Schema{
  285. type: :object,
  286. properties: %{user: %Schema{type: :array, items: user()}}
  287. }),
  288. 403 => Operation.response("Forbidden", "application/json", ApiError)
  289. }
  290. }
  291. end
  292. def toggle_activation_operation do
  293. %Operation{
  294. tags: ["User administration"],
  295. summary: "Toggle user activation",
  296. operationId: "AdminAPI.UserController.toggle_activation",
  297. security: [%{"oAuth" => ["admin:write:accounts"]}],
  298. parameters: [
  299. Operation.parameter(:nickname, :path, :string, "User nickname")
  300. | admin_api_params()
  301. ],
  302. responses: %{
  303. 200 => Operation.response("Response", "application/json", user()),
  304. 403 => Operation.response("Forbidden", "application/json", ApiError)
  305. }
  306. }
  307. end
  308. def activate_operation do
  309. %Operation{
  310. tags: ["User administration"],
  311. summary: "Activate multiple users",
  312. operationId: "AdminAPI.UserController.activate",
  313. security: [%{"oAuth" => ["admin:write:accounts"]}],
  314. parameters: admin_api_params(),
  315. requestBody:
  316. request_body(
  317. "Parameters",
  318. %Schema{
  319. description: "POST body for deleting multiple users",
  320. type: :object,
  321. properties: %{
  322. nicknames: %Schema{
  323. type: :array,
  324. items: %Schema{type: :string}
  325. }
  326. }
  327. }
  328. ),
  329. responses: %{
  330. 200 =>
  331. Operation.response("Response", "application/json", %Schema{
  332. type: :object,
  333. properties: %{user: %Schema{type: :array, items: user()}}
  334. }),
  335. 403 => Operation.response("Forbidden", "application/json", ApiError)
  336. }
  337. }
  338. end
  339. def deactivate_operation do
  340. %Operation{
  341. tags: ["User administration"],
  342. summary: "Deactivates multiple users",
  343. operationId: "AdminAPI.UserController.deactivate",
  344. security: [%{"oAuth" => ["admin:write:accounts"]}],
  345. parameters: admin_api_params(),
  346. requestBody:
  347. request_body(
  348. "Parameters",
  349. %Schema{
  350. description: "POST body for deleting multiple users",
  351. type: :object,
  352. properties: %{
  353. nicknames: %Schema{
  354. type: :array,
  355. items: %Schema{type: :string}
  356. }
  357. }
  358. }
  359. ),
  360. responses: %{
  361. 200 =>
  362. Operation.response("Response", "application/json", %Schema{
  363. type: :object,
  364. properties: %{user: %Schema{type: :array, items: user()}}
  365. }),
  366. 403 => Operation.response("Forbidden", "application/json", ApiError)
  367. }
  368. }
  369. end
  370. def delete_operation do
  371. %Operation{
  372. tags: ["User administration"],
  373. summary: "Removes a single or multiple users",
  374. operationId: "AdminAPI.UserController.delete",
  375. security: [%{"oAuth" => ["admin:write:accounts"]}],
  376. parameters: [
  377. Operation.parameter(
  378. :nickname,
  379. :query,
  380. :string,
  381. "User nickname"
  382. )
  383. | admin_api_params()
  384. ],
  385. requestBody:
  386. request_body(
  387. "Parameters",
  388. %Schema{
  389. description: "POST body for deleting multiple users",
  390. type: :object,
  391. properties: %{
  392. nicknames: %Schema{
  393. type: :array,
  394. items: %Schema{type: :string}
  395. }
  396. }
  397. }
  398. ),
  399. responses: %{
  400. 200 =>
  401. Operation.response("Response", "application/json", %Schema{
  402. description: "Array of nicknames",
  403. type: :array,
  404. items: %Schema{type: :string}
  405. }),
  406. 403 => Operation.response("Forbidden", "application/json", ApiError)
  407. }
  408. }
  409. end
  410. defp user do
  411. %Schema{
  412. type: :object,
  413. properties: %{
  414. id: %Schema{type: :string},
  415. email: %Schema{type: :string, format: :email},
  416. avatar: %Schema{type: :string, format: :uri},
  417. nickname: %Schema{type: :string},
  418. display_name: %Schema{type: :string},
  419. is_active: %Schema{type: :boolean},
  420. local: %Schema{type: :boolean},
  421. roles: %Schema{
  422. type: :object,
  423. properties: %{
  424. admin: %Schema{type: :boolean},
  425. moderator: %Schema{type: :boolean}
  426. }
  427. },
  428. tags: %Schema{type: :array, items: %Schema{type: :string}},
  429. is_confirmed: %Schema{type: :boolean},
  430. is_approved: %Schema{type: :boolean},
  431. url: %Schema{type: :string, format: :uri},
  432. registration_reason: %Schema{type: :string, nullable: true},
  433. actor_type: %Schema{type: :string}
  434. }
  435. }
  436. end
  437. end