From 84b618a6fd7b7e954d6450e458c908326c91d160 Mon Sep 17 00:00:00 2001 From: RBurcia Date: Mon, 16 Nov 2026 10:24:48 -0800 Subject: [PATCH] Let students send requests and stop mid-semester drops Students can send a request (drop a course, schedule a meeting, other) to their major advisor, an instructor, or the registrar's office. It is saved as an append-only note on their own record, labeled as a student request. Closes #114. After the add/drop deadline a student can no longer drop a course on their own, since it cannot be added back: the drop button opens a drop request to their advisor instead, and the server refuses a student's late drop. The registrar or an administrator drops it from the Student Record once it is approved. Closes #115. Co-Authored-By: Claude Opus 5.5 --- api/_lib/permissions.test.ts | 12 ++++- api/_lib/permissions.ts | 1 + src/components/RequestPanel.tsx | 78 +++++++++++++++++++++++++++++++++ src/components/help.ts | 4 +- src/data/store.tsx | 24 +++++++++- src/lib/requests.test.ts | 48 ++++++++++++++++++++ src/lib/requests.ts | 60 +++++++++++++++++++++++++ src/lib/schedule.ts | 5 +++ src/screens/Dashboard.tsx | 22 ++++++++-- src/screens/StudentRecord.tsx | 27 +++++++++--- 10 files changed, 267 insertions(+), 14 deletions(-) create mode 100644 src/components/RequestPanel.tsx create mode 100644 src/lib/requests.test.ts create mode 100644 src/lib/requests.ts diff --git a/api/_lib/permissions.test.ts b/api/_lib/permissions.test.ts index 2128f2c..503cf8d 100644 --- a/api/_lib/permissions.test.ts +++ b/api/_lib/permissions.test.ts @@ -47,7 +47,7 @@ describe('object-based security', () => { expect(check(MARIA, { ...db, transactions: db.transactions.slice(1) }).ok).toBe(false); }); - it('refuses a student registering after the deadline, but not a drop or a staff registration', () => { + it('refuses a student registering or dropping after the deadline, but not the registrar', () => { const open = db.offerings.find((o) => !db.registrations.some((r) => r.studentId === MARIA && r.scheduleNo === o.scheduleNo))!; const late = '2026-10-28'; const closed = { ...db, registrationCloses: '2026-09-26' }; @@ -55,7 +55,15 @@ describe('object-based security', () => { expect(checkObjectPermissions(email(MARIA), closed, add, [], late).ok).toBe(false); expect(checkObjectPermissions(email(ROSA), closed, add, [], late)).toEqual({ ok: true }); const mine = db.registrations.find((r) => r.studentId === MARIA && !r.grade)!; - expect(checkObjectPermissions(email(MARIA), closed, { ...closed, registrations: closed.registrations.filter((r) => r !== mine) }, [], late)).toEqual({ ok: true }); + const dropped = { ...closed, registrations: closed.registrations.filter((r) => r !== mine) }; + expect(checkObjectPermissions(email(MARIA), closed, dropped, [], late).ok).toBe(false); + expect(checkObjectPermissions(email(ADMIN), closed, dropped, [], late)).toEqual({ ok: true }); + expect(checkObjectPermissions(email(MARIA), closed, dropped, [], '2026-09-26')).toEqual({ ok: true }); // the deadline day itself is still open + }); + + it('lets a student send a request to their own record only, stamped with their own ID', () => { + expect(check(MARIA, addNote(MARIA, MARIA))).toEqual({ ok: true }); + expect(check(MARIA, addNote(TOMAS, MARIA)).ok).toBe(false); }); it('lets a student register and drop only for themself', () => { diff --git a/api/_lib/permissions.ts b/api/_lib/permissions.ts index 5ed3e05..069f1de 100644 --- a/api/_lib/permissions.ts +++ b/api/_lib/permissions.ts @@ -128,6 +128,7 @@ function refusal(c: Change, { user: me, isNew }: Actor, before: Db, after: Db, t } if (GRADE_COLS.some((k) => (c.before ?? c.after)![k] != null) && !canGrade) return 'A graded registration can be changed only by the instructor or a user with grade update privileges.'; if (!c.before && !staff && before.registrationCloses && today > before.registrationCloses) return `Registration for ${before.term} closed on ${before.registrationCloses}. Ask the registrar to register you.`; + if (!c.after && !staff && before.registrationCloses && today > before.registrationCloses) return `The add/drop deadline for ${before.term} passed on ${before.registrationCloses}. Send a drop request to your advisor; the registrar drops the course once it is approved.`; return ownStudent || (staff && has('REG')) ? null : 'You can register or drop courses only for yourself.'; } diff --git a/src/components/RequestPanel.tsx b/src/components/RequestPanel.tsx new file mode 100644 index 0000000..7c114ff --- /dev/null +++ b/src/components/RequestPanel.tsx @@ -0,0 +1,78 @@ +import { useState } from 'react'; +import { useStore } from '../data/store'; +import type { Student } from '../data/types'; +import { useToast } from './Shell'; +import { Banner, FieldError } from './ui'; +import { X } from './icons'; +import { useEscapeToCancel } from './draft'; +import { courseOf, currentRegistrations, offeringOf } from '../lib/rules'; +import { formatDate } from '../lib/format'; +import { MESSAGE_MAX, REQUEST_KINDS, requestRecipients, type RequestField, type RequestKind, type StudentRequest } from '../lib/requests'; + +/** + * Side panel where a student sends a request to their major advisor, an instructor or the registrar. + * `dropAfterDeadline` opens it in place of dropping once the add/drop deadline has passed, so the + * student talks to someone before losing a course they cannot add back. + */ +export function RequestPanel({ student, initial, dropAfterDeadline = false, onClose }: { student: Student; initial?: Partial; dropAfterDeadline?: boolean; onClose: () => void }) { + const { db, sendRequest } = useStore(); + const toast = useToast(); + const recipients = requestRecipients(db, student); + const courses = currentRegistrations(db, student.id).map((r) => offeringOf(db, r.scheduleNo)?.courseId).filter((c): c is string => !!c); + const [req, setReq] = useState({ to: recipients[0]?.id ?? '', kind: 'meeting', courseId: '', message: '', ...initial }); + const [err, setErr] = useState<{ field: RequestField; reason: string; requirement: string } | null>(null); + useEscapeToCancel(true, onClose); + + const set = (change: Partial) => { setReq((r) => ({ ...r, ...change })); setErr(null); }; + const error = (f: RequestField) => (err?.field === f ? : null); + + function send() { + const r = sendRequest(student.id, req); + if (!r.ok) return setErr(r); + toast(`Request sent to ${recipients.find((x) => x.id === req.to)?.name ?? 'staff'} · added to your student record`); + onClose(); + } + + return ( +