hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiB08aa13eAhmet Kaan Gümüş2 months ago378 commits
| 1 | //! `GET /limits` — every compile-time validation bound, served as data. |
| 2 | //! |
| 3 | //! The frontend has to enforce the same rules the newtypes do (a `maxlength` |
| 4 | //! on an input, a client-side check before a doomed request). Hard-coding them |
| 5 | //! there means two copies that silently drift apart the day one moves. This |
| 6 | //! endpoint is the single source: every field below reads a `crate::constant` |
| 7 | //! item directly, so a changed constant changes the response in the same |
| 8 | //! commit. |
| 9 | //! |
| 10 | //! School-adjustable policy (exam kinds, attendance statuses, grade bands, the |
| 11 | //! live `max_file_bytes`) lives in `GET /settings` — this route carries only |
| 12 | //! the fixed bounds those settings must themselves stay inside. |
| 13 | |
| 14 | use Json; |
| 15 | use State; |
| 16 | use Serialize; |
| 17 | use ToSchema; |
| 18 | use OpenApiRouter; |
| 19 | use routes; |
| 20 | |
| 21 | use crate*; |
| 22 | use crate; |
| 23 | use crateAppState; |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | /// Account fields: credentials, profile, and the closed role set. |
| 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 | |
| 78 | |
| 79 | $")] |
| 80 | palette_color_pattern: &'static str, |
| 81 | /// Length of a `palette_color`, `#` included. |
| 82 | palette_color_len: usize, |
| 83 | /// How long a login session stays valid, days. |
| 84 | session_duration_days: i64, |
| 85 | } |
| 86 | |
| 87 | /// The auto-earned badge catalog. A group like every other key here, so a |
| 88 | /// client can walk this response uniformly; the catalog itself is the one |
| 89 | /// field inside. |
| 90 | #[derive(Serialize, ToSchema)] |
| 91 | struct BadgeLimits { |
| 92 | /// Every badge the system can auto-award, in catalog order. Hardcoded, so |
| 93 | /// like everything else here it moves only with a deploy. |
| 94 | catalog: Vec<BadgeLimit>, |
| 95 | /// The exam mark that counts as a high one, out of `mark.max_mark`, behind |
| 96 | /// the `high_mark` ladder. Published because the id alone does not say it: |
| 97 | /// deliberately not the school's grade bands, which are renameable labels. |
| 98 | #[schema(example = 90)] |
| 99 | high_mark_min: i64, |
| 100 | } |
| 101 | |
| 102 | /// One badge in the auto-earned catalog. The id is the whole contract: a |
| 103 | /// profile hands back ids and nothing else, and the label and icon behind one |
| 104 | /// live in the client, exactly as they do for a role or a course kind. |
| 105 | #[derive(Serialize, ToSchema)] |
| 106 | struct BadgeLimit { |
| 107 | /// Stable id, never reused for another meaning. A retired badge simply |
| 108 | /// stops appearing here. |
| 109 | #[schema(example = "homework_submitted_10")] |
| 110 | id: &'static str, |
| 111 | /// The lifetime counter it reads — badges sharing one form a ladder. An |
| 112 | /// API-side name, not the column it is stored in, so storage can be |
| 113 | /// renamed without moving this contract. |
| 114 | #[schema(example = "homework_submitted")] |
| 115 | stat: &'static str, |
| 116 | /// Counter value that earns it. Awards are permanent: a counter that later |
| 117 | /// falls back below this does not take the badge away. |
| 118 | #[schema(example = 10)] |
| 119 | threshold: i64, |
| 120 | } |
| 121 | |
| 122 | /// Note bodies and their attachments. |
| 123 | #[derive(Serialize, ToSchema)] |
| 124 | struct NoteLimits { |
| 125 | max_title_len: usize, |
| 126 | max_content_len: usize, |
| 127 | /// How many files one note may carry. |
| 128 | max_files: usize, |
| 129 | /// How many files one course note may carry. |
| 130 | max_course_note_files: usize, |
| 131 | } |
| 132 | |
| 133 | /// Uploaded-file metadata, shared by every upload route. |
| 134 | #[derive(Serialize, ToSchema)] |
| 135 | struct FileLimits { |
| 136 | max_name_len: usize, |
| 137 | max_content_type_len: usize, |
| 138 | /// Inclusive range a manager may set `max_file_bytes` to in `/settings`; |
| 139 | /// the live value is on `GET /settings`, this is the hard ceiling above it. |
| 140 | min_max_file_bytes: i64, |
| 141 | max_max_file_bytes: i64, |
| 142 | default_max_file_bytes: i64, |
| 143 | /// Content types an inline image (question illustrations, option pictures, |
| 144 | /// pool photos, answer drawings) may declare. Raster only — no SVG. |
| 145 | #[schema(example = json!(["image/png", "image/jpeg", "image/webp", "image/gif"]))] |
| 146 | image_content_types: Vec<&'static str>, |
| 147 | } |
| 148 | |
| 149 | /// One-to-one messages. |
| 150 | #[derive(Serialize, ToSchema)] |
| 151 | struct MessageLimits { |
| 152 | max_subject_len: usize, |
| 153 | max_body_len: usize, |
| 154 | /// The sender's optional free-text badge. |
| 155 | max_label_len: usize, |
| 156 | } |
| 157 | |
| 158 | /// Events and their registration lists. |
| 159 | #[derive(Serialize, ToSchema)] |
| 160 | struct EventLimits { |
| 161 | max_title_len: usize, |
| 162 | max_description_len: usize, |
| 163 | } |
| 164 | |
| 165 | /// Courses, their curriculum subjects, lesson sessions, and the classes that |
| 166 | /// bulk-enroll into them. |
| 167 | #[derive(Serialize, ToSchema)] |
| 168 | struct CourseLimits { |
| 169 | max_title_len: usize, |
| 170 | max_description_len: usize, |
| 171 | /// The only accepted `kind` values — behaviorally identical labels. |
| 172 | #[schema(example = json!(["course", "study", "club"]))] |
| 173 | kinds: Vec<&'static str>, |
| 174 | max_subject_name_len: usize, |
| 175 | max_subject_description_len: usize, |
| 176 | max_session_topic_len: usize, |
| 177 | max_term_name_len: usize, |
| 178 | max_class_name_len: usize, |
| 179 | /// A class's optional free-text grade label ("9", "10-A"). |
| 180 | max_class_grade_len: usize, |
| 181 | /// Students one class may hold. Removing one frees a place. |
| 182 | max_class_members: i64, |
| 183 | /// Courses one class may be attached to. Detaching one frees a place. |
| 184 | max_class_courses: i64, |
| 185 | } |
| 186 | |
| 187 | /// Exams, their questions, answers, and marks. |
| 188 | #[derive(Serialize, ToSchema)] |
| 189 | struct ExamLimits { |
| 190 | max_title_len: usize, |
| 191 | max_description_len: usize, |
| 192 | /// The only accepted `mode` values; an exam with no mode is offline-graded. |
| 193 | #[schema(example = json!(["sync", "async", "open"]))] |
| 194 | modes: Vec<&'static str>, |
| 195 | /// Inclusive bounds for `duration_ms` (1 minute – 24 hours). |
| 196 | min_duration_ms: i64, |
| 197 | max_duration_ms: i64, |
| 198 | /// Upper bound for `max_attempts`; `unlimited_attempts` (0) means no limit. |
| 199 | max_attempts: i64, |
| 200 | unlimited_attempts: i64, |
| 201 | /// The only accepted question `kind` values. |
| 202 | #[schema(example = json!(["choice", "text"]))] |
| 203 | question_kinds: Vec<&'static str>, |
| 204 | max_question_text_len: usize, |
| 205 | min_question_points: i64, |
| 206 | max_question_points: i64, |
| 207 | min_question_choices: usize, |
| 208 | max_question_choices: usize, |
| 209 | max_choice_text_len: usize, |
| 210 | max_answer_text_len: usize, |
| 211 | min_mark: i64, |
| 212 | max_mark: i64, |
| 213 | /// Cadence of the exam-room WebSocket's `state` frames, seconds. |
| 214 | ws_tick_secs: u64, |
| 215 | /// Ceiling on a `question_id` sent over the exam-room WebSocket. |
| 216 | ws_max_question_id_len: usize, |
| 217 | } |
| 218 | |
| 219 | /// Homework assignments and submissions. |
| 220 | #[derive(Serialize, ToSchema)] |
| 221 | struct HomeworkLimits { |
| 222 | max_title_len: usize, |
| 223 | max_description_len: usize, |
| 224 | /// A submission's optional free-text note. |
| 225 | max_text_len: usize, |
| 226 | max_files_per_submission: usize, |
| 227 | /// How many students an explicit `assigned` subset may name. |
| 228 | max_assigned: usize, |
| 229 | /// The only accepted teacher-set `status` values. |
| 230 | #[schema(example = json!(["done", "incomplete", "missing"]))] |
| 231 | statuses: Vec<&'static str>, |
| 232 | } |
| 233 | |
| 234 | /// The school question pool and its solutions. |
| 235 | #[derive(Serialize, ToSchema)] |
| 236 | struct QuestionPoolLimits { |
| 237 | max_title_len: usize, |
| 238 | max_body_len: usize, |
| 239 | max_solution_body_len: usize, |
| 240 | } |
| 241 | |
| 242 | /// Teacher availability slots and the bookings on them. |
| 243 | #[derive(Serialize, ToSchema)] |
| 244 | struct AppointmentLimits { |
| 245 | /// A published slot's optional note. |
| 246 | max_note_len: usize, |
| 247 | /// The requester's required reason. |
| 248 | max_reason_len: usize, |
| 249 | /// How many slots one weekly-repeating publish may expand into. |
| 250 | max_slot_occurrences: usize, |
| 251 | } |
| 252 | |
| 253 | /// The food program: menus and their dishes, dietary profiles, bookings and |
| 254 | /// the meal ledger. The school's own lists (`meal_slots`, `dietary_tags`) and |
| 255 | /// its booking cutoff are on `GET /settings`; what stands here is the fixed |
| 256 | /// range those must stay inside. |
| 257 | #[derive(Serialize, ToSchema)] |
| 258 | struct MealLimits { |
| 259 | max_dish_name_len: usize, |
| 260 | max_dish_description_len: usize, |
| 261 | /// How many dishes one menu may list. |
| 262 | max_dishes_per_menu: usize, |
| 263 | /// Dietary tags one dish may carry. |
| 264 | max_dish_tags: usize, |
| 265 | /// Upper bound for a menu's optional `capacity`; absent = uncapped. |
| 266 | max_menu_capacity: i64, |
| 267 | /// How many times one student's seat on one menu may be taken — the first |
| 268 | /// booking plus the re-bookings after a cancel. Past it, `POST |
| 269 | /// /meals/menus/{id}/bookings` is a `409`: every cycle writes two |
| 270 | /// permanent ledger lines, so this bounds the statement, not the mind |
| 271 | /// changing. Only the canteen can free such a seat afterwards. |
| 272 | max_booking_attempts: i64, |
| 273 | /// Dietary tags one student's profile may carry, and its kitchen note. |
| 274 | max_dietary_tags: usize, |
| 275 | max_dietary_note_len: usize, |
| 276 | /// Money is **minor units** (kuruş) as an integer everywhere — never a |
| 277 | /// decimal, never a float. These cap one dish and one ledger line. |
| 278 | max_dish_price_minor: i64, |
| 279 | max_ledger_amount_minor: i64, |
| 280 | /// How the money moved, and why. |
| 281 | max_ledger_method_len: usize, |
| 282 | max_ledger_note_len: usize, |
| 283 | /// Ceiling on the `/settings` knob that closes booking (and cancelling) |
| 284 | /// ahead of a meal, minutes; the live value is on `GET /settings`. |
| 285 | max_cancel_cutoff_minutes: i64, |
| 286 | /// Ceiling on a meal slot's `serving_minute` — minutes past midnight |
| 287 | /// **UTC** on the menu's date, which is what the cutoff counts back from. |
| 288 | /// `1439` = 23:59 UTC. There is no school timezone: staff enter UTC. |
| 289 | max_serving_minute: i64, |
| 290 | /// The only accepted booking `status` values. |
| 291 | #[schema(example = json!(["booked", "cancelled"]))] |
| 292 | booking_statuses: Vec<&'static str>, |
| 293 | /// The only accepted meal-attendance `status` values — deliberately not |
| 294 | /// the school's lesson attendance statuses. |
| 295 | #[schema(example = json!(["served", "missed"]))] |
| 296 | attendance_statuses: Vec<&'static str>, |
| 297 | /// The only accepted ledger `kind` values. |
| 298 | #[schema(example = json!(["charge", "credit", "reversal"]))] |
| 299 | ledger_kinds: Vec<&'static str>, |
| 300 | } |
| 301 | |
| 302 | /// School payments: fee plans, their assignment, and the payment ledger. Money |
| 303 | /// is **minor units** (kuruş) as an integer, and one ledger line is capped by |
| 304 | /// the same `max_ledger_amount_minor` the meal ledger publishes. |
| 305 | #[derive(Serialize, ToSchema)] |
| 306 | struct PaymentLimits { |
| 307 | max_plan_name_len: usize, |
| 308 | /// How many installments one fee plan may schedule. |
| 309 | max_plan_installments: usize, |
| 310 | /// How many students one bulk assignment may name. |
| 311 | max_assign_students: usize, |
| 312 | /// How many charge lines one bulk assignment may append — the students it |
| 313 | /// names times the plan's installments. A request past this is a `400` |
| 314 | /// telling the caller to split the batch; nothing is written. |
| 315 | max_assign_writes: usize, |
| 316 | /// How many lines may be applied to one ledger line: the payments under a |
| 317 | /// charge, the refunds under a payment, and the reversals among them. Past |
| 318 | /// it, a further payment or refund against that line is a `409`. |
| 319 | max_applied_lines: usize, |
| 320 | /// Ceiling on the optional `request_key` that makes a credit or a refund |
| 321 | /// retry-safe; charset `[A-Za-z0-9-]` (no `_`), at least one character. |
| 322 | max_request_key_len: usize, |
| 323 | /// The only accepted payment-ledger `kind` values. |
| 324 | #[schema(example = json!(["charge", "credit", "reversal", "refund"]))] |
| 325 | ledger_kinds: Vec<&'static str>, |
| 326 | } |
| 327 | |
| 328 | /// The AI chatbot. Each range bounds the matching `/settings` knob; the live |
| 329 | /// values are on `GET /settings`. |
| 330 | #[derive(Serialize, ToSchema)] |
| 331 | struct ChatbotLimits { |
| 332 | /// Hard ceiling on a message, above which no school setting can reach. |
| 333 | max_message_len: usize, |
| 334 | /// A thread's display name. Threads are named by hand or left untitled — |
| 335 | /// nothing auto-titles one. |
| 336 | max_thread_title_len: usize, |
| 337 | min_max_message_len: i64, |
| 338 | max_max_message_len: i64, |
| 339 | default_max_message_len: i64, |
| 340 | min_history_turns: i64, |
| 341 | max_history_turns: i64, |
| 342 | default_history_turns: i64, |
| 343 | min_max_threads: i64, |
| 344 | max_max_threads: i64, |
| 345 | default_max_threads: i64, |
| 346 | } |
| 347 | |
| 348 | /// What a finished pomodoro stint must be to *count* — to move the lifetime |
| 349 | /// counters the badges and the study streak read. Not a validation bound: |
| 350 | /// `POST /pomodoro/finish` never refuses a stint over these, it records it and |
| 351 | /// answers `counted: false`. Published so a client can say what a stint is |
| 352 | /// worth (and what is left of today's quota) instead of guessing why a badge |
| 353 | /// did not arrive. |
| 354 | #[derive(Serialize, ToSchema)] |
| 355 | struct PomodoroLimits { |
| 356 | /// Shortest stint that counts, milliseconds — a stint of exactly this long |
| 357 | /// counts. Well under a conventional 25-minute pomodoro: breaking off early |
| 358 | /// is still studying. Its job is only to price a scripted round-trip out. |
| 359 | #[schema(example = 300000)] |
| 360 | min_counted_ms: i64, |
| 361 | /// How many stints count per UTC day. Every further one that day is |
| 362 | /// recorded and listed as usual, and counts nothing. |
| 363 | #[schema(example = 16)] |
| 364 | max_counted_per_day: i64, |
| 365 | } |
| 366 | |
| 367 | /// A collaborative whiteboard: its title, its roster, and the two growth caps |
| 368 | /// that decide when a canvas must be cleared and when a board is finished. |
| 369 | #[derive(Serialize, ToSchema)] |
| 370 | struct BoardLimits { |
| 371 | max_title_len: usize, |
| 372 | /// People the creator may name onto one board. Every participant draws, so |
| 373 | /// this also bounds a room's writer count. |
| 374 | max_participants: usize, |
| 375 | /// Ceiling on one stroke's serialized payload, bytes. |
| 376 | max_stroke_payload_len: usize, |
| 377 | /// The *live* canvas cap: strokes since the last clear. Hitting it is |
| 378 | /// recoverable — the creator clears, the canvas empties, the history is |
| 379 | /// kept, and drawing resumes. |
| 380 | max_epoch_strokes: i64, |
| 381 | /// The *lifetime* storage cap, which never resets because a clear keeps its |
| 382 | /// history. Hitting it makes the board permanently read-only: it stays |
| 383 | /// fully readable and replayable, and a new board must be opened. |
| 384 | max_board_strokes: i64, |
| 385 | /// Boards one creating user may hold. Deleting a board frees a seat. |
| 386 | max_boards_per_creator: i64, |
| 387 | /// The accepted stroke kinds. `clear` is a marker that ends an epoch, not a |
| 388 | /// deletion. |
| 389 | #[schema(example = json!(["stroke", "clear"]))] |
| 390 | stroke_kinds: Vec<&'static str>, |
| 391 | /// Cadence of the board-room WebSocket's keepalive ticks, seconds. |
| 392 | ws_tick_secs: u64, |
| 393 | /// Ceiling on a `board_id` sent over the board-room WebSocket. |
| 394 | ws_max_board_id_len: usize, |
| 395 | } |
| 396 | |
| 397 | /// Bounds on the school-editable lists in `PATCH /settings`. |
| 398 | #[derive(Serialize, ToSchema)] |
| 399 | struct SettingsLimits { |
| 400 | /// Entry count for the exam-kind and attendance-status lists. |
| 401 | max_list_len: usize, |
| 402 | /// Per-entry characters in those lists. |
| 403 | max_item_len: usize, |
| 404 | min_exam_kind_weight: i64, |
| 405 | max_exam_kind_weight: i64, |
| 406 | max_grade_bands: usize, |
| 407 | max_grade_label_len: usize, |
| 408 | /// Attendance statuses no school may remove. |
| 409 | #[schema(example = json!(["present", "absent", "late", "excused"]))] |
| 410 | required_attendance_statuses: Vec<&'static str>, |
| 411 | } |
| 412 | |
| 413 | /// The request budgets a caller is held to before it starts getting `429`s |
| 414 | /// with a `Retry-After`. Unlike everything else here these are **deployment** |
| 415 | /// configuration, not compile-time constants — they come from environment |
| 416 | /// variables, so the numbers are this server's live values rather than fixed |
| 417 | /// ones. `0` means the tier is switched off. |
| 418 | #[derive(Serialize, ToSchema)] |
| 419 | struct RateLimits { |
| 420 | /// Fixed window every tier is counted over, seconds. |
| 421 | window_secs: u64, |
| 422 | /// Per-IP budget for `/auth/login` and `/auth/register`. |
| 423 | #[schema(example = 10)] |
| 424 | auth_per_minute: u32, |
| 425 | /// Per-IP budget across the whole API, this endpoint included. |
| 426 | #[schema(example = 300)] |
| 427 | api_per_minute: u32, |
| 428 | /// Per-*user* budget for sending chatbot messages (keyed by account, not |
| 429 | /// address, so it survives a changing IP). |
| 430 | #[schema(example = 20)] |
| 431 | chatbot_per_minute: u32, |
| 432 | } |
| 433 | |
| 434 | /// Rules that hold across every endpoint. |
| 435 | #[derive(Serialize, ToSchema)] |
| 436 | struct RequestLimits { |
| 437 | /// Upper bound on a list endpoint's `?limit=`. Omitting it returns |
| 438 | /// everything remaining. |
| 439 | max_page_limit: i64, |
| 440 | /// How far in the past a submitted schedule instant may lie before it is |
| 441 | /// refused as backdated — the grace that absorbs clock skew. |
| 442 | schedule_past_grace_ms: i64, |
| 443 | /// Ceiling on how long one request may take before it is aborted. |
| 444 | request_timeout_secs: u64, |
| 445 | /// Longest `x-request-id` header the server keeps. A longer one — or one |
| 446 | /// carrying anything outside `[A-Za-z0-9._-]` — is replaced by a |
| 447 | /// server-minted UUID, so the caller loses correlation on its own id. |
| 448 | max_request_id_len: usize, |
| 449 | } |
| 450 | |
| 451 | /// Every fixed limit the API enforces, grouped by the resource it applies to. |
| 452 | #[derive(Serialize, ToSchema)] |
| 453 | struct LimitsResponse { |
| 454 | user: UserLimits, |
| 455 | badges: BadgeLimits, |
| 456 | note: NoteLimits, |
| 457 | file: FileLimits, |
| 458 | message: MessageLimits, |
| 459 | event: EventLimits, |
| 460 | course: CourseLimits, |
| 461 | exam: ExamLimits, |
| 462 | homework: HomeworkLimits, |
| 463 | question_pool: QuestionPoolLimits, |
| 464 | appointment: AppointmentLimits, |
| 465 | meal: MealLimits, |
| 466 | payment: PaymentLimits, |
| 467 | chatbot: ChatbotLimits, |
| 468 | pomodoro: PomodoroLimits, |
| 469 | board: BoardLimits, |
| 470 | settings: SettingsLimits, |
| 471 | request: RequestLimits, |
| 472 | rate: RateLimits, |
| 473 | } |
| 474 | |
| 475 | impl LimitsResponse { |
| 476 | fn new(st: &AppState) -> Self { |
| 477 | Self { |
| 478 | user: UserLimits { |
| 479 | min_slug_len: MIN_SLUG_LEN, |
| 480 | max_slug_len: MAX_SLUG_LEN, |
| 481 | reserved_slugs: crate::tenant::RESERVED_SLUGS.to_vec(), |
| 482 | max_school_name_len: MAX_SCHOOL_NAME_LEN, |
| 483 | min_username_len: MIN_USERNAME_LEN, |
| 484 | max_username_len: MAX_USERNAME_LEN, |
| 485 | username_separators: USERNAME_SEPARATORS.iter().map(char::to_string).collect(), |
| 486 | reserved_usernames: RESERVED_USERNAMES.to_vec(), |
| 487 | min_password_len: MIN_PASSWORD_LEN, |
| 488 | max_password_len: MAX_PASSWORD_LEN, |
| 489 | max_name_len: MAX_NAME_LEN, |
| 490 | max_display_name_len: MAX_DISPLAY_NAME_LEN, |
| 491 | max_bio_len: MAX_BIO_LEN, |
| 492 | max_profile_courses: MAX_PROFILE_COURSES, |
| 493 | max_profile_classes: MAX_PROFILE_CLASSES, |
| 494 | max_email_len: MAX_EMAIL_LEN, |
| 495 | min_phone_digits: MIN_PHONE_DIGITS, |
| 496 | max_phone_digits: MAX_PHONE_DIGITS, |
| 497 | roles: ROLES.iter().map(|role| role.as_str()).collect(), |
| 498 | themes: THEMES.iter().map(|theme| theme.as_str()).collect(), |
| 499 | languages: LANGUAGES.iter().map(|language| language.as_str()).collect(), |
| 500 | palette_color_pattern: PALETTE_COLOR_PATTERN, |
| 501 | palette_color_len: PALETTE_COLOR_LEN, |
| 502 | session_duration_days: SESSION_DURATION_DAYS, |
| 503 | }, |
| 504 | badges: BadgeLimits { |
| 505 | catalog: BADGES |
| 506 | .iter() |
| 507 | .map(|(id, stat, threshold)| BadgeLimit { |
| 508 | id, |
| 509 | stat: stat.as_str(), |
| 510 | threshold: *threshold, |
| 511 | }) |
| 512 | .collect(), |
| 513 | high_mark_min: HIGH_MARK_MIN, |
| 514 | }, |
| 515 | note: NoteLimits { |
| 516 | max_title_len: MAX_NOTE_TITLE_LEN, |
| 517 | max_content_len: MAX_NOTE_CONTENT_LEN, |
| 518 | max_files: MAX_NOTE_FILES, |
| 519 | max_course_note_files: MAX_COURSE_NOTE_FILES, |
| 520 | }, |
| 521 | file: FileLimits { |
| 522 | max_name_len: MAX_FILE_NAME_LEN, |
| 523 | max_content_type_len: MAX_FILE_CONTENT_TYPE_LEN, |
| 524 | min_max_file_bytes: MIN_MAX_FILE_BYTES, |
| 525 | max_max_file_bytes: MAX_MAX_FILE_BYTES, |
| 526 | default_max_file_bytes: DEFAULT_MAX_FILE_BYTES, |
| 527 | image_content_types: QUESTION_IMAGE_CONTENT_TYPES.to_vec(), |
| 528 | }, |
| 529 | message: MessageLimits { |
| 530 | max_subject_len: MAX_MESSAGE_SUBJECT_LEN, |
| 531 | max_body_len: MAX_MESSAGE_BODY_LEN, |
| 532 | max_label_len: MAX_MESSAGE_LABEL_LEN, |
| 533 | }, |
| 534 | event: EventLimits { |
| 535 | max_title_len: MAX_EVENT_TITLE_LEN, |
| 536 | max_description_len: MAX_EVENT_DESCRIPTION_LEN, |
| 537 | }, |
| 538 | course: CourseLimits { |
| 539 | max_title_len: MAX_COURSE_TITLE_LEN, |
| 540 | max_description_len: MAX_COURSE_DESCRIPTION_LEN, |
| 541 | kinds: COURSE_KINDS.to_vec(), |
| 542 | max_subject_name_len: MAX_SUBJECT_NAME_LEN, |
| 543 | max_subject_description_len: MAX_SUBJECT_DESCRIPTION_LEN, |
| 544 | max_session_topic_len: MAX_SESSION_TOPIC_LEN, |
| 545 | max_term_name_len: MAX_TERM_NAME_LEN, |
| 546 | max_class_name_len: MAX_CLASS_NAME_LEN, |
| 547 | max_class_grade_len: MAX_CLASS_GRADE_LEN, |
| 548 | max_class_members: MAX_CLASS_MEMBERS, |
| 549 | max_class_courses: MAX_CLASS_COURSES, |
| 550 | }, |
| 551 | exam: ExamLimits { |
| 552 | max_title_len: MAX_EXAM_TITLE_LEN, |
| 553 | max_description_len: MAX_EXAM_DESCRIPTION_LEN, |
| 554 | modes: EXAM_MODES.to_vec(), |
| 555 | min_duration_ms: MIN_EXAM_DURATION_MS, |
| 556 | max_duration_ms: MAX_EXAM_DURATION_MS, |
| 557 | max_attempts: MAX_EXAM_ATTEMPTS, |
| 558 | unlimited_attempts: UNLIMITED_EXAM_ATTEMPTS, |
| 559 | question_kinds: QUESTION_KINDS.to_vec(), |
| 560 | max_question_text_len: MAX_QUESTION_TEXT_LEN, |
| 561 | min_question_points: MIN_QUESTION_POINTS, |
| 562 | max_question_points: MAX_QUESTION_POINTS, |
| 563 | min_question_choices: MIN_QUESTION_CHOICES, |
| 564 | max_question_choices: MAX_QUESTION_CHOICES, |
| 565 | max_choice_text_len: MAX_CHOICE_TEXT_LEN, |
| 566 | max_answer_text_len: MAX_ANSWER_TEXT_LEN, |
| 567 | min_mark: MIN_MARK, |
| 568 | max_mark: MAX_MARK, |
| 569 | ws_tick_secs: EXAM_WS_TICK_SECS, |
| 570 | ws_max_question_id_len: MAX_QUESTION_ID_LEN, |
| 571 | }, |
| 572 | homework: HomeworkLimits { |
| 573 | max_title_len: MAX_HOMEWORK_TITLE_LEN, |
| 574 | max_description_len: MAX_HOMEWORK_DESCRIPTION_LEN, |
| 575 | max_text_len: MAX_HOMEWORK_TEXT_LEN, |
| 576 | max_files_per_submission: MAX_HOMEWORK_FILES_PER_SUBMISSION, |
| 577 | max_assigned: MAX_HOMEWORK_ASSIGNED, |
| 578 | statuses: HOMEWORK_STATUSES.to_vec(), |
| 579 | }, |
| 580 | question_pool: QuestionPoolLimits { |
| 581 | max_title_len: MAX_POOL_QUESTION_TITLE_LEN, |
| 582 | max_body_len: MAX_POOL_QUESTION_BODY_LEN, |
| 583 | max_solution_body_len: MAX_SOLUTION_BODY_LEN, |
| 584 | }, |
| 585 | appointment: AppointmentLimits { |
| 586 | max_note_len: MAX_APPOINTMENT_NOTE_LEN, |
| 587 | max_reason_len: MAX_APPOINTMENT_REASON_LEN, |
| 588 | max_slot_occurrences: MAX_SLOT_OCCURRENCES, |
| 589 | }, |
| 590 | meal: MealLimits { |
| 591 | max_dish_name_len: MAX_DISH_NAME_LEN, |
| 592 | max_dish_description_len: MAX_DISH_DESCRIPTION_LEN, |
| 593 | max_dishes_per_menu: MAX_DISHES_PER_MENU, |
| 594 | max_dish_tags: MAX_DISH_TAGS, |
| 595 | max_menu_capacity: MAX_MENU_CAPACITY, |
| 596 | max_booking_attempts: MAX_MEAL_BOOKING_ATTEMPTS, |
| 597 | max_dietary_tags: MAX_DIETARY_TAGS, |
| 598 | max_dietary_note_len: MAX_DIETARY_NOTE_LEN, |
| 599 | max_dish_price_minor: MAX_DISH_PRICE_MINOR, |
| 600 | max_ledger_amount_minor: MAX_LEDGER_AMOUNT_MINOR, |
| 601 | max_ledger_method_len: MAX_LEDGER_METHOD_LEN, |
| 602 | max_ledger_note_len: MAX_LEDGER_NOTE_LEN, |
| 603 | max_cancel_cutoff_minutes: MAX_MEAL_CANCEL_CUTOFF_MINUTES, |
| 604 | max_serving_minute: MAX_MEAL_SERVING_MINUTE, |
| 605 | booking_statuses: MEAL_BOOKING_STATUSES.to_vec(), |
| 606 | attendance_statuses: MEAL_ATTENDANCE_STATUSES.to_vec(), |
| 607 | ledger_kinds: MEAL_LEDGER_KINDS.to_vec(), |
| 608 | }, |
| 609 | payment: PaymentLimits { |
| 610 | max_plan_name_len: MAX_FEE_PLAN_NAME_LEN, |
| 611 | max_plan_installments: MAX_FEE_PLAN_INSTALLMENTS, |
| 612 | max_assign_students: MAX_FEE_PLAN_ASSIGN_STUDENTS, |
| 613 | max_assign_writes: MAX_FEE_PLAN_ASSIGN_WRITES, |
| 614 | max_applied_lines: MAX_LEDGER_APPLIED_LINES, |
| 615 | max_request_key_len: MAX_PAYMENT_REQUEST_KEY_LEN, |
| 616 | ledger_kinds: PAYMENT_LEDGER_KINDS.to_vec(), |
| 617 | }, |
| 618 | chatbot: ChatbotLimits { |
| 619 | max_message_len: MAX_CHATBOT_MESSAGE_LEN, |
| 620 | max_thread_title_len: MAX_CHATBOT_THREAD_TITLE_LEN, |
| 621 | min_max_message_len: MIN_MAX_CHATBOT_MESSAGE_LEN, |
| 622 | max_max_message_len: MAX_MAX_CHATBOT_MESSAGE_LEN, |
| 623 | default_max_message_len: DEFAULT_MAX_CHATBOT_MESSAGE_LEN, |
| 624 | min_history_turns: MIN_CHATBOT_HISTORY_TURNS, |
| 625 | max_history_turns: MAX_CHATBOT_HISTORY_TURNS, |
| 626 | default_history_turns: DEFAULT_CHATBOT_HISTORY_TURNS, |
| 627 | min_max_threads: MIN_MAX_CHATBOT_THREADS, |
| 628 | max_max_threads: MAX_MAX_CHATBOT_THREADS, |
| 629 | default_max_threads: DEFAULT_MAX_CHATBOT_THREADS, |
| 630 | }, |
| 631 | pomodoro: PomodoroLimits { |
| 632 | min_counted_ms: MIN_COUNTED_POMODORO_MS, |
| 633 | max_counted_per_day: MAX_COUNTED_POMODORO_PER_DAY, |
| 634 | }, |
| 635 | board: BoardLimits { |
| 636 | max_title_len: MAX_BOARD_TITLE_LEN, |
| 637 | max_participants: MAX_BOARD_PARTICIPANTS, |
| 638 | max_stroke_payload_len: MAX_STROKE_PAYLOAD_LEN, |
| 639 | max_epoch_strokes: MAX_EPOCH_STROKES, |
| 640 | max_board_strokes: MAX_BOARD_STROKES, |
| 641 | max_boards_per_creator: MAX_BOARDS_PER_CREATOR, |
| 642 | stroke_kinds: BOARD_STROKE_KINDS.to_vec(), |
| 643 | ws_tick_secs: BOARD_WS_TICK_SECS, |
| 644 | ws_max_board_id_len: MAX_BOARD_ID_LEN, |
| 645 | }, |
| 646 | settings: SettingsLimits { |
| 647 | max_list_len: MAX_SETTINGS_LIST_LEN, |
| 648 | max_item_len: MAX_SETTINGS_ITEM_LEN, |
| 649 | min_exam_kind_weight: MIN_EXAM_KIND_WEIGHT, |
| 650 | max_exam_kind_weight: MAX_EXAM_KIND_WEIGHT, |
| 651 | max_grade_bands: MAX_GRADE_BANDS, |
| 652 | max_grade_label_len: MAX_GRADE_LABEL_LEN, |
| 653 | required_attendance_statuses: DEFAULT_ATTENDANCE_STATUSES.to_vec(), |
| 654 | }, |
| 655 | rate: RateLimits { |
| 656 | window_secs: 60, |
| 657 | auth_per_minute: st.rate_limit.auth_per_minute, |
| 658 | api_per_minute: st.rate_limit.api_per_minute, |
| 659 | chatbot_per_minute: st.chatbot_limit.max_per_window(), |
| 660 | }, |
| 661 | request: RequestLimits { |
| 662 | max_page_limit: MAX_PAGE_LIMIT, |
| 663 | schedule_past_grace_ms: SCHEDULE_PAST_GRACE_MS, |
| 664 | request_timeout_secs: REQUEST_TIMEOUT_SECS, |
| 665 | max_request_id_len: MAX_REQUEST_ID_LEN, |
| 666 | }, |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | /// Every fixed validation bound the API enforces. Unauthenticated: the |
| 672 | /// registration and login forms need the username and password bounds before a |
| 673 | /// session exists, and none of these values are secrets — they are the same |
| 674 | /// rules a 400 would spell out. |
| 675 | /// |
| 676 | /// The values are compile-time constants, so the response only ever changes |
| 677 | /// with a deploy — cache it for the session rather than re-fetching per form. |
| 678 | /// School-adjustable policy (exam kinds, attendance statuses, grade bands, the |
| 679 | /// live `max_file_bytes` and chatbot knobs) is on `GET /settings` instead; what |
| 680 | /// appears here for those is the fixed range a manager may set them within. |
| 681 | #[utoipa::path( |
| 682 | get, |
| 683 | path = "/limits", |
| 684 | tag = "meta", |
| 685 | responses((status = 200, description = "Every fixed validation bound", body = LimitsResponse)), |
| 686 | )] |
| 687 | async fn get_limits(State(st): State<AppState>) -> Json<LimitsResponse> { |
| 688 | Json(LimitsResponse::new(&st)) |
| 689 | } |