hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiBaf331ecAhmet Kaan Gümüş2 months ago451 commits
| 1 | use crate; |
| 2 | use Json; |
| 3 | use ; |
| 4 | use StatusCode; |
| 5 | use Response; |
| 6 | use ; |
| 7 | use json; |
| 8 | use ; |
| 9 | use OpenApiRouter; |
| 10 | use routes; |
| 11 | |
| 12 | use crate |
| 13 | |
| 14 | ; |
| 15 | use crateDatabase; |
| 16 | use crate; |
| 17 | use crateClassGroupId; |
| 18 | |
| 19 | use crate; |
| 20 | use crate; |
| 21 | use crateRole; |
| 22 | use crate; |
| 23 | use crate; |
| 24 | use crateensure_can_observe; |
| 25 | use crateAppState; |
| 26 | |
| 27 | use visible_courses; |
| 28 | use AssignableRole; |
| 29 | use Role as RoleSchema; |
| 30 | use |
| 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 | /// Partial personal-info update. Per field: omitted (or `null`) keeps the |
| 74 | /// current value, an empty string clears it, anything else is validated and set. |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | /// Partial UI-preference update. Same field semantics as [`UpdateProfile`]: |
| 99 | /// omitted (or `null`) keeps the current value, an empty string clears it back |
| 100 | /// to "never chose" (the client then follows the device preference), anything |
| 101 | /// else is validated and set. |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | /// Resolve one patched field into what the save should write: absent (or |
| 117 | /// `null`) is `None` — the column is not written at all, so a concurrent PATCH |
| 118 | /// of it survives; `""` is `Some(None)`, an explicit clear; anything else must |
| 119 | /// parse into the domain newtype, exactly as a create would. |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | /// Validate and persist exactly the info fields `req` carried — nothing is |
| 132 | /// merged from `user`'s snapshot, so a concurrent PATCH of another field is not |
| 133 | /// reverted. Shared by the self-service and admin profile endpoints — they |
| 134 | /// differ only in whose row they load and who may call them. |
| 135 | async |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | /// Validate and persist exactly the preference fields `req` carried — same |
| 165 | /// no-merge reasoning as [`apply_profile`]. Shared by the |
| 166 | /// self-service and admin preference endpoints — they differ only in whose row |
| 167 | /// they load and who may call them. |
| 168 | async |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | /// Find users by username or name — backs the pickers (enroll, grade, mark |
| 199 | /// attendance) and, for a student or parent, the one way to find the staff |
| 200 | /// member they are allowed to message. Any authenticated user may ask; a |
| 201 | /// caller below teacher only ever sees the roles they may message (teacher, |
| 202 | /// manager, admin), in the items *and* in `total`. `role` narrows to one role |
| 203 | /// (e.g. `role=student` for an enroll picker) — a student or parent naming a |
| 204 | /// role they may not message is refused; a blank `q` with a `role` lists |
| 205 | /// everyone in that role. Paged via `?limit=&offset=` like the other lists |
| 206 | /// (omit `limit` for every match); returns a `{items, total, limit, offset}` |
| 207 | /// envelope carrying only id/username/display name — no contact details. |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | async |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | /// List every user with their role, newest first. Admin only. Paged: pass |
| 255 | /// `?limit=&offset=` to take a window (omit `limit` for the whole list); the |
| 256 | /// response is a `{items, total, limit, offset}` envelope where `total` counts |
| 257 | /// every user. |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | async |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | /// Update the caller's own personal info: name, surname, email, phone, birth |
| 283 | /// date, plus the public-profile pair `display_name` and `bio` (both readable |
| 284 | /// school-wide at `GET /users/{id}/profile`, unlike the contact fields). Any |
| 285 | /// authenticated role. Omitted fields stay as they are; an empty string clears |
| 286 | /// a field. |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | async |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | /// Update the caller's own UI preferences: `theme` (`light`/`dark`), |
| 309 | /// `language` (`tr`/`en`), and `palette_color` (accent color as `#rrggbb`). |
| 310 | /// Any authenticated role. Omitted fields stay as they |
| 311 | /// are; an empty string clears one back to "never chose" (the client then |
| 312 | /// follows the device preference). Read them back on any user response, e.g. |
| 313 | /// `GET /auth/me`. |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | async |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | /// Fetch one user with their role and personal info. Admin only. |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | async |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | /// Update any user's personal info. Admin only — the school-office path for |
| 361 | /// maintaining records on behalf of students and staff. Same field semantics |
| 362 | /// as `PATCH /users/me`. |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | async |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | /// Update any user's UI preferences. Admin only — everyone else manages their |
| 392 | /// own through `PATCH /users/me/preferences`, which this mirrors field for |
| 393 | /// field. |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | async |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | /// Set a user's role. Admin only. An admin cannot change their own role, and |
| 423 | /// the school's **last** admin cannot be demoted by anyone (`409`) — together |
| 424 | /// those keep role management from locking everyone out, including when two |
| 425 | /// admins demote each other at the same instant (the floor is a predicate on |
| 426 | /// the role write itself, so the racing demotions serialize on row locks). |
| 427 | /// A school that has already lost its admins is recovered by hand against the |
| 428 | /// database, since the seed never promotes. |
| 429 | /// Setting any non-`student` role also drops the user's course enrollments — |
| 430 | /// only students enroll, so a promoted user leaves every roster. Demoting below |
| 431 | /// `teacher` drops their course teaching assignments for the mirror reason, and |
| 432 | /// withdraws their published appointment slots, cancelling the live bookings on |
| 433 | /// them: nothing could reach either afterwards — a slot is listed only on its |
| 434 | /// own teacher's calendar and deleted only by a teacher+, and a booking on one |
| 435 | /// is decided only by a teacher+ and cancelled only by its requester, who is |
| 436 | /// refused once the window opens. The requester keeps the booking as |
| 437 | /// `cancelled`, naming the ex-teacher and the reason. |
| 438 | /// Demoting to `parent` additionally gives back the seats they hold on |
| 439 | /// still-open event signup lists: a parent can no longer free them, and nobody |
| 440 | /// else may. Seats on lists that have already closed stay as they are — that |
| 441 | /// roster is history. It also takes the account off every whiteboard roster and |
| 442 | /// **closes every board it created** — permanently read-only, nothing deleted. |
| 443 | /// A demoted creator is a `404` on their own board, the four commands that could |
| 444 | /// end it are the creator's alone, and no route lists a board the caller is not |
| 445 | /// on, so the room would otherwise be commandable by nobody while its |
| 446 | /// participants kept drawing on it. Closed, they keep reading the board, its |
| 447 | /// history and its epochs; only writes are refused. |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | |
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | async |
| 466 | |
| 467 | |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | |
| 484 | |
| 485 | |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 | |
| 494 | |
| 495 | |
| 496 | |
| 497 | |
| 498 | |
| 499 | |
| 500 | |
| 501 | |
| 502 | |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | |
| 511 | |
| 512 | |
| 513 | |
| 514 | |
| 515 | |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | |
| 521 | |
| 522 | |
| 523 | |
| 524 | |
| 525 | |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | /// One page of a parent's observed students, sorted by username. Shared by the |
| 531 | /// admin listing and the parent's own `/me/students` — they differ only in |
| 532 | /// whose links they read and who may call them. |
| 533 | async |
| 534 | |
| 535 | |
| 536 | |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | |
| 549 | |
| 550 | |
| 551 | |
| 552 | |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | |
| 558 | |
| 559 | |
| 560 | |
| 561 | |
| 562 | /// Tie a student to a parent account. Admin only — family ties are school-office |
| 563 | /// records, like roles. `{id}` must hold the `parent` role and `user_id` the |
| 564 | /// `student` role; a parent may observe any number of students. Idempotent: |
| 565 | /// linking the same pair again keeps the one tie (the `linked_by` stamp moves |
| 566 | /// to the latest linker, like re-enrolling). The tie grants the |
| 567 | /// parent read access to the student's marks, attendance, and pomodoro reports |
| 568 | /// — nothing else, and never any write. |
| 569 | |
| 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | |
| 585 | async |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | |
| 597 | |
| 598 | |
| 599 | |
| 600 | |
| 601 | |
| 602 | |
| 603 | |
| 604 | |
| 605 | |
| 606 | /// List the students tied to a parent account, sorted by username. Admin only |
| 607 | /// — parents read their own list at `GET /users/me/students`. Paged via |
| 608 | /// `?limit=&offset=` like the other lists. |
| 609 | |
| 610 | |
| 611 | |
| 612 | |
| 613 | |
| 614 | |
| 615 | |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | async |
| 624 | |
| 625 | |
| 626 | |
| 627 | |
| 628 | |
| 629 | |
| 630 | |
| 631 | |
| 632 | |
| 633 | |
| 634 | |
| 635 | |
| 636 | /// Untie a student from a parent account. Admin only. The student's data is |
| 637 | /// untouched — only the parent's read grant goes away. |
| 638 | |
| 639 | |
| 640 | |
| 641 | |
| 642 | |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | async |
| 655 | |
| 656 | |
| 657 | : , |
| 658 | ) |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | |
| 666 | |
| 667 | |
| 668 | |
| 669 | |
| 670 | |
| 671 | |
| 672 | /// The students the calling parent observes, sorted by username. Requires the |
| 673 | /// `parent` role. Each entry's reports live at `GET /marks/{user}`, |
| 674 | /// `GET /attendance/{user}`, and `GET /pomodoro/{user}`. Paged via |
| 675 | /// `?limit=&offset=`. |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | |
| 683 | |
| 684 | |
| 685 | |
| 686 | |
| 687 | |
| 688 | |
| 689 | async |
| 690 | |
| 691 | |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | // ---- the public profile ----------------------------------------------------- |
| 701 | // The school-wide read half of a user row: who they are, what they belong to, |
| 702 | // and the counters that motivate. Deliberately *not* `UserResponse` — that one |
| 703 | // carries email, phone, and birth date, which keep exactly the gate they have |
| 704 | // today (self, teacher+, admin). Nothing here widens where they are reachable. |
| 705 | |
| 706 | /// A user's public profile. Contact details are not part of it, at any role. |
| 707 | |
| 708 | |
| 709 | |
| 710 | |
| 711 | |
| 712 | |
| 713 | |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | |
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | |
| 729 | |
| 730 | |
| 731 | |
| 732 | |
| 733 | |
| 734 | |
| 735 | |
| 736 | |
| 737 | |
| 738 | /// One earned badge. Permanent: once it appears here it never leaves, even if |
| 739 | /// the counter behind it falls back below the threshold that earned it. |
| 740 | |
| 741 | |
| 742 | |
| 743 | |
| 744 | |
| 745 | |
| 746 | |
| 747 | |
| 748 | |
| 749 | |
| 750 | |
| 751 | /// What a stored avatar is, without its bytes. |
| 752 | |
| 753 | |
| 754 | |
| 755 | |
| 756 | |
| 757 | |
| 758 | |
| 759 | |
| 760 | |
| 761 | /// A class section as a profile shows it: the label, and nothing about who runs |
| 762 | /// it. The office-side view (creator, homeroom teacher) stays behind |
| 763 | /// `GET /classes/{id}`, which is teacher+. |
| 764 | |
| 765 | |
| 766 | |
| 767 | |
| 768 | |
| 769 | |
| 770 | |
| 771 | |
| 772 | |
| 773 | |
| 774 | /// A course as a profile shows it — a label, nothing more. |
| 775 | |
| 776 | |
| 777 | |
| 778 | |
| 779 | |
| 780 | |
| 781 | |
| 782 | |
| 783 | |
| 784 | |
| 785 | |
| 786 | /// The motivational counters. Derived, never settable, and never `null`: an |
| 787 | /// account with no rows behind a counter reads a true `0`. |
| 788 | /// |
| 789 | /// Two kinds live here. The first four are **computed at read time** from the |
| 790 | /// rows that exist right now, so deleting the rows moves them down. Every |
| 791 | /// `*_total` one is a **stored lifetime counter**, incremented as the work |
| 792 | /// happens and never recomputed — they can therefore outlive the rows behind |
| 793 | /// them (an exam deleted by its teacher still counts as sat), which is exactly |
| 794 | /// why a badge earned off them stays earned. Each is named for a `stat` of the |
| 795 | /// badge catalog at `GET /limits`, plus `_total`, and that spelling is the join |
| 796 | /// a client makes between the two surfaces — so the suffix is on the key even |
| 797 | /// where the counter is not a running total (`study_streak_total` is a longest, |
| 798 | /// not a sum). |
| 799 | /// |
| 800 | /// Some are staff counters and some student ones; a role that never does the |
| 801 | /// work simply reads zero, which is why no key is conditional. |
| 802 | /// |
| 803 | /// Every number here is the **owner's** true total for every reader, never |
| 804 | /// narrowed per viewer — deliberately so even where the rows behind it sit |
| 805 | /// behind a gate this reader would fail (`GET /pomodoro/{id}`, |
| 806 | /// `GET /marks/user/{id}`, `GET /attendance/user/{id}`). A magnitude names no |
| 807 | /// course, class, lesson or exam, and a per-reader counter would make one |
| 808 | /// profile read differently to different people. |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | |
| 815 | |
| 816 | |
| 817 | |
| 818 | |
| 819 | |
| 820 | |
| 821 | |
| 822 | |
| 823 | |
| 824 | |
| 825 | |
| 826 | |
| 827 | |
| 828 | |
| 829 | |
| 830 | |
| 831 | |
| 832 | |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | |
| 838 | |
| 839 | |
| 840 | |
| 841 | |
| 842 | |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | |
| 849 | |
| 850 | |
| 851 | |
| 852 | |
| 853 | |
| 854 | |
| 855 | |
| 856 | |
| 857 | |
| 858 | |
| 859 | /// Build one profile as `viewer` may see it. The course block is chosen off the |
| 860 | /// owner's **live** role, not off the `creator`/`teachers` columns: those are |
| 861 | /// historical and no demotion sweeps them, so a demoted ex-teacher lists what |
| 862 | /// they are enrolled in, like any other student. |
| 863 | /// |
| 864 | /// A course carries a title, and `GET /courses/{id}` hands that title only to |
| 865 | /// the enrolled, the staff who run it, and manager+ — so the block is |
| 866 | /// intersected with [`visible_courses`], the same catalog `GET /courses` |
| 867 | /// serves. Reading your own profile, or reading as manager+, needs no |
| 868 | /// intersection: both already see the whole list. |
| 869 | /// |
| 870 | /// The class block answers to [`ensure_can_observe`], the gate |
| 871 | /// `GET /classes/user/{id}` holds — teacher+, or a parent linked to the target |
| 872 | /// — because every other `/classes` read is teacher+ and a class name and grade |
| 873 | /// are exactly what those routes withhold. That gate is all-or-nothing rather |
| 874 | /// than per class, so a viewer who fails it gets an empty block, not a 403: the |
| 875 | /// rest of the profile is still public to them. |
| 876 | /// |
| 877 | /// So no *named* thing here crosses a gate the viewer would fail directly. The |
| 878 | /// magnitudes deliberately do — **every** one of them, not just the two that |
| 879 | /// count the gated blocks. `stats.courses` and `stats.classes` are the obvious |
| 880 | /// pair; `pomodoro_focus_ms` and `pomodoro_focus_ms_total` are byte-identical |
| 881 | /// to the `total_focus_ms` that `GET /pomodoro/{id}` serves behind |
| 882 | /// [`ensure_can_observe`]; and `lessons_attended_total`, |
| 883 | /// `homework_submitted_total`, `homework_on_time_total`, `exam_sat_total` and |
| 884 | /// `high_mark_total` are magnitudes of the same report data that gate holds — |
| 885 | /// for a reader who is exactly [`Role::Teacher`] they are in fact *wider* than |
| 886 | /// the reports themselves, which [`crate::web::marks`] and |
| 887 | /// [`crate::web::attendance`] narrow to the courses that teacher manages. |
| 888 | /// |
| 889 | /// That is the decision, not an oversight: every magnitude in `stats` is the |
| 890 | /// owner's true total for every reader. They are the motivational counters, a |
| 891 | /// per-reader number would make one profile read differently to different |
| 892 | /// people, and a magnitude names no course, no class, no lesson and no exam — |
| 893 | /// the *named* things stay behind their own gates, above. |
| 894 | async |
| 895 | |
| 896 | |
| 897 | |
| 898 | |
| 899 | |
| 900 | |
| 901 | |
| 902 | |
| 903 | |
| 904 | |
| 905 | |
| 906 | |
| 907 | |
| 908 | |
| 909 | |
| 910 | |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
| 915 | |
| 916 | |
| 917 | |
| 918 | |
| 919 | |
| 920 | |
| 921 | |
| 922 | |
| 923 | |
| 924 | |
| 925 | |
| 926 | |
| 927 | |
| 928 | |
| 929 | |
| 930 | |
| 931 | |
| 932 | |
| 933 | |
| 934 | |
| 935 | |
| 936 | |
| 937 | |
| 938 | |
| 939 | |
| 940 | |
| 941 | |
| 942 | |
| 943 | |
| 944 | |
| 945 | |
| 946 | |
| 947 | |
| 948 | |
| 949 | |
| 950 | |
| 951 | |
| 952 | |
| 953 | |
| 954 | |
| 955 | |
| 956 | |
| 957 | |
| 958 | |
| 959 | |
| 960 | |
| 961 | |
| 962 | |
| 963 | |
| 964 | |
| 965 | |
| 966 | |
| 967 | |
| 968 | |
| 969 | |
| 970 | |
| 971 | |
| 972 | |
| 973 | |
| 974 | |
| 975 | |
| 976 | |
| 977 | |
| 978 | |
| 979 | |
| 980 | |
| 981 | |
| 982 | |
| 983 | |
| 984 | |
| 985 | |
| 986 | |
| 987 | |
| 988 | |
| 989 | |
| 990 | |
| 991 | |
| 992 | |
| 993 | |
| 994 | |
| 995 | |
| 996 | |
| 997 | |
| 998 | |
| 999 | |
| 1000 | |
| 1001 | |
| 1002 | |
| 1003 | |
| 1004 | |
| 1005 | |
| 1006 | |
| 1007 | /// The owner's earned badges, and the backstop that keeps them honest. |
| 1008 | /// |
| 1009 | /// Every write that moves a counter syncs the badges behind it, so in the |
| 1010 | /// steady state the earned set holds nothing the award rows do not already |
| 1011 | /// carry and this is one read and **no write at all**. Only a threshold crossed |
| 1012 | /// by a path whose sync was lost — a transient database error, which those |
| 1013 | /// callers log and swallow on purpose — leaves a gap, and that heals here on |
| 1014 | /// the next profile read of that account. |
| 1015 | /// |
| 1016 | /// Nothing here revokes: [`badge::sync`] only ever adds, so a counter that has |
| 1017 | /// since fallen back below its threshold leaves the badge standing. The sync's |
| 1018 | /// own error is logged and dropped, and the awards already read are served — |
| 1019 | /// a decoration may not fail the profile it decorates. |
| 1020 | async |
| 1021 | |
| 1022 | |
| 1023 | |
| 1024 | |
| 1025 | |
| 1026 | |
| 1027 | |
| 1028 | |
| 1029 | |
| 1030 | |
| 1031 | |
| 1032 | |
| 1033 | |
| 1034 | |
| 1035 | |
| 1036 | |
| 1037 | |
| 1038 | |
| 1039 | |
| 1040 | |
| 1041 | /// The profile gate: any authenticated account reads any profile — except a |
| 1042 | /// parent, who is an observer of their own children and of nobody else. The |
| 1043 | /// link alone is not the grant either; [`ensure_can_observe`] re-reads the |
| 1044 | /// target's live role, so a student who was promoted out stops being readable. |
| 1045 | async |
| 1046 | |
| 1047 | |
| 1048 | |
| 1049 | |
| 1050 | |
| 1051 | |
| 1052 | |
| 1053 | |
| 1054 | |
| 1055 | |
| 1056 | /// The target's row, 404 if it is gone, once the caller is allowed to see it. |
| 1057 | async |
| 1058 | |
| 1059 | |
| 1060 | |
| 1061 | |
| 1062 | |
| 1063 | |
| 1064 | |
| 1065 | /// The caller's own public profile — what everyone else sees of them. |
| 1066 | |
| 1067 | |
| 1068 | |
| 1069 | |
| 1070 | |
| 1071 | |
| 1072 | |
| 1073 | |
| 1074 | |
| 1075 | |
| 1076 | async |
| 1077 | |
| 1078 | |
| 1079 | |
| 1080 | |
| 1081 | |
| 1082 | |
| 1083 | /// One user's public profile: display name, bio, avatar meta, their class and |
| 1084 | /// course blocks, the badges they have earned, and the motivational counters. |
| 1085 | /// Badges carry an id and the instant they were first earned; their labels and |
| 1086 | /// icons come from the `badges` catalog at `GET /limits`. Readable by every |
| 1087 | /// authenticated account — except a parent, who reads only their own and their |
| 1088 | /// linked students'. Never carries email, phone, or birth date; those stay on |
| 1089 | /// `GET /users/{id}` (admin) and `GET /auth/me`. The embedded blocks are capped |
| 1090 | /// at `max_profile_classes` / `max_profile_courses` (see `GET /limits`) — the |
| 1091 | /// full paged lists are `GET /classes/me` and `GET /courses/me`. The course |
| 1092 | /// block is also cut to what the *reader* may already see: only courses they |
| 1093 | /// would pass `GET /courses/{id}` on. The class block holds the same bar as |
| 1094 | /// `GET /classes/user/{id}` — teacher+, a parent linked to this student, or the |
| 1095 | /// owner themselves; every other reader gets an empty `classes` array rather |
| 1096 | /// than a 403. Every number in `stats` stays the owner's true total either way, |
| 1097 | /// including the ones whose underlying reports are gated (`/pomodoro/{id}`, |
| 1098 | /// `/marks/user/{id}`, `/attendance/user/{id}`): they are motivational |
| 1099 | /// counters, and a magnitude names no course, class, lesson or exam. |
| 1100 | |
| 1101 | |
| 1102 | |
| 1103 | |
| 1104 | |
| 1105 | |
| 1106 | |
| 1107 | |
| 1108 | |
| 1109 | |
| 1110 | |
| 1111 | |
| 1112 | |
| 1113 | async |
| 1114 | |
| 1115 | |
| 1116 | |
| 1117 | |
| 1118 | |
| 1119 | |
| 1120 | |
| 1121 | |
| 1122 | // ---- the avatar ------------------------------------------------------------- |
| 1123 | // One optional picture per user, the same one-image-on-the-owning-row shape the |
| 1124 | // question pool uses: bytes on disk under a server-generated ULID, metadata on |
| 1125 | // the user row. Every write here must take the replaced blob off disk — no |
| 1126 | // route deletes a user, so nothing else would ever collect it. |
| 1127 | |
| 1128 | /// Upload (or replace) the caller's own avatar. `multipart/form-data` with the |
| 1129 | /// image under a `file` field; the declared content type must be `image/png`, |
| 1130 | /// `image/jpeg`, `image/webp`, or `image/gif` (rasters only — no SVG), the |
| 1131 | /// bytes at most the school's `max_file_bytes` (settings). Replacing one drops |
| 1132 | /// the previous picture. |
| 1133 | |
| 1134 | |
| 1135 | |
| 1136 | |
| 1137 | |
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 | |
| 1142 | |
| 1143 | |
| 1144 | |
| 1145 | |
| 1146 | |
| 1147 | async |
| 1148 | |
| 1149 | |
| 1150 | |
| 1151 | |
| 1152 | |
| 1153 | |
| 1154 | |
| 1155 | |
| 1156 | |
| 1157 | |
| 1158 | |
| 1159 | |
| 1160 | |
| 1161 | |
| 1162 | |
| 1163 | |
| 1164 | |
| 1165 | |
| 1166 | |
| 1167 | |
| 1168 | |
| 1169 | |
| 1170 | |
| 1171 | |
| 1172 | |
| 1173 | |
| 1174 | |
| 1175 | |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 | |
| 1180 | |
| 1181 | |
| 1182 | /// The caller's own avatar bytes. The self alias of `GET /{id}/avatar` — the |
| 1183 | /// static `/me/avatar` segment wins over `/{id}/avatar` in the router, so |
| 1184 | /// without this a client that never learned its own id gets a bodyless `405` |
| 1185 | /// on the obvious route. It serves the caller's own row and nothing else, so |
| 1186 | /// it asks no gate: the session already proves the reach. |
| 1187 | |
| 1188 | |
| 1189 | |
| 1190 | |
| 1191 | |
| 1192 | |
| 1193 | |
| 1194 | |
| 1195 | |
| 1196 | |
| 1197 | |
| 1198 | async |
| 1199 | |
| 1200 | |
| 1201 | |
| 1202 | |
| 1203 | |
| 1204 | |
| 1205 | /// The avatar bytes. Same reach as the profile itself: every authenticated |
| 1206 | /// account, except a parent, who is limited to their own and their linked |
| 1207 | /// students'. |
| 1208 | |
| 1209 | |
| 1210 | |
| 1211 | |
| 1212 | |
| 1213 | |
| 1214 | |
| 1215 | |
| 1216 | |
| 1217 | |
| 1218 | |
| 1219 | |
| 1220 | |
| 1221 | async |
| 1222 | |
| 1223 | |
| 1224 | |
| 1225 | |
| 1226 | |
| 1227 | |
| 1228 | |
| 1229 | |
| 1230 | /// The shared tail of both avatar reads: the bytes, or a `404` when the row |
| 1231 | /// carries none. The caller owns the gate — this one is reached already. |
| 1232 | async |
| 1233 | |
| 1234 | |
| 1235 | |
| 1236 | |
| 1237 | |
| 1238 | |
| 1239 | |
| 1240 | |
| 1241 | /// Remove the caller's own avatar. |
| 1242 | |
| 1243 | |
| 1244 | |
| 1245 | |
| 1246 | |
| 1247 | |
| 1248 | |
| 1249 | |
| 1250 | |
| 1251 | |
| 1252 | |
| 1253 | async |
| 1254 | |
| 1255 | |
| 1256 | |
| 1257 | |
| 1258 | |
| 1259 | |
| 1260 | /// Remove any user's avatar. Admin only — the moderation path: an offensive |
| 1261 | /// picture is a school problem, and no route deletes the account it hangs on. |
| 1262 | |
| 1263 | |
| 1264 | |
| 1265 | |
| 1266 | |
| 1267 | |
| 1268 | |
| 1269 | |
| 1270 | |
| 1271 | |
| 1272 | |
| 1273 | |
| 1274 | |
| 1275 | async |
| 1276 | |
| 1277 | |
| 1278 | |
| 1279 | |
| 1280 | |
| 1281 | |
| 1282 | |
| 1283 | /// Clear the row's avatar and take its blob off disk — the shared tail of the |
| 1284 | /// self and moderation deletes. A row without one (or no row at all) is a 404. |
| 1285 | async |
| 1286 | |
| 1287 | |
| 1288 | |
| 1289 | |
| 1290 | |
| 1291 | |
| 1292 | |
| 1293 | |
| 1294 |