AladiaDocs

Substitutions

Temporary teacher substitutions inside: data model, resolution rule, permissions, propagation, routes, tests and open items.

User-facing behaviour is in the help page Substitutions. This page is for the team. The source of truth is the code; the comments at the top of the files below say the same in Italian.

WhereWhat
libs/common/src/common/responsibles/responsibles.tsthe responsibles rule, activeGradingSubstitutions, coveredBySubstitution (the one scope of a substitution, used by the rule, the To-grade queue, the guard and the preview/create counts)
libs/common/src/common/responsibles/substitutions.tspure functions: period checks, eventsToSubstitute, notices plan, substituteMay, substituteCanGrade
apps/gateway/.../responsibles/substitutions.service.tspreview, create, edit, cancel, list, badges, access checks
apps/gateway/.../responsibles/substitute-access.guard.tsSubstituteOrAbilityGuard
apps/calendar/src/app/event-substitutions/rows, candidate events, fork carry (followFork)
apps/education/src/app/responsibles/teacher-succession.service.tsgrading preview (pending submissions, exams due)

Data model

Collection event_substitutions (calendar), one row per event and per course:

FieldMeaning
groupIdthe substitution: all rows created together share it; edit, cancel and the list work by group
eventId, courseId, calendarId, lectureIdthe event and, for a lesson, that course's calendar and lecture. A lesson shared by several courses (one Event in several course calendars) has one row per course
eventStart, eventEndthe event times (kept in sync when the event moves)
substituteId, originalIdsubstitute and usual teacher (titolare)
subjectId, levelIdthe scope: subject page (levelId empty) or level page
from, tothe period: start of the first day, end of the last day
includeGrading"Also hand over exam grading". Default false: rows created before the field read as false, no migration
notifyStudents, reasonnotices; the reason is private (never to students, chat, badges)
addedMemberthe substitute was added to the event by this substitution (removed on cancel, never the usual teacher)
statusactive or cancelled (rows stay as history)

Indexes: { eventId, status }, { subjectId, levelId, status, to }, { substituteId, status, to }. Nothing is copied onto submissions: grading is resolved on the spot.

Resolution rule

resolveResponsibles(target, directory):

  1. substitution layer
    • an event: active rows of that event whose period contains the event start;
    • a document to grade (no event, gradingAt = now): groups with includeGrading, whose period contains now and whose scope matches the document (inSubstitutionScope: from the subject any level of the subject, from the level that level). A document without subjects takes its lesson's subject;
    • in both cases the substitute replaces the usual teacher only if the usual teacher is responsible by the rule without substitutions, and the usual teacher stays in covered ("Covered by …");
  2. level teachers, if the level has any;
  3. subject teachers;
  4. course teachers;
  5. event manager.

The substitution follows the person: from the subject page the candidate events are all events of the subject at any level (eventsInPeriod), and eventsToSubstitute keeps those where the usual teacher is responsible without substitutions. A level with a different teacher drops out by itself; a level without teachers inherits from the subject. The grading preview (TeacherSuccessionService.preview with period) and the courses where the substitute may grade (personScopeCourseIds: subject courses plus its levels' courses) use the same rule.

Permissions

substituteMay(capability, substitution) and SubstituteOrAbilityGuard(ability, capability): the usual ability on the resource, or an active substitution.

CapabilityGranted whenRoutes
room-hostevent membership with the usual teacher's rolethe lesson room
attendanceactive row on the lectures in the request, period not overPATCH /courses/:courseId/attendances
lesson-materialssameGET /courses/:courseId/chapters/:chapterId/lectures/:id
gradingincludeGrading, period running, submission still submitted, and the rule resolves it to the substitute now (substituteCanGrade)PATCH /exams-in-courses/:courseId/attempts/:attemptId, GET …/session/review, PATCH …/session/grade, GET …/session/proctoring

Everything else (course management, other submissions, the course-wide assessments view) stays refused. In To grade the substitute opens the single-submission review (SessionReviewDialog), never the course-wide dialog.

Propagation and forks

  • Create: one row per (event, course); the substitute is added once per event with the usual teacher's role, members preview included.
  • Cancel: future rows → cancelled and the substitute removed where the substitution added them; past rows keep their history with to = now.
  • Edit: only "Also hand over exam grading" changed → includeGrading updated on the active rows (UPDATE_SUBSTITUTIONS); anything else → the group's rows are cancelled and recreated.
  • Fork (EventSubstitutionsCarryService.followFork): "This calendar only", a course removed from sharing or a draft fork create a new Event; the active rows follow it, one per course of the new event (courseTargetsOf).
  • Moves (refreshDates, refreshSeriesDates): eventStart/eventEnd follow the event; a lesson moved out of the period leaves the substitution.
  • End of the period: nothing runs; rows only apply inside their period.

Notices

TeacherSubstitutionChangedDto (queue subjects.teacher-substitution-changed):

  • notification: substitute (substitution-assigned), usual teacher (substitution-covered), on cancel both (substitution-cancelled), a substitute replaced in an edit (previousSubstitute → substitution-cancelled); withGrading placeholder only for these;
  • students (lessons-substituted): one per student across covered courses (planSubstitutionNotices), never withGrading, never the reason. They are personal notifications sent by the academy: in the academy context the bell shows them together with the academy's own (inboxFilter in the notification service); Students and Viewers of the academy see only these personal ones, never the academy-addressed admin notifications (onlyPersonalNotificationsFor, checked at every request);
  • chat: one system message per covered course channel, never grading;
  • activity log: metadata.includeGrading, entity name with (+ correzioni).

API

RoutePurpose
GET …/members/replace-preview?outgoingUserId&mode=temporary&from&to[&groupId]lessons, courses, alreadyCovered, grading { pending, dueExams }
POST …/members/replace { mode: 'temporary', outgoingUserId, incomingUserId, from, to, notifyStudents, reason?, includeGrading? }create
GET …/members/substitutionscurrent and scheduled groups (includeGrading for the "+ grading" chip)
PATCH …/members/substitutions/:groupIdedit (also includeGrading alone)
DELETE …/members/substitutions/:groupIdcancel from now
POST /calendars/events/substitutionsbadges of events or lectures
GET /exams-in-courses/grading-queue?responsible=To grade, with substitution on covered rows
GET /exams-in-courses/minethe student's assessments, graders with who graded by hand

… is /subjects-areas/:areaId/subjects/:subjectId (subject page) or /subjects-areas/:areaId/subjects/:subjectId/levels/:levelId (level page).

Tests

Unit (backend/tests/unit/responsibles/, npx jest -c jest.unit.config.cjs tests/unit/responsibles):

  • substitutions.spec.ts: rule, period, events, notices, create, edit of grading only;
  • substitution-grading.spec.ts: grading rule with an injected clock (before / during / after) for events, submissions and the guard, To grade queue, student feed;
  • substitution-convergence.spec.ts: a lesson shared by 3 courses, replaced substitute, student push texts;
  • substitution-person.spec.ts: the substitution follows the person (subject teacher also level teacher, level with inherited teacher, level with another teacher, from the level page).

End to end on Accademia Leonardo (web-next/e2e/help/flows/home/):

  • temporary-substitution.spec.mjs: the dialog on the next day with lessons, the grading checkbox, 375px light and dark;
  • substitution-intensive.spec.mjs: events and submissions across all converging courses before / during / after cancel, permission probes (read-only), student side (one notice, no grading or reason, grader name, no 403), expiry step. SUBSTITUTION_FROM=subject|level (default subject).

Seeds and scripts (scripts/e2e/, Leonardo only, backups in _bak_202610_conv_*):

  1. PHASE=plan|apply|cleanup node scripts/e2e/seed-convergence-events.mjs: converging lessons in a third course through the app's routes;
  2. bash scripts/e2e/mongosh.sh scripts/e2e/seed-convergence-demo.js PHASE=plan|apply|cleanup (on the server): one exam per course with pending submissions, plus an Italiano exam without level;
  3. node web-next/e2e/help/flows/run.mjs home/substitution-intensive [--shots];
  4. SUBSTITUTION_KEEP_GROUP=1 node web-next/e2e/help/flows/run.mjs home/substitution-intensive (prints the group id);
  5. bash scripts/e2e/mongosh.sh scripts/e2e/substitution-expire.js GROUP_ID=<id> PHASE=plan|apply (on the server);
  6. SUBSTITUTION_EXPIRE_STEP=1 node web-next/e2e/help/flows/run.mjs home/substitution-intensive (checks and cancels);
  7. cleanup: step 1 and 2 with PHASE=cleanup. Never substitution-expire.js PHASE=restore after a cancel: it would reactivate cancelled rows.

Open items

  • G7: lessons created after the substitution (series extended, course added to sharing) are not covered; editing the days or the substitute recomputes.
  • Calendars of cycle 2+ are rebuilt at publish without substitutions.
  • Substitutions created before e219fc6396 on a lesson shared by several courses have a row for the first course only: cancel and recreate.
  • Badges (POST /calendars/events/substitutions) do not check that the caller can see the event (names only, never the reason).

See also docs/CALENDAR_PROPAGATION_MAP.md §9–10 in the repository.

On this page