Merge branch 'feat/openapi-spec-export' into 'develop'
[akkoma] / lib / pleroma / web / api_spec / operations / admin / status_operation.ex
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
5 defmodule Pleroma.Web.ApiSpec.Admin.StatusOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.Account
9 alias Pleroma.Web.ApiSpec.Schemas.ApiError
10 alias Pleroma.Web.ApiSpec.Schemas.FlakeID
11 alias Pleroma.Web.ApiSpec.Schemas.Status
12 alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
13
14 import Pleroma.Web.ApiSpec.Helpers
15 import Pleroma.Web.ApiSpec.StatusOperation, only: [id_param: 0]
16
17 def open_api_operation(action) do
18 operation = String.to_existing_atom("#{action}_operation")
19 apply(__MODULE__, operation, [])
20 end
21
22 def index_operation do
23 %Operation{
24 tags: ["Status administration"],
25 operationId: "AdminAPI.StatusController.index",
26 summary: "Get all statuses",
27 security: [%{"oAuth" => ["read:statuses"]}],
28 parameters: [
29 Operation.parameter(
30 :godmode,
31 :query,
32 %Schema{type: :boolean, default: false},
33 "Allows to see private statuses"
34 ),
35 Operation.parameter(
36 :local_only,
37 :query,
38 %Schema{type: :boolean, default: false},
39 "Excludes remote statuses"
40 ),
41 Operation.parameter(
42 :with_reblogs,
43 :query,
44 %Schema{type: :boolean, default: false},
45 "Allows to see reblogs"
46 ),
47 Operation.parameter(
48 :page,
49 :query,
50 %Schema{type: :integer, default: 1},
51 "Page"
52 ),
53 Operation.parameter(
54 :page_size,
55 :query,
56 %Schema{type: :integer, default: 50},
57 "Number of statuses to return"
58 )
59 | admin_api_params()
60 ],
61 responses: %{
62 200 =>
63 Operation.response("Array of statuses", "application/json", %Schema{
64 type: :array,
65 items: status()
66 })
67 }
68 }
69 end
70
71 def show_operation do
72 %Operation{
73 tags: ["Status adminitration)"],
74 summary: "Get status",
75 operationId: "AdminAPI.StatusController.show",
76 parameters: [id_param() | admin_api_params()],
77 security: [%{"oAuth" => ["read:statuses"]}],
78 responses: %{
79 200 => Operation.response("Status", "application/json", status()),
80 404 => Operation.response("Not Found", "application/json", ApiError)
81 }
82 }
83 end
84
85 def update_operation do
86 %Operation{
87 tags: ["Status adminitration)"],
88 summary: "Change the scope of a status",
89 operationId: "AdminAPI.StatusController.update",
90 parameters: [id_param() | admin_api_params()],
91 security: [%{"oAuth" => ["write:statuses"]}],
92 requestBody: request_body("Parameters", update_request(), required: true),
93 responses: %{
94 200 => Operation.response("Status", "application/json", Status),
95 400 => Operation.response("Error", "application/json", ApiError)
96 }
97 }
98 end
99
100 def delete_operation do
101 %Operation{
102 tags: ["Status adminitration)"],
103 summary: "Delete status",
104 operationId: "AdminAPI.StatusController.delete",
105 parameters: [id_param() | admin_api_params()],
106 security: [%{"oAuth" => ["write:statuses"]}],
107 responses: %{
108 200 => empty_object_response(),
109 404 => Operation.response("Not Found", "application/json", ApiError)
110 }
111 }
112 end
113
114 defp status do
115 %Schema{
116 anyOf: [
117 Status,
118 %Schema{
119 type: :object,
120 properties: %{
121 account: %Schema{allOf: [Account, admin_account()]}
122 }
123 }
124 ]
125 }
126 end
127
128 def admin_account do
129 %Schema{
130 type: :object,
131 properties: %{
132 id: FlakeID,
133 avatar: %Schema{type: :string},
134 nickname: %Schema{type: :string},
135 display_name: %Schema{type: :string},
136 is_active: %Schema{type: :boolean},
137 local: %Schema{type: :boolean},
138 roles: %Schema{
139 type: :object,
140 properties: %{
141 admin: %Schema{type: :boolean},
142 moderator: %Schema{type: :boolean}
143 }
144 },
145 tags: %Schema{type: :string},
146 is_confirmed: %Schema{type: :string}
147 }
148 }
149 end
150
151 defp update_request do
152 %Schema{
153 type: :object,
154 properties: %{
155 sensitive: %Schema{
156 type: :boolean,
157 description: "Mark status and attached media as sensitive?"
158 },
159 visibility: VisibilityScope
160 },
161 example: %{
162 "visibility" => "private",
163 "sensitive" => "false"
164 }
165 }
166 end
167 end