hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | //! Course workflows: the catalog's CRUD — the template a class section |
| 2 | //! attaches, with no term, capacity or teacher list of its own any more |
| 3 | //! (D1/D5/D6: staffing and roster live on the instances, |
| 4 | //! [`crate::service::class_course`]) — the two gates over a catalog row every |
| 5 | //! caller of those routes shares ([`can_manage_course`], [`can_view_course`]), |
| 6 | //! and the delete that collects the image/homework/note-file blob keys before |
| 7 | //! the guarded cascade sweeps those rows. The queries live in |
| 8 | //! [`crate::db::course`]. |
| 9 | |
| 10 | use crateDatabase; |
| 11 | use cratecourse; |
| 12 | use crate; |
| 13 | use crateRole; |
| 14 | use crate; |
| 15 | use crateAppError; |
| 16 | |
| 17 | /// Mint a catalog course. The catalog is not bound to a term (D1): exams are, |
| 18 | /// through their instance, and no capacity is stored — the roster counter |
| 19 | /// lives on the instance and gates nothing. |
| 20 | pub async |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | pub async |
| 31 | |
| 32 | |
| 33 | |
| 34 | /// The catalog the visible list's manager arm serves, optionally narrowed by |
| 35 | /// the `GET /courses` filters (`kind`, folded `q`) — pushed into the SQL so |
| 36 | /// listing one kind is not a full-catalog pull. |
| 37 | pub async |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | pub async |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | pub async |
| 56 | |
| 57 | |
| 58 | |
| 59 | pub async |
| 60 | |
| 61 | |
| 62 | |
| 63 | /// Who may write the **catalog** row (edit it, delete it, write its |
| 64 | /// subjects): its creator, or anyone `manager` and above — and in every case |
| 65 | /// only while the caller is *still* `teacher` or above. |
| 66 | /// |
| 67 | /// The `teacher` floor is enforced here rather than left to the callers: half |
| 68 | /// of them extract `CurrentUser`, not `RequireTeacher`, so a creator demoted |
| 69 | /// to `student` or `parent` would otherwise keep catalog rights forever (the |
| 70 | /// `creator` column is a historical fact and is never swept). |
| 71 | /// |
| 72 | /// The teacher *assignment* list is gone from this row (D6): who teaches is |
| 73 | /// per instance now, and being assigned to one grants rights inside it — via |
| 74 | /// [`super::instance::can_manage_instance`] — never over the catalog. |
| 75 | /// |
| 76 | /// It lives here, not in the web layer, because the gates over a catalog row |
| 77 | /// are a service rule the RAG surfaces read too ([`super::rag_scope`] scopes |
| 78 | /// what a course note's own reader may ask about). |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | /// Who may read a catalog course (its details, its curriculum subjects): |
| 85 | /// anyone who can manage it, a teacher assigned to one of its **instances**, |
| 86 | /// and anyone the course reaches — a student enrolled in any of its instances, |
| 87 | /// or a member of the course itself. Other teachers and unenrolled students see |
| 88 | /// nothing. |
| 89 | /// |
| 90 | /// The assigned-teacher arm is what keeps the catalog honest about the |
| 91 | /// instance layer: those teachers author homework and exam questions *inside* |
| 92 | /// the instance (D10 lets them), and every one of those routes needs a |
| 93 | /// `subject_id` belonging to this very course — so a `403` here would hand them |
| 94 | /// a picker they cannot fill. At HEAD the assignment list lived on the catalog |
| 95 | /// row and the arm came for free; after D6 it is read through the instances |
| 96 | /// they teach ([`list_for_teacher`]). |
| 97 | pub async |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | /// Only what the request carried is written: an omitted field (`None`) is |
| 117 | /// not stored at all, so a concurrent PATCH of that field survives. |
| 118 | pub async |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | /// What [`delete`] did: whether the course went, and the blob keys of the |
| 129 | /// rows its cascade removed — exactly whose files the web layer may unlink. |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | /// Delete the course: collect the image/homework/note-file blob keys, then |
| 142 | /// run the cascading delete — which takes every instance the catalog is taught |
| 143 | /// in (with everything under them), every individual membership and every |
| 144 | /// teacher link, all in one guarded transaction. |
| 145 | /// |
| 146 | /// The old writer leases on the exam-attempt and homework state are gone |
| 147 | /// with the store that needed them: this cascade is one guarded |
| 148 | /// transaction whose retry answers a child write that raced it mid-sweep |
| 149 | /// (`is_retryable_cascade` — a foreign key naming a row the racing write |
| 150 | /// just landed), so an attempt started or a grade written beside the sweep |
| 151 | /// is either swept by the re-sent cascade or refused by the very foreign |
| 152 | /// key it would have orphaned. No lock can out-guard that. |
| 153 | /// |
| 154 | /// The keys are read before the delete because it takes their rows with it; |
| 155 | /// a refused delete just drops them unused. Unlinking the blobs stays the |
| 156 | /// web layer's job — a crash in between strands at worst an unreachable |
| 157 | /// blob. |
| 158 | pub async |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 |