hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | //! Homework workflows: the cascading delete and the shared student-side wall |
| 2 | //! ([`gate_own_submission`]) every submission path walks. Row reads and |
| 3 | //! listings pass through to [`crate::db::homework`]; the submission, file, |
| 4 | //! and grade workflows live in the sibling `service::homework_*` modules. |
| 5 | //! |
| 6 | //! There is no homework subsystem lock any more: the writes that used to |
| 7 | //! serialize on one — the PATCH's orphan guard, the delete cascade, grading, |
| 8 | //! and every student-side write — now contend on the *homework row itself* |
| 9 | //! (`SELECT … FOR UPDATE` inside each transaction), so the ordering they |
| 10 | //! need survives a multi-process deployment. See |
| 11 | //! [`crate::db::homework::update`] and |
| 12 | //! [`crate::db::homework_result::grade`]. |
| 13 | |
| 14 | use crateDatabase; |
| 15 | use cratehomework; |
| 16 | use crateClassCourseId; |
| 17 | use crate; |
| 18 | use crateRole; |
| 19 | use crateSubjectId; |
| 20 | use crateTimestamp; |
| 21 | use crate; |
| 22 | use crateAppError; |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | pub async |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | /// The homework row, for callers that only inspect it — the web layer's gates |
| 61 | /// read through here. |
| 62 | pub async |
| 63 | |
| 64 | |
| 65 | |
| 66 | /// The optional predicates of the cross-instance homework reads — the |
| 67 | /// `?due_after=&due_before=&class_course=` scoping of `GET /homework`. |
| 68 | /// Absent fields widen the read; none of them widens the caller's |
| 69 | /// visibility, which the web layer still applies on top. |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | /// Every homework, newest first — the manager+ view, narrowed by `filter` |
| 81 | /// in SQL and paged in the database (a manager retains nothing in Rust, so |
| 82 | /// the window and the count are both the database's). |
| 83 | pub async |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | /// The homework of one class×course instance, newest first — the read behind |
| 101 | /// `GET /instances/{id}/homework`. |
| 102 | pub async |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | /// Every homework of every instance in `instances` (one query) — the read |
| 110 | /// behind a caller's visible courses, narrowed by `filter` in SQL. Unpaged: |
| 111 | /// the caller may still drop rows in Rust (a student's audience), so a |
| 112 | /// window here could only hide rows that trim was about to keep. |
| 113 | pub async |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | /// The homework of one instance that `user` is meant to see — the per-instance |
| 129 | /// block of a homework report. |
| 130 | pub async |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | /// Re-scope (or re-tag, re-title, re-describe, re-schedule) the homework. |
| 139 | /// |
| 140 | /// The audience-narrowing orphan guard and the stale-re-tag refusal are one |
| 141 | /// transaction with the write in [`homework::update`], under the homework |
| 142 | /// row's lock — a submission (which locks the same row before writing) |
| 143 | /// cannot land between the check and the narrowing it would have refused. |
| 144 | pub async |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | /// Delete the homework: run the cascading delete (submissions, their files, |
| 157 | /// results, then the row — one transaction, children first) and return the |
| 158 | /// submission-file blob keys, which the transaction collected before the |
| 159 | /// wipes so no file added mid-delete can strand its blob. The web layer |
| 160 | /// unlinks the blobs once the rows are gone; a crash in between strands at |
| 161 | /// worst an unreachable file. |
| 162 | pub async |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | /// A 403 unless `user` is enrolled in the instance the homework belongs to — |
| 168 | /// the homework twin of the exam sitting wall |
| 169 | /// ([`crate::service::exam_attempt::ensure_enrolled`], which is `Exam`-shaped). |
| 170 | /// Submitting is course content, so leaving the instance closes it; re-checked |
| 171 | /// on every submission and file write, so an unenrollment mid-task bites the |
| 172 | /// next. |
| 173 | async |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | /// Read a homework and clear `user` to act on their own submission to it — the |
| 190 | /// shared wall of the submission, file, and (student side of the) download |
| 191 | /// paths. Three gates, in order: |
| 192 | /// |
| 193 | /// 1. Exact `Student` on the *live* role. Teachers assign homework, they never |
| 194 | /// hand it in; the `RequireStudent` extractor's ≥Student would wave a |
| 195 | /// promoted teacher through, so this checks the role `CurrentUser` read for |
| 196 | /// this very request — the same reasoning as [`crate::service::exam_attempt::ensure_student`]. |
| 197 | /// 2. Current enrollment in the course. |
| 198 | /// 3. The audience check: a student a subset homework does not name gets a 404, |
| 199 | /// never a 403, so a subset assignment never leaks to those left out (the |
| 200 | /// no-leak idiom an unseen exam draft uses). |
| 201 | pub async |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | /// The year wall of the student side: an archived year makes past structure |
| 222 | /// read-only. Deliberately *not* inside [`gate_own_submission`] — that gate |
| 223 | /// also fronts the download read, and an archived year is still browsable. So |
| 224 | /// every student *write* calls this right after the gate, which keeps the |
| 225 | /// order that matters: a student the homework never named is refused by the |
| 226 | /// audience check with a 404 and never learns the homework exists. |
| 227 | /// |
| 228 | /// The gate keys on the homework's instance → its class section → that |
| 229 | /// section's year (D8): a term archived inside an open year does not close |
| 230 | /// homework, the year does. |
| 231 | pub async |
| 232 | |
| 233 | |
| 234 | |
| 235 | /// Bring one user's badge awards up to date after a write moved their counters |
| 236 | /// — the student's after a submission, the grader's after a grade. Never fails |
| 237 | /// the request it follows: a badge is a decoration on top |
| 238 | /// of the work, and losing one to a transient database error is not worth |
| 239 | /// refusing a hand-in over — the next counter move re-runs this and heals it. |
| 240 | pub async |
| 241 | |
| 242 | |
| 243 | |
| 244 |