Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b24c857
Update course icons and portal design
YoussefHanyy Nov 27, 2026
c912219
refactor: organize the course editor into tabs
wweater Nov 27, 2026
3cb4a13
Polish advisor and coordinator Portal workflows
AdamMagued Nov 27, 2026
8d8ee03
feat: polish student schedule swaps and shared notification feedback
YoussefHanyy Nov 27, 2026
c56991a
fix: emphasize swap deadlines and verify shared Home notifications
YoussefHanyy Nov 27, 2026
b3006f0
fix: prevent duplicate extra-hours submissions
wweater Nov 27, 2026
e3cab8d
Fix Calendar OAuth return and polish student schedule pages
YoussefHanyy Nov 27, 2026
4a5dbdf
Simplify connected Google Calendar actions
YoussefHanyy Nov 27, 2026
6735c8e
Merge calendar sync redesign into development
wweater Nov 27, 2026
1d44555
Refine Portal staff and student workflows
AdamMagued Nov 27, 2026
b4afc28
Restore Portal navigation and remove submission demo sign-in
AdamMagued Nov 27, 2026
0569c91
Complete standalone assessment seed and sign-in setup
AdamMagued Nov 27, 2026
f03d415
Reconcile main sign-in release with stricter assessment gate
AdamMagued Nov 27, 2026
628fa76
Document populated evaluation workflows
AdamMagued Nov 27, 2026
35919c7
Keep Portal navigation stable while home data loads
AdamMagued Nov 27, 2026
70a30f5
Fix administrator read-only advising overview
AdamMagued Nov 27, 2026
ecfe4b2
Enforce assessed scheduling and payment eligibility
AdamMagued Nov 27, 2026
abd83ea
Explain extra-hours payment eligibility and recovery
AdamMagued Nov 27, 2026
dcd2b1d
Merge main and remove quick sign-in on every host
AdamMagued Nov 27, 2026
3a7d63b
Use clear service errors in the Portal
AdamMagued Nov 27, 2026
7c2a6bb
Make the submission setup guide account-based
AdamMagued Nov 27, 2026
a1ecd1a
Give graduation planner tables room at their edges
AdamMagued Nov 27, 2026
bd1c049
Keep the student directory stable during repeated searches
AdamMagued Nov 27, 2026
5b87f0b
Disable shortcut provisioning in the submission defaults
AdamMagued Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ WEB_ORIGIN=
# Generate once: node -e "console.log(require('node:crypto').randomBytes(32).toString('hex'))"
JWT_SECRET=

# Stripe hosted Checkout. Only sandbox secret keys (sk_test_) are accepted.
# Provider credential for hosted card checkout.
STRIPE_SECRET_KEY=

# Email delivery. Enter the provider settings in your ignored .env file.
Expand All @@ -22,7 +22,7 @@ SMTP_REQUIRE_TLS=true
SMTP_USER=
SMTP_PASS=
SMTP_FROM=
# Probation warnings run in production by default. Enable in development for SMTP testing.
# Probation warnings run automatically in production.
# PROBATION_WARNINGS_ENABLED=true

# Google Calendar OAuth (Req. 116). Create OAuth credentials in Google Cloud.
Expand All @@ -31,6 +31,3 @@ GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT_URI=http://localhost:3000/api/calendar/oauth/callback
CALENDAR_TOKEN_ENCRYPTION_KEY=
UNIVERSITY_TIMEZONE=Africa/Cairo

# Development accounts only; disabled by default and always disabled in production.
ALLOW_DEMO_SEED=true
101 changes: 49 additions & 52 deletions README.md

Large diffs are not rendered by default.

228 changes: 153 additions & 75 deletions apps/api/src/controllers/extra-hours.controller.js

Large diffs are not rendered by default.

51 changes: 40 additions & 11 deletions apps/api/src/controllers/extra-hours.integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
AcademicTerm,
Course,
CourseAttempt,
CourseOffering,
ExtraHoursRequest,
FinancialTransaction,
Notification,
Expand Down Expand Up @@ -125,11 +126,12 @@ before(async () => {
// Course 2: 2 credit hours
// Course 3: 4 credit hours
const [c1, c2, c3] = await Course.create([
{ code: "CSEN501", name: "Databases I", creditHours: 3, courseType: "core", facultyMajors: ["CS"], recommendedSemester: 5, offeringSeasons: ["winter"] },
{ code: "CSEN501", name: "Databases I", creditHours: 3, courseType: "core", facultyMajors: ["CS"], recommendedSemester: 5, offeringSeasons: ["winter", "spring", "summer"] },
{ code: "CSEN502", name: "Networks", creditHours: 2, courseType: "core", facultyMajors: ["CS"], recommendedSemester: 5, offeringSeasons: ["winter"] },
{ code: "CSEN503", name: "Advanced Algorithms", creditHours: 4, courseType: "core", facultyMajors: ["CS"], recommendedSemester: 5, offeringSeasons: ["winter"] },
]);
courses = [c1, c2, c3];
await publishCourse(c1, term);

// Mark Course 1 as attempted/failed previously by regular student so it's a "repeated" course
await CourseAttempt.create({
Expand All @@ -143,6 +145,15 @@ before(async () => {
});
});

function publishCourse(course, term) {
return CourseOffering.create({
course: course._id, term: term._id, isPublished: true,
instructors: [{ fullName: "Test instructor" }], eligibleGroups: [{ major: "CS" }],
slots: [{ componentType: "lecture", groupNumber: "1", day: "Monday",
startMinute: 480, endMinute: 540, room: "Test room", capacity: 20 }],
});
}

after(async () => {
if (server) await new Promise((resolve) => server.close(resolve));
await mongoose.disconnect();
Expand Down Expand Up @@ -267,21 +278,38 @@ test("Req 83: Non-graduating student cannot request more than 3 extra hours", as
test("Req 83: Graduating student can request more than 3 extra hours up to 34 total", async () => {
await ExtraHoursRequest.deleteMany({});

// Semester 5 standard is 30. Adding 4 credits = 34 total.
// Allowed when graduatingWithinOneYear = true.
const day = 86400000;
const start = Date.now() + 30 * day;
const upcoming = await AcademicTerm.create({
code: "REQ83-W", season: "winter", academicYear: "2030/2031", termStart: start, termEnd: start + 70 * day,
teachingStart: start, teachingEnd: start + 65 * day, registrationStart: start - 10 * day, registrationEnd: start,
advisingDeadline: start - day, wholeScheduleSwapDeadline: start - day,
});
await CourseOffering.insertMany(courses.map((course, index) => ({
course: course._id, term: upcoming._id, isPublished: true,
instructors: [{ fullName: "Test instructor" }], eligibleGroups: [{ major: "CS" }],
slots: [{ componentType: "lecture", groupNumber: "1", day: "Monday",
startMinute: 480 + 60 * index, endMinute: 540 + 60 * index, room: "Test room", capacity: 20 }],
})));
const electives = await Course.create(Array.from({ length: 4 }, (_, i) => ({
code: `EL83-${i}`, name: `Completed elective ${i}`, courseType: "elective", creditHours: 4, facultyMajors: ["CS"],
})));
await CourseAttempt.insertMany(electives.map((course) => ({
student: profiles.regular._id, course: course._id, term: term._id, result: "passed", attendance: "attended", grade: "A",
})));
const res = await apiCall("/extra-hours", {
method: "POST",
userRole: "advisor",
body: {
studentId: String(profiles.regular._id),
courseIds: [String(courses[2]._id)], // 4 credits
graduatingWithinOneYear: true,
},
method: "POST", userRole: "advisor",
body: { studentId: String(profiles.regular._id), termId: String(upcoming._id), courseIds: [String(courses[2]._id)] },
});

assert.equal(res.status, 201);
assert.equal(res.status, 201, res.body.message);
assert.equal(res.body.requestedHours, 4);
assert.equal(res.body.eligibilitySnapshot.hoursAfterRequest, 34);
assert.equal(res.body.eligibilitySnapshot.graduatingWithinOneYear, true);
const approved = await apiCall(`/extra-hours/${res.body._id}/decision`, {
method: "POST", userRole: "coordinator", body: { decision: "approved", responseNote: "Verified curriculum fit." },
});
assert.equal(approved.status, 200, approved.body.message);
});

test("Req 83: Probation students cannot receive extra credit hours", async () => {
Expand Down Expand Up @@ -354,6 +382,7 @@ test("Req 117 delivers extra-hours decisions, payment outcomes, deferred charges
const [walletTerm, deferredTerm] = await Promise.all([
alternateTerm("EH-WALLET", "spring"), alternateTerm("EH-DEFERRED", "summer"),
]);
await Promise.all([publishCourse(courses[0], walletTerm), publishCourse(courses[0], deferredTerm)]);
const submit = async (termId) => {
const response = await apiCall("/extra-hours", {
method: "POST",
Expand Down
109 changes: 105 additions & 4 deletions apps/api/src/controllers/group-a.audit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ beforeEach(async () => {
{ code: "ABASE502", name: "Base course", creditHours: 4, courseType: "core", facultyMajors: ["CS"], offeringSeasons: ["winter", "spring", "summer"] },
]);
await Promise.all(courses.map((course, index) => publishFixture(course, index)));
await publishFixture(courses[0], 0, terms[1]);
const electives = await Course.create(Array.from({ length: 4 }, (_, index) => ({ code: `AELEC${index}`, name: "Completed elective", creditHours: 4, courseType: "elective", facultyMajors: ["CS"] })));
await CourseAttempt.insertMany(electives.map((course) => ({ student: student._id, course: course._id, term: past._id, result: "passed", attendance: "attended", grade: "A" })));
});
function publishFixture(course, index = 2) {
function publishFixture(course, index = 2, term = terms[0]) {
const startMinute = 480 + index * 60;
return CourseOffering.create({
course: course._id, term: terms[0]._id, isPublished: true,
course: course._id, term: term._id, isPublished: true,
instructors: [{ fullName: "Fixture Instructor" }], eligibleGroups: [{ major: "CS" }],
slots: [{ componentType: "lecture", groupNumber: "1", day: "Monday", startMinute, endMinute: startMinute + 60, room: "Fixture room", capacity: 20 }],
});
Expand Down Expand Up @@ -208,6 +209,95 @@ test("A1 Req 91, 93-94: Stripe checkout retries and only verified payment produc
assert.equal((await call(receiptPath, { role: "otherStudent" })).status, 404);
});

test("Req 83 and 87: a graduation assertion cannot bypass the academic credit limit", async () => {
await Course.insertMany(Array.from({ length: 16 }, (_, index) => ({
code: `CLEARWIN${index}`, name: `Remaining course ${index}`, creditHours: 4,
courseType: "core", facultyMajors: ["CS"], offeringSeasons: ["winter"],
})));
const course = courses[1];
const result = await call("/extra-hours", { role: "advisor", method: "POST", body: {
...requestBody(), courseIds: [course.id], graduatingWithinOneYear: true,
} });
assert.equal(result.status, 400);
assert.match(result.data.message, /at most 3 hours/i);
const legacy = await extra({
courses: [{ course: course.id, hours: 4, pricePerHour: 800, subtotal: 3200, isRepeated: false }],
requestedHours: 4, totalCost: 3200,
eligibilitySnapshot: { standardAllowance: 30, hoursBeforeRequest: 30, hoursAfterRequest: 34, isProbation: false, graduatingWithinOneYear: true },
});
assert.equal((await decide(legacy, { decision: "approved", responseNote: "Confirm" })).status, 409);
assert.equal((await ExtraHoursRequest.findById(legacy.id)).decisionStatus, "pending");
});

test("Req 87: current credits, term availability and repeat pricing gate coordinator approval", async () => {
const request = await extra();
const approve = () => decide(request, { decision: "approved", responseNote: "Confirm" });
await Course.updateOne({ _id: courses[0]._id }, { creditHours: 2 });
let response = await approve();
assert.equal(response.status, 409);
assert.match(response.data.message, /credits or prices have changed/);
await Course.updateOne({ _id: courses[0]._id }, { creditHours: 3 });
await CourseOffering.updateOne({ course: courses[0]._id, term: terms[0]._id }, { isPublished: false });
response = await approve();
assert.equal(response.status, 409);
assert.match(response.data.message, /unpublished/);
await CourseOffering.deleteOne({ course: courses[0]._id, term: terms[0]._id });
response = await approve();
assert.equal(response.status, 409);
assert.match(response.data.message, /unavailable/);
await publishFixture(courses[0], 0);
await CourseAttempt.create({ student: student._id, course: courses[0]._id, term: past._id, result: "failed", attendance: "attended", grade: "F" });
response = await approve();
assert.equal(response.status, 409);
assert.match(response.data.message, /credits or prices have changed/);
assert.equal((await ExtraHoursRequest.findById(request.id)).decisionStatus, "pending");
});

test("Req 91–92: stale approval cannot debit a wallet, defer a charge or open Stripe checkout", async (t) => {
mockStripeCheckout(t);
const request = await extra({ decisionStatus: "approved", settlementStatus: "awaitingChoice" });
await FinancialTransaction.create({ student: student._id, kind: "walletTopUp", amount: 3000, status: "succeeded" });
await Course.updateOne({ _id: courses[0]._id }, { creditHours: 2 });
const results = await Promise.all([
settle(request, { option: "now", method: "wallet" }),
settle(request, { option: "deferred" }),
call(`/extra-hours/${request.id}/checkout`, { role: "student", method: "POST", body: {} }),
]);
assert.ok(results.every(({ status, data }) => status === 409 && /credits or prices have changed/.test(data.message)));
await Course.updateOne({ _id: courses[0]._id }, { creditHours: 3 });
await CourseOffering.deleteOne({ course: courses[0]._id, term: terms[0]._id });
const missingOffering = await settle(request, { option: "deferred" });
assert.equal(missingOffering.status, 409);
assert.match(missingOffering.data.message, /unavailable/);
assert.equal((await getWallet(student._id)).balance, 3000);
assert.equal(await FinancialTransaction.countDocuments({ extraHoursRequest: request.id }), 0);
assert.equal(await UniversityInstallment.countDocuments(), 0);
assert.equal((await ExtraHoursRequest.findById(request.id)).settlementStatus, "awaitingChoice");
});

test("Req 91: Stripe capture after a course change produces one wallet credit across simultaneous confirmations", async (t) => {
const stripe = mockStripeCheckout(t);
const request = await extra({ decisionStatus: "approved", settlementStatus: "awaitingChoice" });
const checkout = (suffix = "") => call(`/extra-hours/${request.id}/checkout${suffix}`, { role: "student", method: "POST", body: {} });
assert.equal((await checkout()).status, 201);
await Course.updateOne({ _id: courses[0]._id }, { creditHours: 2 });
stripe.pay();
const results = await Promise.all([checkout("/check"), checkout("/check")]);
assert.deepEqual(results.map(({ data }) => data.status), ["refunded", "refunded"]);
assert.equal((await checkout("/check")).data.status, "refunded");
const capture = await FinancialTransaction.findOne({ extraHoursRequest: request.id, kind: "gatewayPayment" });
assert.equal(capture.status, "REFUNDED");
assert.equal(capture.transactionReference, "pi_receipt");
const refunded = await FinancialTransaction.find({ extraHoursRequest: request.id, kind: "refund" });
assert.equal(refunded.length, 1);
assert.equal(String(refunded[0].relatedTransaction), capture.id);
assert.equal((await getWallet(student._id)).balance, 2400);
const state = await ExtraHoursRequest.findById(request.id).populate("courses.course", "creditHours").lean();
assert.equal(state.settlementStatus, "refunded");
assert.equal(calculateDraftCreditPolicy(student, [state]).approvedExtraHours, 0);
assert.equal(await Notification.countDocuments({ recipient: users.student._id, type: "refundIssued" }), 1);
});

test("A1 Req 94: deferred confirmation download is not labelled a paid receipt", async () => {
const request = await extra({ decisionStatus: "approved", settlementStatus: "awaitingChoice" });
const result = await settle(request, { option: "deferred" });
Expand Down Expand Up @@ -490,6 +580,7 @@ test("Req 92 and 102: distinct deferrals share the next installment and cancella
})));
const requests = [];
for (const course of shortCourses) {
await publishFixture(course);
const created = await call("/extra-hours", { role: "advisor", method: "POST",
body: { ...requestBody(), courseIds: [String(course._id)] } });
assert.equal(created.status, 201, JSON.stringify(created.data));
Expand Down Expand Up @@ -520,7 +611,12 @@ test("Req 92 and 102: distinct deferrals share the next installment and cancella
});

test("Req 92 and 94: existing outstanding charges gain a reusable installment link without changing amounts", async () => {
const request = await extra({ decisionStatus: "approved", settlementStatus: "deferred", settlementOption: "deferred" });
const legacyCourse = await Course.create({ code: "LEGACY-OLD", name: "Existing course", creditHours: 2, courseType: "core", facultyMajors: ["CS"] });
const request = await extra({
courses: [{ course: legacyCourse.id, hours: 2, pricePerHour: 800, subtotal: 1600, isRepeated: false }],
requestedHours: 2, totalCost: 1600, decisionStatus: "approved", settlementStatus: "deferred", settlementOption: "deferred",
eligibilitySnapshot: { standardAllowance: 30, hoursBeforeRequest: 30, hoursAfterRequest: 32, isProbation: false, graduatingWithinOneYear: false },
});
const old = await FinancialTransaction.create({
student: student._id, extraHoursRequest: request._id, kind: "deferredCharge", status: "PENDING",
amount: request.totalCost, settlementOption: "deferred", installment: "Next installment",
Expand All @@ -534,7 +630,12 @@ test("Req 92 and 94: existing outstanding charges gain a reusable installment li
assert.equal(upgraded.installment, old.installment);
assert.equal(await UniversityInstallment.countDocuments({ student: student._id, term: terms[0]._id }), 1);

const next = await extra({ decisionStatus: "approved", settlementStatus: "awaitingChoice" });
const course = await Course.create({ code: "LEGACY-INST", name: "Next installment course", creditHours: 1, courseType: "core", facultyMajors: ["CS"] });
await publishFixture(course);
const next = await extra({
courses: [{ course: course.id, hours: 1, pricePerHour: 800, subtotal: 800, isRepeated: false }],
requestedHours: 1, totalCost: 800, decisionStatus: "approved", settlementStatus: "awaitingChoice",
});
const settled = await settle(next, { option: "deferred" });
assert.equal(settled.status, 200);
assert.equal(settled.data.transaction.installmentId, String(upgraded.installmentId));
Expand Down
11 changes: 1 addition & 10 deletions apps/api/src/controllers/scheduling.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ScheduleActivity } from "../models/communications.js";
import { loadStudentWorkflows } from "../services/student-workflow-status.js";
import { notifyStudents } from "../services/student-notifications.js";
import { calculateDraftCreditPolicy } from "../utils/credit-allowance.js";
import { majorMatches } from "../utils/major.js";
import { majorMatches, offeringEligibleForStudent } from "../utils/major.js";
import { buildWeeklyCalendar } from "../../../../server/src/utils/weeklyCalendar.js";
import { toMinutes, findFirstClash, describeSlot, slotsOverlap } from "../../../../server/src/utils/timetable.js";
import { buildRegisteredCourses } from "../../../../server/src/utils/registeredCourses.js";
Expand Down Expand Up @@ -616,15 +616,6 @@ function canManageAdvisingStudent(viewer, student) {
return null;
}

function offeringEligibleForStudent(offering, student) {
const course = offering.course;
const majorIsEligible = !course.facultyMajors?.length || course.facultyMajors.some((major) => majorMatches(major, student.major));
return majorIsEligible && (offering.eligibleGroups || []).some((group) =>
majorMatches(group.major, student.major) && (group.semester == null || Number(group.semester) === Number(student.currentSemester)) &&
(!group.studyGroup || !student.studyGroup || String(group.studyGroup) === String(student.studyGroup))
);
}

function groupDraftOffering(offering, preferenceGroups, reservedSlots) {
const byComponent = new Map();
for (const slot of offering.slots || []) {
Expand Down
Loading
Loading