logo

pleroma

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

report_operation.ex (6957B)


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