forge
Explore
Log in

Don't you dare go Hollow

📐 own the stale-write 409 on all four surfaces

Browse files at this commit

646ec10b238698a3d3a6c1376fec4611ce61bd81Ahmet Kaan GümüşParent: 1bd7851
  • docs
    • 📐 own the stale-write 409 on all four surfaces
Show full message
docs: 📐 own the stale-write 409 on all four surfaces
README.mdmodified+4 -4
@@ -696,7 +696,7 @@ window filtering, before paging; negative values are a `400` naming the field.
696 | GET | `/courses` | student | The caller's visible courses: created + enrolled (manager+: all) · paged |696 | GET | `/courses` | student | The caller's visible courses: created + enrolled (manager+: all) · paged |
697 | GET | `/courses/me` | student | The caller's **enrolled** courses · paged |697 | GET | `/courses/me` | student | The caller's **enrolled** courses · paged |
698 | GET | `/courses/{id}` | student | Get course (enrolled, creator, assigned teacher, or manager+) |698 | GET | `/courses/{id}` | student | Get course (enrolled, creator, assigned teacher, or manager+) |
699-| PATCH | `/courses/{id}` | teacher | Edit course incl. `kind` and `capacity` (`null` lifts the cap) (course manager) |699+| PATCH | `/courses/{id}` | teacher | Edit course incl. `kind` and `capacity` (`null` lifts the cap) (course manager; `409` if the `term_id` it moves off changed since the read — nothing written, re-read and retry) |
700 | DELETE | `/courses/{id}` | teacher | Delete course + its exams, results, subjects, sessions, and homework (submissions, files, and grades included) (creator, or manager+ — **not** an assigned teacher; `409` while anyone is still enrolled) |700 | DELETE | `/courses/{id}` | teacher | Delete course + its exams, results, subjects, sessions, and homework (submissions, files, and grades included) (creator, or manager+ — **not** an assigned teacher; `409` while anyone is still enrolled) |
701 | POST | `/courses/{id}/teachers` | manager | `{user_id}` — assign a **teacher+** to run the course (idempotent; returns the course) |701 | POST | `/courses/{id}/teachers` | manager | `{user_id}` — assign a **teacher+** to run the course (idempotent; returns the course) |
702 | DELETE | `/courses/{id}/teachers/{user}` | manager | Unassign a teacher (`404` if they weren't assigned) |702 | DELETE | `/courses/{id}/teachers/{user}` | manager | Unassign a teacher (`404` if they weren't assigned) |
@@ -706,7 +706,7 @@ window filtering, before paging; negative values are a `400` naming the field.
706 | POST | `/classes` | manager | `{name, grade?, term_id?}` — create a class (şube); `grade` is a free-text year label |706 | POST | `/classes` | manager | `{name, grade?, term_id?}` — create a class (şube); `grade` is a free-text year label |
707 | GET | `/classes` | teacher | List classes, newest first · paged |707 | GET | `/classes` | teacher | List classes, newest first · paged |
708 | GET | `/classes/{id}` | teacher | Get one class |708 | GET | `/classes/{id}` | teacher | Get one class |
709-| PATCH | `/classes/{id}` | manager | Edit a class (`null` clears `grade`/`term_id`) |709+| PATCH | `/classes/{id}` | manager | Edit a class (`null` clears `grade`/`term_id`; `409` if the `term_id` it moves off changed since the read — nothing written, re-read and retry) |
710 | DELETE | `/classes/{id}` | manager | Delete a class — `409` while it still holds students or courses |710 | DELETE | `/classes/{id}` | manager | Delete a class — `409` while it still holds students or courses |
711 | POST | `/classes/{id}/members` | manager | `{user_id}` — add a **student**; enrolls them into every attached course (`409` if one is full, naming it, or if already a member) |711 | POST | `/classes/{id}/members` | manager | `{user_id}` — add a **student**; enrolls them into every attached course (`409` if one is full, naming it, or if already a member) |
712 | GET | `/classes/{id}/members` | teacher | List the class roster · paged |712 | GET | `/classes/{id}/members` | teacher | List the class roster · paged |
@@ -743,7 +743,7 @@ window filtering, before paging; negative values are a `400` naming the field.
743 | POST | `/exams/{id}/attempt/finish` | student | Submit the attempt (`409` once the deadline passed); allowed even while locked out of the room |743 | POST | `/exams/{id}/attempt/finish` | student | Submit the attempt (`409` once the deadline passed); allowed even while locked out of the room |
744 | POST | `/exams/{id}/questions` | teacher | `{subject_id, text, kind, points, choices?, correct?}` — add a question tagged with one of the course's subjects (course manager; frozen once attempted) |744 | POST | `/exams/{id}/questions` | teacher | `{subject_id, text, kind, points, choices?, correct?}` — add a question tagged with one of the course's subjects (course manager; frozen once attempted) |
745 | GET | `/exams/{id}/questions` | teacher | The full question list, `correct` included (course manager) · paged |745 | GET | `/exams/{id}/questions` | teacher | The full question list, `correct` included (course manager) · paged |
746-| PATCH | `/exams/{id}/questions/{qid}` | teacher | Edit a question — the kind bundle revalidates as a unit (course manager; frozen once attempted) |746+| PATCH | `/exams/{id}/questions/{qid}` | teacher | Edit a question — the kind bundle revalidates as a unit (course manager; frozen once attempted; an omitted `subject_id` is filled from the stored row, so *any* edit is a `409` if someone re-tagged the question since the read — nothing written, re-read and retry) |
747 | DELETE | `/exams/{id}/questions/{qid}` | teacher | Delete a question + its answers (course manager; frozen once attempted) |747 | DELETE | `/exams/{id}/questions/{qid}` | teacher | Delete a question + its answers (course manager; frozen once attempted) |
748 | POST | `/exams/{id}/questions/from-bank/{bid}` | teacher | Instantiate a **bank question** into this exam — copies it to a fresh exam-scoped question (new id, own images + answers; records the template in `source_bank`); body `{subject_id}` retags it against the course's subjects (`400` cross-course; course manager; `409` once attempted) |748 | POST | `/exams/{id}/questions/from-bank/{bid}` | teacher | Instantiate a **bank question** into this exam — copies it to a fresh exam-scoped question (new id, own images + answers; records the template in `source_bank`); body `{subject_id}` retags it against the course's subjects (`400` cross-course; course manager; `409` once attempted) |
749 | POST | `/exams/{id}/questions/{qid}/to-bank` | teacher | Save an existing exam question into the school **question bank** — copies it to a detached bank row (new id, own images; records the origin exam in `source_exam`); the source question is untouched (course manager) |749 | POST | `/exams/{id}/questions/{qid}/to-bank` | teacher | Save an existing exam question into the school **question bank** — copies it to a detached bank row (new id, own images; records the origin exam in `source_exam`); the source question is untouched (course manager) |
@@ -786,7 +786,7 @@ window filtering, before paging; negative values are a `400` naming the field.
786 | GET | `/courses/{id}/homework` | student | List the course's homework, newest first (enrolled, creator, assigned teacher, or manager+; students see only what they're assigned) · paged |786 | GET | `/courses/{id}/homework` | student | List the course's homework, newest first (enrolled, creator, assigned teacher, or manager+; students see only what they're assigned) · paged |
787 | GET | `/homework` | student | The caller's cross-course homework: their courses' (manager+: all; students only what they're assigned) · paged |787 | GET | `/homework` | student | The caller's cross-course homework: their courses' (manager+: all; students only what they're assigned) · paged |
788 | GET | `/homework/{id}` | student | Get homework (course viewers; a subset homework is a `404` to students it doesn't name) |788 | GET | `/homework/{id}` | student | Get homework (course viewers; a subset homework is a `404` to students it doesn't name) |
789-| PATCH | `/homework/{id}` | teacher | Edit title/description/`due_at`/`subject_id`/`assigned` (course manager; a newly set due date is re-checked; `409` if narrowing `assigned` would strand an existing submission or grade — the blockers are named) |789+| PATCH | `/homework/{id}` | teacher | Edit title/description/`due_at`/`subject_id`/`assigned` (course manager; a newly set due date is re-checked; `409` if narrowing `assigned` would strand an existing submission or grade — the blockers are named — or if the `subject_id` it re-tags from changed since the read: nothing written, re-read and retry) |
790 | DELETE | `/homework/{id}` | teacher | Delete homework + its submissions, files, and grades — file blobs included (course manager) |790 | DELETE | `/homework/{id}` | teacher | Delete homework + its submissions, files, and grades — file blobs included (course manager) |
791 | POST | `/homework/{id}/submission` | student | `{text?}` — hand in / re-edit own work (**students only**, enrolled, assigned): text replaces whole (omit clears), `submitted_at` pins the first hand-in, `updated_at` moves; `409` once graded |791 | POST | `/homework/{id}/submission` | student | `{text?}` — hand in / re-edit own work (**students only**, enrolled, assigned): text replaces whole (omit clears), `submitted_at` pins the first hand-in, `updated_at` moves; `409` once graded |
792 | GET | `/homework/{id}/submission` | student | Own submission: text, both stamps, computed `late`, files, grade-if-any (`404` until submitted) |792 | GET | `/homework/{id}/submission` | student | Own submission: text, both stamps, computed `late`, files, grade-if-any (`404` until submitted) |
src/web/classes.rsmodified+1 -0
@@ -281,6 +281,7 @@ async fn get_class(
281 (status = 401, description = "Not authenticated", body = ErrorResponse),281 (status = 401, description = "Not authenticated", body = ErrorResponse),
282 (status = 403, description = "Requires manager role or higher", body = ErrorResponse),282 (status = 403, description = "Requires manager role or higher", body = ErrorResponse),
283 (status = 404, description = "Not found", body = ErrorResponse),283 (status = 404, description = "Not found", body = ErrorResponse),
284+ (status = 409, description = "The term this update moves the class off changed since the caller read it — nothing was written, re-read and retry", body = ErrorResponse),
284 ),285 ),
285 )]286 )]
286 async fn update_class(287 async fn update_class(
src/web/courses.rsmodified+1 -0
@@ -409,6 +409,7 @@ async fn get_course(
409 (status = 401, description = "Not authenticated", body = ErrorResponse),409 (status = 401, description = "Not authenticated", body = ErrorResponse),
410 (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse),410 (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse),
411 (status = 404, description = "Not found", body = ErrorResponse),411 (status = 404, description = "Not found", body = ErrorResponse),
412+ (status = 409, description = "The term this update moves the course off changed since the caller read it — nothing was written, re-read and retry", body = ErrorResponse),
412 ),413 ),
413 )]414 )]
414 async fn update_course(415 async fn update_course(
src/web/exams/questions.rsmodified+4 -2
@@ -310,7 +310,9 @@ pub(crate) async fn question_page(
310 /// course. Omitted fields keep their value; `kind`/`choices`/`correct` are310 /// course. Omitted fields keep their value; `kind`/`choices`/`correct` are
311 /// re-validated as a unit, so a kind switch must bring the matching fields311 /// re-validated as a unit, so a kind switch must bring the matching fields
312 /// along. `subject_id` re-tags within the course's subjects. Locked once312 /// along. `subject_id` re-tags within the course's subjects. Locked once
313-/// attempts exist.313+/// attempts exist. An omitted `subject_id` is filled from the stored row, so
314+/// any edit here — not just a re-tag — is refused with a `409` when someone
315+/// else moved the question's subject after the caller read it.
314 #[utoipa::path(316 #[utoipa::path(
315 patch,317 patch,
316 path = "/{id}/questions/{qid}",318 path = "/{id}/questions/{qid}",
@@ -327,7 +329,7 @@ pub(crate) async fn question_page(
327 (status = 401, description = "Not authenticated", body = ErrorResponse),329 (status = 401, description = "Not authenticated", body = ErrorResponse),
328 (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse),330 (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse),
329 (status = 404, description = "No such exam, or no such question in it", body = ErrorResponse),331 (status = 404, description = "No such exam, or no such question in it", body = ErrorResponse),
330- (status = 409, description = "Attempts have started — questions are frozen", body = ErrorResponse),332+ (status = 409, description = "Attempts have started — questions are frozen, or the subject the question was read on changed since — nothing was written, re-read and retry", body = ErrorResponse),
331 ),333 ),
332 )]334 )]
333 pub(crate) async fn update_question(335 pub(crate) async fn update_question(
src/web/homework.rsmodified+1 -1
@@ -300,7 +300,7 @@ struct UpdateHomework {
300 (status = 401, description = "Not authenticated", body = ErrorResponse),300 (status = 401, description = "Not authenticated", body = ErrorResponse),
301 (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse),301 (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse),
302 (status = 404, description = "Not found", body = ErrorResponse),302 (status = 404, description = "Not found", body = ErrorResponse),
303- (status = 409, description = "Narrowing the assigned list would orphan an existing submission or result", body = ErrorResponse),303+ (status = 409, description = "Narrowing the assigned list would orphan an existing submission or result, or the subject this update re-tags from changed since the caller read it — nothing was written, re-read and retry", body = ErrorResponse),
304 ),304 ),
305 )]305 )]
306 async fn update_homework(306 async fn update_homework(