Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

390 行
12KB

  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. 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 deleting 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 toggle_activation_operation do
  231. %Operation{
  232. tags: ["User administration"],
  233. summary: "Toggle user activation",
  234. operationId: "AdminAPI.UserController.toggle_activation",
  235. security: [%{"oAuth" => ["admin:write:accounts"]}],
  236. parameters: [
  237. Operation.parameter(:nickname, :path, :string, "User nickname")
  238. | admin_api_params()
  239. ],
  240. responses: %{
  241. 200 => Operation.response("Response", "application/json", user()),
  242. 403 => Operation.response("Forbidden", "application/json", ApiError)
  243. }
  244. }
  245. end
  246. def activate_operation do
  247. %Operation{
  248. tags: ["User administration"],
  249. summary: "Activate multiple users",
  250. operationId: "AdminAPI.UserController.activate",
  251. security: [%{"oAuth" => ["admin:write:accounts"]}],
  252. parameters: admin_api_params(),
  253. requestBody:
  254. request_body(
  255. "Parameters",
  256. %Schema{
  257. description: "POST body for deleting multiple users",
  258. type: :object,
  259. properties: %{
  260. nicknames: %Schema{
  261. type: :array,
  262. items: %Schema{type: :string}
  263. }
  264. }
  265. }
  266. ),
  267. responses: %{
  268. 200 =>
  269. Operation.response("Response", "application/json", %Schema{
  270. type: :object,
  271. properties: %{user: %Schema{type: :array, items: user()}}
  272. }),
  273. 403 => Operation.response("Forbidden", "application/json", ApiError)
  274. }
  275. }
  276. end
  277. def deactivate_operation do
  278. %Operation{
  279. tags: ["User administration"],
  280. summary: "Deactivates multiple users",
  281. operationId: "AdminAPI.UserController.deactivate",
  282. security: [%{"oAuth" => ["admin:write:accounts"]}],
  283. parameters: admin_api_params(),
  284. requestBody:
  285. request_body(
  286. "Parameters",
  287. %Schema{
  288. description: "POST body for deleting multiple users",
  289. type: :object,
  290. properties: %{
  291. nicknames: %Schema{
  292. type: :array,
  293. items: %Schema{type: :string}
  294. }
  295. }
  296. }
  297. ),
  298. responses: %{
  299. 200 =>
  300. Operation.response("Response", "application/json", %Schema{
  301. type: :object,
  302. properties: %{user: %Schema{type: :array, items: user()}}
  303. }),
  304. 403 => Operation.response("Forbidden", "application/json", ApiError)
  305. }
  306. }
  307. end
  308. def delete_operation do
  309. %Operation{
  310. tags: ["User administration"],
  311. summary: "Removes a single or multiple users",
  312. operationId: "AdminAPI.UserController.delete",
  313. security: [%{"oAuth" => ["admin:write:accounts"]}],
  314. parameters: [
  315. Operation.parameter(
  316. :nickname,
  317. :query,
  318. :string,
  319. "User nickname"
  320. )
  321. | admin_api_params()
  322. ],
  323. requestBody:
  324. request_body(
  325. "Parameters",
  326. %Schema{
  327. description: "POST body for deleting multiple users",
  328. type: :object,
  329. properties: %{
  330. nicknames: %Schema{
  331. type: :array,
  332. items: %Schema{type: :string}
  333. }
  334. }
  335. }
  336. ),
  337. responses: %{
  338. 200 =>
  339. Operation.response("Response", "application/json", %Schema{
  340. description: "Array of nicknames",
  341. type: :array,
  342. items: %Schema{type: :string}
  343. }),
  344. 403 => Operation.response("Forbidden", "application/json", ApiError)
  345. }
  346. }
  347. end
  348. defp user do
  349. %Schema{
  350. type: :object,
  351. properties: %{
  352. id: %Schema{type: :string},
  353. email: %Schema{type: :string, format: :email},
  354. avatar: %Schema{type: :string, format: :uri},
  355. nickname: %Schema{type: :string},
  356. display_name: %Schema{type: :string},
  357. is_active: %Schema{type: :boolean},
  358. local: %Schema{type: :boolean},
  359. roles: %Schema{
  360. type: :object,
  361. properties: %{
  362. admin: %Schema{type: :boolean},
  363. moderator: %Schema{type: :boolean}
  364. }
  365. },
  366. tags: %Schema{type: :array, items: %Schema{type: :string}},
  367. is_confirmed: %Schema{type: :boolean},
  368. is_approved: %Schema{type: :boolean},
  369. url: %Schema{type: :string, format: :uri},
  370. registration_reason: %Schema{type: :string, nullable: true},
  371. actor_type: %Schema{type: :string}
  372. }
  373. }
  374. end
  375. end