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