diff --git a/src/api/__tests__/appointments/appointments.test.ts b/src/api/__tests__/appointments/appointments.test.ts index 67472fa..81f0db7 100644 --- a/src/api/__tests__/appointments/appointments.test.ts +++ b/src/api/__tests__/appointments/appointments.test.ts @@ -168,12 +168,14 @@ describe("appointments API", () => { const mockAppt = { id: "a1" }; mockFetchSuccess(mockAppt); - const result = await patchAcceptReschedule("a1"); + const body = { proposed_starts_at: 1000, proposed_ends_at: 2000 }; + const result = await patchAcceptReschedule("a1", body); expect(result).toEqual(mockAppt); const [url, init] = lastFetchCall(); expect(url).toBe("/api/appointments/a1/reschedule/accept"); expect(init?.method).toBe("PATCH"); + expect(init?.body).toBe(JSON.stringify(body)); }); it("patchDeclineReschedule calls /appointments/:id/reschedule/decline", async () => { diff --git a/src/api/appointments/patchAcceptReschedule.ts b/src/api/appointments/patchAcceptReschedule.ts index 3f2322a..f5ef500 100644 --- a/src/api/appointments/patchAcceptReschedule.ts +++ b/src/api/appointments/patchAcceptReschedule.ts @@ -1,6 +1,10 @@ import { client } from "../client"; import type { Appointment } from "../client"; -export function patchAcceptReschedule(id: string): Promise { - return client(`/appointments/${id}/reschedule/accept`, { method: "PATCH" }); +// The backend pins which proposal is being accepted: the caller echoes the +// proposed window it read, and a superseded proposal returns 409. +export type AcceptRescheduleBody = { proposed_starts_at: number; proposed_ends_at: number }; + +export function patchAcceptReschedule(id: string, body: AcceptRescheduleBody): Promise { + return client(`/appointments/${id}/reschedule/accept`, { method: "PATCH", body }); } diff --git a/src/api/client/types.ts b/src/api/client/types.ts index 294a085..071a7df 100644 --- a/src/api/client/types.ts +++ b/src/api/client/types.ts @@ -159,6 +159,10 @@ export type Enrollment = { course: string; user: PersonRef; enrolled_by: PersonRef; + // The class (ClassGroup id) that pumped this enrollment, or null for a + // hand-placed row. A row with a source is swept when that class drops the + // student or detaches the course; a null row is permanent. + source: string | null; }; export type CourseSession = { @@ -492,6 +496,11 @@ export type Limits = { max_subject_description_len: number; max_session_topic_len: number; max_term_name_len: number; + max_class_name_len: number; + max_class_grade_len: number; + max_class_members: number; + max_class_courses: number; + max_class_bytes: number; }; exam: { max_title_len: number; diff --git a/src/components/exams/answer-sheet-view.tsx b/src/components/exams/answer-sheet-view.tsx index 7cb0975..8b51d3d 100644 --- a/src/components/exams/answer-sheet-view.tsx +++ b/src/components/exams/answer-sheet-view.tsx @@ -22,6 +22,11 @@ export function AnswerSheetView(props: { examId: string; userId: string; mode?: // /review routes (no userId in path). Everything below is identical either way. const mode = () => props.mode ?? "grader"; + // Self-review reads 409 while the caller's latest sitting is still in + // progress — a retake must submit before it can read the answer key. We + // degrade to a friendly banner instead of erroring the panel. + const [reviewInProgress, setReviewInProgress] = createSignal(false); + // Which sitting the grader is viewing. null = the latest (grade-of-record), the default. const [selectedSeq, setSelectedSeq] = createSignal(null); // Switch sittings inside a transition so the current sheet stays on screen @@ -34,10 +39,15 @@ export function AnswerSheetView(props: { examId: string; userId: string; mode?: const [attempts] = createResource( () => [props.examId, props.userId] as const, async ([examId, userId]) => { + if (mode() === "self") setReviewInProgress(false); try { return mode() === "self" ? await getExamReviewAttempts(examId) : await getStudentAttempts(examId, userId); } catch (err) { if (err instanceof ApiError && err.status === 404) return [] as number[]; + if (mode() === "self" && err instanceof ApiError && err.status === 409) { + setReviewInProgress(true); + return [] as number[]; + } throw err; } }, @@ -94,7 +104,8 @@ export function AnswerSheetView(props: { examId: string; userId: string; mode?: : await getStudentAttemptAnswers(examId, userId, seq); } } catch (err) { - if (err instanceof ApiError && err.status === 404) { + if (err instanceof ApiError && (err.status === 404 || (mode() === "self" && err.status === 409))) { + if (mode() === "self" && err instanceof ApiError && err.status === 409) setReviewInProgress(true); sheet = { exam: examId, user: { id: userId, username: userId, display_name: null }, @@ -136,6 +147,9 @@ export function AnswerSheetView(props: { examId: string; userId: string; mode?: // unmount and its portalled menu would flash unpositioned (top-left) on // every select. Only the answer sheet suspends.
+ +

{t("exams.reviewInProgress")}

+
1}>
{t("exams.previousAttempts")} @@ -148,7 +162,7 @@ export function AnswerSheetView(props: { examId: string; userId: string; mode?:
}> - + {(d) => (
diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index a1fa209..b1dd6e9 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -816,6 +816,7 @@ export type MessageKey = | "exams.attemptN" | "exams.currentAttempt" | "exams.pastAttemptReadOnly" + | "exams.reviewInProgress" | "exams.uploadAnswerImage" | "exams.playDrawing" | "exams.showImage" @@ -870,6 +871,7 @@ export type MessageKey = | "settings.maxFileSize" | "settings.maxFileSizeHelp" | "settings.maxFileSizeInvalid" + | "settings.mealSlotNameInvalid" | "settings.aiPolicy" | "settings.aiPolicyHelp" | "settings.chatHistory" @@ -2123,6 +2125,7 @@ const en: Dict = { "exams.attemptN": "Attempt {n}", "exams.currentAttempt": "current", "exams.pastAttemptReadOnly": "Viewing a previous attempt — read-only. Grading applies to the current attempt.", + "exams.reviewInProgress": "Submit your current attempt before you can review it.", "exams.uploadAnswerImage": "Upload image", "exams.playDrawing": "Play drawing", "exams.showImage": "Show image", @@ -2177,6 +2180,7 @@ const en: Dict = { "settings.maxFileSize": "Max note file size", "settings.maxFileSizeHelp": "Per-file upload cap for note attachments, in MiB. Backend accepts 0.001-25 MiB.", "settings.maxFileSizeInvalid": "Enter a valid file size.", + "settings.mealSlotNameInvalid": "A meal slot name can't contain / \\ ? # or %.", "settings.aiPolicy": "AI policy", "settings.aiPolicyHelp": "Limits for conversation context, threads, and message length.", "settings.chatHistory": "History turns", @@ -3356,6 +3360,7 @@ const tr: Dict = { "exams.attemptN": "{n}. deneme", "exams.currentAttempt": "güncel", "exams.pastAttemptReadOnly": "Önceki bir deneme görüntüleniyor — salt okunur. Puanlama güncel denemeye uygulanır.", + "exams.reviewInProgress": "İncelemek için önce mevcut denemeni gönder.", "exams.uploadAnswerImage": "Görsel yükle", "exams.playDrawing": "Çizimi oynat", "exams.showImage": "Görseli göster", @@ -3410,6 +3415,7 @@ const tr: Dict = { "settings.maxFileSize": "Not dosyası boyut sınırı", "settings.maxFileSizeHelp": "Not ekleri için dosya başına yükleme sınırı, MiB cinsinden. Backend 0.001-25 MiB kabul eder.", "settings.maxFileSizeInvalid": "Geçerli bir dosya boyutu gir.", + "settings.mealSlotNameInvalid": "Öğün adı / \\ ? # veya % içeremez.", "settings.aiPolicy": "Yapay zekâ politikası", "settings.aiPolicyHelp": "Konuşma bağlamı, konu sayısı ve mesaj uzunluğu sınırları.", "settings.chatHistory": "Geçmiş turu", diff --git a/src/pages/appointments-page.tsx b/src/pages/appointments-page.tsx index bc96e48..bf2358a 100644 --- a/src/pages/appointments-page.tsx +++ b/src/pages/appointments-page.tsx @@ -355,7 +355,7 @@ function AppointmentsContent() { const a = cell.row.original; const actions = [] as { label: string; icon: import("solid-js").JSX.Element; destructive?: boolean; onSelect: () => void }[]; for (const action of appointmentActions(a, "requester", now())) { - if (action === "acceptReschedule") actions.push({ label: t("appointments.acceptReschedule"), icon: , onSelect: () => void act(() => patchAcceptReschedule(a.id), "appointments.status.approved") }); + if (action === "acceptReschedule" && a.proposed_starts_at != null && a.proposed_ends_at != null) actions.push({ label: t("appointments.acceptReschedule"), icon: , onSelect: () => void act(() => patchAcceptReschedule(a.id, { proposed_starts_at: a.proposed_starts_at!, proposed_ends_at: a.proposed_ends_at! }), "appointments.status.approved") }); if (action === "declineReschedule") actions.push({ label: t("appointments.declineReschedule"), icon: , destructive: true, onSelect: () => askCancel(() => patchDeclineReschedule(a.id), false) }); if (action === "cancel") actions.push({ label: t("appointments.cancel"), icon: , destructive: true, onSelect: () => askCancel((reason) => patchCancelAppointment(a.id, reason ? { reason } : undefined)) }); } diff --git a/src/pages/meal-detail-page.tsx b/src/pages/meal-detail-page.tsx index 8cec912..7501d76 100644 --- a/src/pages/meal-detail-page.tsx +++ b/src/pages/meal-detail-page.tsx @@ -68,6 +68,9 @@ function MealDetailContent() { const isParent = () => role() === "parent"; const canServe = () => hasMinRole(role(), "teacher"); const canManage = () => hasMinRole(role(), "manager"); + // Canteen balance/ledger are family-money reads: self, a parent of the + // student, or manager+. Teachers are no longer allowed (backend 403s). + const canReadMoney = () => isStudent() || isParent() || canManage(); const isAdmin = () => role() === "admin"; const moneyLocale = () => locale() === "tr" ? "tr-TR" : "en-US"; @@ -99,10 +102,10 @@ function MealDetailContent() { async (userId) => userId === auth.user()!.id ? getMyDietaryProfile() : getDietaryProfileByUserId(userId), ); const [balance, { refetch: refetchBalance }] = createResource( - targetId, + () => canReadMoney() ? targetId() : null, async (userId) => userId === auth.user()!.id ? getMyMealBalance() : getMealBalanceByUserId(userId), ); - const [ledger, { refetch: refetchLedger }] = createResource(targetId, (userId) => getMealLedgerByUserId(userId, { limit: 20 })); + const [ledger, { refetch: refetchLedger }] = createResource(() => canReadMoney() ? targetId() : null, (userId) => getMealLedgerByUserId(userId, { limit: 20 })); const [attendance] = createResource(targetId, (userId) => getMealAttendanceByUserId(userId, { limit: 20 })); // The backend does not expose a teacher-visible service-roster endpoint. // Teachers can still see and amend recorded service; managers additionally @@ -231,9 +234,9 @@ function MealDetailContent() {

{t("meals.dietaryProfile")}

{(tag) => ⚠ {tag}}

{profile()?.note || t("meals.noDietaryNotes")}

-

{t("meals.balance")}

{formatTry(balance()?.balance_minor ?? 0, moneyLocale())}

+

{t("meals.balance")}

{formatTry(balance()?.balance_minor ?? 0, moneyLocale())}

-

{t("meals.ledger")}

{(line) =>

{t(`meals.ledger.${line.kind}` as never)}

{line.note || line.method || "—"} · {formatDateTime(line.created_at, locale())}

{line.kind === "charge" ? "−" : "+"}{formatTry(line.amount_minor, moneyLocale())}
}

{t("meals.noLedger")}

+

{t("meals.ledger")}

{(line) =>

{t(`meals.ledger.${line.kind}` as never)}

{line.note || line.method || "—"} · {formatDateTime(line.created_at, locale())}

{line.kind === "charge" ? "−" : "+"}{formatTry(line.amount_minor, moneyLocale())}
}

{t("meals.noLedger")}

{t("meals.attendance")}

{(row) =>
{row.status}{formatDateTime(row.marked_at, locale())}
}
diff --git a/src/pages/settings-page.tsx b/src/pages/settings-page.tsx index 5a3d109..42e8300 100644 --- a/src/pages/settings-page.tsx +++ b/src/pages/settings-page.tsx @@ -111,6 +111,18 @@ function SettingsContent() { setError(t("settings.maxFileSizeInvalid")); return; } + // A meal-slot name becomes a URL path segment on the backend, so these + // characters are rejected there — but a name already on the saved list is + // grandfathered in, so only newly-typed names are blocked client-side. + const savedSlotNames = new Set((baseline()?.meal_slots ?? []).map((slot) => slot.name)); + const badSlot = mealSlots().find((slot) => { + const name = slot.name.trim(); + return name !== "" && /[/\\?#%]/.test(name) && !savedSlotNames.has(name); + }); + if (badSlot) { + setError(t("settings.mealSlotNameInvalid")); + return; + } setPending(true); try { const before = baseline();