logo

pleroma

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

report_operation.ex (7418B)


  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.ReportOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. alias Pleroma.Web.ApiSpec.Schemas.Account
  8. alias Pleroma.Web.ApiSpec.Schemas.ApiError
  9. alias Pleroma.Web.ApiSpec.Schemas.FlakeID
  10. alias Pleroma.Web.ApiSpec.Schemas.Status
  11. import Pleroma.Web.ApiSpec.Helpers
  12. def open_api_operation(action) do
  13. operation = String.to_existing_atom("#{action}_operation")
  14. apply(__MODULE__, operation, [])
  15. end
  16. def index_operation do
  17. %Operation{
  18. tags: ["Report management"],
  19. summary: "Retrieve a list of reports",
  20. operationId: "AdminAPI.ReportController.index",
  21. security: [%{"oAuth" => ["admin:read:reports"]}],
  22. parameters: [
  23. Operation.parameter(
  24. :state,
  25. :query,
  26. report_state(),
  27. "Filter by report state"
  28. ),
  29. Operation.parameter(
  30. :rule_id,
  31. :query,
  32. %Schema{type: :string},
  33. "Filter by selected rule id"
  34. ),
  35. Operation.parameter(
  36. :limit,
  37. :query,
  38. %Schema{type: :integer},
  39. "The number of records to retrieve"
  40. ),
  41. Operation.parameter(
  42. :page,
  43. :query,
  44. %Schema{type: :integer, default: 1},
  45. "Page number"
  46. ),
  47. Operation.parameter(
  48. :page_size,
  49. :query,
  50. %Schema{type: :integer, default: 50},
  51. "Number number of log entries per page"
  52. )
  53. | admin_api_params()
  54. ],
  55. responses: %{
  56. 200 =>
  57. Operation.response("Response", "application/json", %Schema{
  58. type: :object,
  59. properties: %{
  60. total: %Schema{type: :integer},
  61. reports: %Schema{
  62. type: :array,
  63. items: report()
  64. }
  65. }
  66. }),
  67. 403 => Operation.response("Forbidden", "application/json", ApiError)
  68. }
  69. }
  70. end
  71. def show_operation do
  72. %Operation{
  73. tags: ["Report management"],
  74. summary: "Retrieve a report",
  75. operationId: "AdminAPI.ReportController.show",
  76. parameters: [id_param() | admin_api_params()],
  77. security: [%{"oAuth" => ["admin:read:reports"]}],
  78. responses: %{
  79. 200 => Operation.response("Report", "application/json", report()),
  80. 404 => Operation.response("Not Found", "application/json", ApiError)
  81. }
  82. }
  83. end
  84. def update_operation do
  85. %Operation{
  86. tags: ["Report management"],
  87. summary: "Change state of specified reports",
  88. operationId: "AdminAPI.ReportController.update",
  89. security: [%{"oAuth" => ["admin:write:reports"]}],
  90. parameters: admin_api_params(),
  91. requestBody: request_body("Parameters", update_request(), required: true),
  92. responses: %{
  93. 204 => no_content_response(),
  94. 400 => Operation.response("Bad Request", "application/json", update_400_response()),
  95. 403 => Operation.response("Forbidden", "application/json", ApiError)
  96. }
  97. }
  98. end
  99. def notes_create_operation do
  100. %Operation{
  101. tags: ["Report management"],
  102. summary: "Add a note to the report",
  103. operationId: "AdminAPI.ReportController.notes_create",
  104. parameters: [id_param() | admin_api_params()],
  105. requestBody:
  106. request_body("Parameters", %Schema{
  107. type: :object,
  108. properties: %{
  109. content: %Schema{type: :string, description: "The message"}
  110. }
  111. }),
  112. security: [%{"oAuth" => ["admin:write:reports"]}],
  113. responses: %{
  114. 204 => no_content_response(),
  115. 404 => Operation.response("Not Found", "application/json", ApiError)
  116. }
  117. }
  118. end
  119. def notes_delete_operation do
  120. %Operation{
  121. tags: ["Report management"],
  122. summary: "Delete note attached to the report",
  123. operationId: "AdminAPI.ReportController.notes_delete",
  124. parameters: [
  125. Operation.parameter(:report_id, :path, :string, "Report ID"),
  126. Operation.parameter(:id, :path, :string, "Note ID")
  127. | admin_api_params()
  128. ],
  129. security: [%{"oAuth" => ["admin:write:reports"]}],
  130. responses: %{
  131. 204 => no_content_response(),
  132. 404 => Operation.response("Not Found", "application/json", ApiError)
  133. }
  134. }
  135. end
  136. def report_state do
  137. %Schema{type: :string, enum: ["open", "closed", "resolved"]}
  138. end
  139. def id_param do
  140. Operation.parameter(:id, :path, FlakeID.schema(), "Report ID",
  141. example: "9umDrYheeY451cQnEe",
  142. required: true
  143. )
  144. end
  145. defp report do
  146. %Schema{
  147. type: :object,
  148. properties: %{
  149. id: FlakeID,
  150. state: report_state(),
  151. account: account_admin(),
  152. actor: account_admin(),
  153. content: %Schema{type: :string},
  154. created_at: %Schema{type: :string, format: :"date-time"},
  155. statuses: %Schema{type: :array, items: Status},
  156. notes: %Schema{
  157. type: :array,
  158. items: %Schema{
  159. type: :object,
  160. properties: %{
  161. id: %Schema{type: :integer},
  162. user_id: FlakeID,
  163. content: %Schema{type: :string},
  164. inserted_at: %Schema{type: :string, format: :"date-time"}
  165. }
  166. }
  167. },
  168. rules: %Schema{
  169. type: :array,
  170. items: %Schema{
  171. type: :object,
  172. properties: %{
  173. id: %Schema{type: :string},
  174. text: %Schema{type: :string},
  175. hint: %Schema{type: :string, nullable: true}
  176. }
  177. }
  178. }
  179. }
  180. }
  181. end
  182. defp account_admin do
  183. %Schema{
  184. title: "Account",
  185. description: "Account view for admins",
  186. type: :object,
  187. properties:
  188. Map.merge(Account.schema().properties, %{
  189. nickname: %Schema{type: :string},
  190. is_active: %Schema{type: :boolean},
  191. local: %Schema{type: :boolean},
  192. roles: %Schema{
  193. type: :object,
  194. properties: %{
  195. admin: %Schema{type: :boolean},
  196. moderator: %Schema{type: :boolean}
  197. }
  198. },
  199. is_confirmed: %Schema{type: :boolean}
  200. })
  201. }
  202. end
  203. defp update_request do
  204. %Schema{
  205. type: :object,
  206. required: [:reports],
  207. properties: %{
  208. reports: %Schema{
  209. type: :array,
  210. items: %Schema{
  211. type: :object,
  212. properties: %{
  213. id: %Schema{allOf: [FlakeID], description: "Required, report ID"},
  214. state: %Schema{
  215. type: :string,
  216. description:
  217. "Required, the new state. Valid values are `open`, `closed` and `resolved`"
  218. }
  219. }
  220. },
  221. example: %{
  222. "reports" => [
  223. %{"id" => "123", "state" => "closed"},
  224. %{"id" => "1337", "state" => "resolved"}
  225. ]
  226. }
  227. }
  228. }
  229. }
  230. end
  231. defp update_400_response do
  232. %Schema{
  233. type: :array,
  234. items: %Schema{
  235. type: :object,
  236. properties: %{
  237. id: %Schema{allOf: [FlakeID], description: "Report ID"},
  238. error: %Schema{type: :string, description: "Error message"}
  239. }
  240. }
  241. }
  242. end
  243. end