Line data Source code
1 4 : (ns schemas.api.admin
2 : "Request / response schemas for the `/api/admin/*` endpoints."
3 : (:require
4 : [schemas.api.account :as api-account-schemas]
5 : [schemas.domain.user :as domain-user-schemas]))
6 :
7 :
8 : ;; ---------------------------------------------------------------------------
9 : ;; Roles catalog
10 : ;; ---------------------------------------------------------------------------
11 :
12 :
13 4 : (def RoleCreateSchema
14 28 : [:map {:swagger/title "RoleCreateSchema"
15 : :swagger/description "Request body to create a role in the catalog"}
16 8 : [:name
17 28 : [:string {:min 1
18 : :max 200}]]
19 20 : [:display-name {:optional true}
20 12 : [:maybe :string]]
21 20 : [:description {:optional true}
22 12 : [:maybe :string]]
23 20 : [:scope [:enum "global"]]])
24 :
25 :
26 4 : (def RoleUpdateSchema
27 20 : [:map {:swagger/title "RoleUpdateSchema"}
28 20 : [:display-name {:optional true}
29 12 : [:maybe :string]]
30 20 : [:description {:optional true}
31 12 : [:maybe :string]]
32 20 : [:scope {:optional true}
33 12 : [:enum "global"]]])
34 :
35 :
36 4 : (def RolePathParamsSchema
37 20 : [:map {:swagger/title "RolePathParamsSchema"}
38 28 : [:role-name {:description "Role name (e.g. `coach`)"
39 : :example "coach"}
40 28 : [:string {:min 1
41 : :max 200}]]])
42 :
43 :
44 4 : (def RoleSchema
45 28 : [:map {:swagger/title "Role"
46 : :swagger/description "Role catalog object"}
47 12 : [:name :string]
48 20 : [:display-name {:optional true}
49 12 : [:maybe :string]]
50 20 : [:description {:optional true}
51 12 : [:maybe :string]]
52 20 : [:scope [:enum "global"]]])
53 :
54 :
55 4 : (def RoleResponseSchema
56 8 : [:or
57 76 : [:map [:status [:= 200]] [:body [:map [:message :string] [:data [:vector RoleSchema]]]]]
58 68 : [:map [:status [:= 201]] [:body [:map [:message :string] [:data RoleSchema]]]]
59 28 : [:map [:status [:= 204]]]
60 56 : [:map [:status [:= 400]] [:body [:map [:message :string]]]]
61 56 : [:map [:status [:= 403]] [:body [:map [:message :string]]]]
62 56 : [:map [:status [:= 404]] [:body [:map [:message :string]]]]])
63 :
64 :
65 : ;; ---------------------------------------------------------------------------
66 : ;; Assignments (Casbin `g` rows)
67 : ;; ---------------------------------------------------------------------------
68 :
69 :
70 4 : (def AssignmentSchema
71 28 : [:map {:swagger/title "Assignment"
72 : :swagger/description "Casbin grouping assignment object"}
73 20 : [:user-uuid [:ref :types/UuidString]]
74 12 : [:role :string]
75 12 : [:domain :string]])
76 :
77 :
78 4 : (def AssignmentMutateSchema
79 28 : [:map {:swagger/title "AssignmentMutateSchema"
80 : :swagger/description "Request body to grant or revoke a role"}
81 20 : [:user-uuid [:ref :types/UuidString]]
82 28 : [:role [:string {:min 1}]]
83 28 : [:domain [:string {:min 1}]]])
84 :
85 :
86 4 : (def AssignmentListResponseSchema
87 8 : [:or
88 76 : [:map [:status [:= 200]] [:body [:map [:message :string] [:data [:vector AssignmentSchema]]]]]])
89 :
90 :
91 4 : (def AssignmentMutateResponseSchema
92 8 : [:or
93 68 : [:map [:status [:= 201]] [:body [:map [:message :string] [:data AssignmentSchema]]]]
94 28 : [:map [:status [:= 204]]]
95 56 : [:map [:status [:= 400]] [:body [:map [:message :string]]]]
96 56 : [:map [:status [:= 403]] [:body [:map [:message :string]]]]])
97 :
98 :
99 : ;; ---------------------------------------------------------------------------
100 : ;; Users
101 : ;; ---------------------------------------------------------------------------
102 :
103 :
104 4 : (def UserListPathParamsSchema
105 20 : [:map {:swagger/title "AdminUserPathParamsSchema"}
106 20 : [:user-uuid {:description "User UUID"}
107 12 : [:ref :types/UuidString]]])
108 :
109 :
110 4 : (def AdminUserSchema
111 28 : [:map {:swagger/title "AdminUser"
112 : :swagger/description "Admin user object"}
113 20 : [:uuid [:ref :types/UuidString]]
114 20 : [:name {:optional true}
115 12 : [:maybe :string]]
116 20 : [:username {:optional true}
117 12 : [:maybe :string]]
118 20 : [:photo-url {:optional true}
119 12 : [:maybe :string]]
120 24 : [:created-datetime {:optional true}
121 : :any]
122 24 : [:updated-datetime {:optional true}
123 : :any]
124 36 : [:roles [:sequential [:enum "root" "admin" "player"]]]
125 20 : [:name-locks {:optional true}
126 12 : [:sequential :string]]])
127 :
128 :
129 4 : (def UserRolesUpdateSchema
130 20 : [:map {:swagger/title "UserRolesUpdateSchema"}
131 36 : [:roles [:sequential [:enum "root" "admin" "player"]]]])
132 :
133 :
134 4 : (def UserNameLocksUpdateSchema
135 28 : [:map {:swagger/title "UserNameLocksUpdateSchema"
136 : :swagger/description "Languages whose name the user can no longer change"}
137 12 : [:languages domain-user-schemas/NameLocksSchema]])
138 :
139 :
140 4 : (def AdminUserUpdateSchema
141 28 : [:map {:swagger/title "AdminUserUpdateSchema"
142 : :swagger/description "Request body to update a user's profile (name, username)"}
143 8 : [:name
144 36 : [:string {:min 1
145 : :max 120
146 : :description "User's display name"}]]
147 20 : [:username {:optional true}
148 8 : [:maybe
149 36 : [:string {:min 4
150 : :max 100
151 : :description "Unique username"}]]]
152 28 : [:name-localized {:optional true
153 : :description "Localized names; \"\" removes one, omitted languages are kept"}
154 4 : api-account-schemas/NameLocalizedRequestSchema]])
155 :
156 :
157 4 : (def AdminUserListResponseSchema
158 8 : [:or
159 76 : [:map [:status [:= 200]] [:body [:map [:message :string] [:data [:vector AdminUserSchema]]]]]])
160 :
161 :
162 4 : (def AdminUserResponseSchema
163 8 : [:or
164 68 : [:map [:status [:= 200]] [:body [:map [:message :string] [:data AdminUserSchema]]]]
165 68 : [:map [:status [:= 400]] [:body [:map [:message :string] [:error :map]]]]
166 56 : [:map [:status [:= 404]] [:body [:map [:message :string]]]]])
167 :
168 :
169 : ;; ---------------------------------------------------------------------------
170 : ;; Policies (Casbin `p` rows)
171 : ;; ---------------------------------------------------------------------------
172 :
173 :
174 4 : (def PolicySchema
175 28 : [:map {:swagger/title "Policy"
176 : :swagger/description "Casbin policy object"}
177 12 : [:role :string]
178 12 : [:domain :string]
179 12 : [:obj-type :string]
180 12 : [:action :string]
181 24 : [:cond {:optional true}
182 : :string]
183 20 : [:effect {:optional true}
184 16 : [:enum "allow" "deny"]]])
185 :
186 :
187 4 : (def PolicyMutateSchema
188 20 : [:map {:swagger/title "PolicyMutateSchema"}
189 28 : [:role [:string {:min 1}]]
190 28 : [:domain [:string {:min 1}]]
191 28 : [:obj-type [:string {:min 1}]]
192 28 : [:action [:string {:min 1}]]
193 24 : [:cond {:optional true}
194 : :string]
195 20 : [:effect {:optional true}
196 16 : [:enum "allow" "deny"]]])
197 :
198 :
199 4 : (def PolicyListResponseSchema
200 84 : [:or [:map [:status [:= 200]] [:body [:map [:message :string] [:data [:vector PolicySchema]]]]]])
201 :
202 :
203 4 : (def PolicyMutateResponseSchema
204 8 : [:or
205 68 : [:map [:status [:= 201]] [:body [:map [:message :string] [:data PolicySchema]]]]
206 28 : [:map [:status [:= 204]]]
207 56 : [:map [:status [:= 400]] [:body [:map [:message :string]]]]
208 56 : [:map [:status [:= 403]] [:body [:map [:message :string]]]]])
209 :
210 :
211 4 : (def PolicyDeleteResponseSchema
212 8 : [:or
213 28 : [:map [:status [:= 204]]]
214 56 : [:map [:status [:= 400]] [:body [:map [:message :string]]]]
215 56 : [:map [:status [:= 403]] [:body [:map [:message :string]]]]])
216 :
217 :
218 : ;; ---------------------------------------------------------------------------
219 : ;; Events / Templates (read-only "see everything" listings)
220 : ;; ---------------------------------------------------------------------------
221 :
222 :
223 4 : (def AdminEventListResponseSchema
224 8 : [:or
225 8 : [:map
226 20 : [:status [:= 200]]
227 56 : [:body [:map [:message :string] [:data [:vector [:ref :domain/EventRecord]]]]]]])
228 :
229 :
230 4 : (def AdminTemplateListResponseSchema
231 8 : [:or
232 8 : [:map
233 20 : [:status [:= 200]]
234 56 : [:body [:map [:message :string] [:data [:vector [:ref :domain/TemplateRecord]]]]]]])
235 :
236 :
237 : ;; ---------------------------------------------------------------------------
238 : ;; Telegram channel publication
239 : ;; ---------------------------------------------------------------------------
240 :
241 :
242 4 : (def AdminTelegramPostSchema
243 28 : [:map {:swagger/title "AdminTelegramPostSchema"
244 : :swagger/description "One reviewed Telegram channel post"}
245 8 : [:text
246 28 : [:string {:min 1
247 : :max 32768}]]
248 20 : [:image-url {:optional true}
249 28 : [:maybe [:string {:max 2048}]]]])
250 :
251 :
252 4 : (def AdminTelegramPublicationSchema
253 28 : [:map {:swagger/title "AdminTelegramPublicationSchema"
254 : :swagger/description "A reviewed series of posts for a Telegram channel"}
255 8 : [:chat-id
256 28 : [:string {:min 1
257 : :max 128}]]
258 8 : [:posts
259 28 : [:vector {:min 1
260 : :max 20}
261 4 : AdminTelegramPostSchema]]
262 24 : [:disable-notification {:optional true}
263 : :boolean]
264 20 : [:publication-id {:optional true}
265 12 : [:ref :types/UuidString]]
266 20 : [:candidate-id {:optional true}
267 12 : [:ref :types/UuidString]]])
268 :
269 :
270 4 : (def AdminTelegramPreparedPostSchema
271 8 : [:map
272 12 : [:html :string]
273 12 : [:markdown :string]
274 12 : [:length :int]
275 20 : [:image-url [:maybe :string]]
276 20 : [:inline-image-urls [:vector :string]]
277 12 : [:rich-message :map]])
278 :
279 :
280 4 : (def AdminTelegramCandidatePreviewPostSchema
281 64 : [:map [:html :string] [:markdown :string] [:length :int] [:image-url [:maybe :string]]])
282 :
283 :
284 4 : (def AdminTelegramCandidateSchema
285 8 : [:map
286 20 : [:candidate-id [:ref :types/UuidString]]
287 12 : [:source-id :string]
288 12 : [:title :string]
289 12 : [:source :map]
290 28 : [:status [:enum "awaiting_review" "published" "rejected"]]
291 28 : [:publication-id [:maybe [:ref :types/UuidString]]]
292 12 : [:disable-notification :boolean]
293 20 : [:posts [:vector AdminTelegramPostSchema]]
294 20 : [:preview-posts [:vector AdminTelegramCandidatePreviewPostSchema]]])
295 :
296 :
297 4 : (def AdminTelegramCandidatesResponseSchema
298 8 : [:map
299 20 : [:status [:= 200]]
300 48 : [:body [:map [:message :string] [:data [:vector AdminTelegramCandidateSchema]]]]])
301 :
302 :
303 4 : (def AdminTelegramCandidatePathParamsSchema
304 20 : [:map {:swagger/title "AdminTelegramCandidatePathParamsSchema"}
305 20 : [:candidate-uuid [:ref :types/UuidString]]])
306 :
307 :
308 4 : (def AdminTelegramCandidateArchiveResponseSchema
309 8 : [:or
310 8 : [:map
311 20 : [:status [:= 200]]
312 8 : [:body
313 8 : [:map
314 12 : [:message :string]
315 56 : [:data [:map [:candidate-id [:ref :types/UuidString]] [:status [:= "rejected"]]]]]]]
316 56 : [:map [:status [:= 400]] [:body [:map [:message :string]]]]])
317 :
318 :
319 4 : (def AdminTelegramPublishRequestSchema
320 28 : [:map {:swagger/title "AdminTelegramPublishRequestSchema"
321 : :swagger/description "Publishes one exact saved preview revision once"}
322 20 : [:revision-id [:ref :types/UuidString]]
323 20 : [:idempotency-key [:ref :types/UuidString]]])
324 :
325 :
326 4 : (def AdminTelegramPreviewResponseSchema
327 8 : [:or
328 8 : [:map
329 20 : [:status [:= 200]]
330 8 : [:body
331 8 : [:map
332 12 : [:message :string]
333 8 : [:data
334 8 : [:map
335 12 : [:chat-id :string]
336 12 : [:disable-notification :boolean]
337 20 : [:publication-id [:ref :types/UuidString]]
338 20 : [:revision-id [:ref :types/UuidString]]
339 12 : [:revision :int]
340 12 : [:content-hash :string]
341 20 : [:candidate-id {:optional true}
342 20 : [:maybe [:ref :types/UuidString]]]
343 20 : [:posts [:vector AdminTelegramPreparedPostSchema]]]]]]]
344 56 : [:map [:status [:= 400]] [:body [:map [:message :string]]]]])
345 :
346 :
347 4 : (def AdminTelegramPublishDataSchema
348 8 : [:map
349 20 : [:publication-id [:ref :types/UuidString]]
350 20 : [:revision-id [:ref :types/UuidString]]
351 20 : [:delivery-id [:ref :types/UuidString]]
352 12 : [:delivery-status :string]
353 12 : [:deduplicated :boolean]
354 12 : [:chat-id :string]
355 12 : [:published-post-count :int]
356 20 : [:sent-message-ids [:vector :int]]])
357 :
358 :
359 4 : (def AdminTelegramPublishResponseSchema
360 8 : [:or
361 8 : [:map
362 20 : [:status [:= 200]]
363 40 : [:body [:map [:message :string] [:data AdminTelegramPublishDataSchema]]]]
364 56 : [:map [:status [:= 400]] [:body [:map [:message :string]]]]
365 8 : [:map
366 20 : [:status [:= 409]]
367 52 : [:body [:map [:message :string] [:data AdminTelegramPublishDataSchema] [:error :map]]]]
368 8 : [:map
369 20 : [:status [:= 502]]
370 52 : [:body [:map [:message :string] [:data AdminTelegramPublishDataSchema] [:error :map]]]]])
|