Commit 4e145ef
fix(personas): H-2/H-3/M-2/M-5 — audit table + admin guards + rate limit
Per #229 review:
H-2: append-only persona_assignment_audit table. New migration 0023
chains from 0022. CREATED / CHANGED / DISABLED rows written in the
same transaction as the upsert/disable so the audit and state never
desync. HEAD_REVISION bumped to 0023_persona_assignment_audit;
test_head_revision_is_current also updated (was stale at 0021
before this change).
H-3: last-admin guard. POST .../disable refuses with HTTP 409 +
code=LAST_ADMIN when the target is persona='admin' and active admin
count <= 1. New store method count_active_admins() does the count.
M-2: PATCH no longer silently re-enables a disabled assignment.
Returns 409 + code=USER_DISABLED pointing the admin at the
yet-to-land POST .../enable endpoint.
M-5: per-admin invite rate limit. POST /admin/personas rejects with
HTTP 429 + code=RATE_LIMIT when the calling admin has issued >= 20
assignments in the trailing hour. New store method
count_invites_by_admin().
Tests added:
* test_persona_changes_create_audit_rows
* test_disabling_last_admin_returns_409_LAST_ADMIN
* test_patch_disabled_user_returns_409_USER_DISABLED
* test_admin_cannot_send_more_than_20_invites_per_hour
Review: #229 (comment)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent bc9a355 commit 4e145ef
5 files changed
Lines changed: 296 additions & 17 deletions
File tree
- server/backend
- alembic/versions
- src/cq_server
- store
- tests
Lines changed: 77 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
183 | 198 | | |
184 | 199 | | |
185 | 200 | | |
| |||
198 | 213 | | |
199 | 214 | | |
200 | 215 | | |
| 216 | + | |
| 217 | + | |
201 | 218 | | |
202 | 219 | | |
203 | 220 | | |
| |||
255 | 272 | | |
256 | 273 | | |
257 | 274 | | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
258 | 290 | | |
259 | 291 | | |
260 | 292 | | |
261 | 293 | | |
262 | 294 | | |
263 | 295 | | |
| 296 | + | |
| 297 | + | |
264 | 298 | | |
265 | 299 | | |
266 | 300 | | |
| |||
273 | 307 | | |
274 | 308 | | |
275 | 309 | | |
276 | | - | |
| 310 | + | |
277 | 311 | | |
278 | 312 | | |
279 | 313 | | |
280 | 314 | | |
281 | | - | |
282 | | - | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
283 | 318 | | |
284 | 319 | | |
285 | 320 | | |
| 321 | + | |
286 | 322 | | |
287 | 323 | | |
288 | 324 | | |
289 | 325 | | |
290 | 326 | | |
291 | 327 | | |
292 | 328 | | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
293 | 342 | | |
294 | | - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
295 | 349 | | |
0 commit comments