Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
355f21b
Passwords also refuse a distinctive word of an institute's name, not …
omerFixesBugs Nov 16, 2026
7016eff
Sprint 1 P1-J plan (docs/plans/sprint-1-p1j-password-hash.md): the ap…
omerFixesBugs Nov 16, 2026
25da8a3
Sprint 1 P2 plan (docs/plans/sprint-1-p2-files.md): institute profile…
omerFixesBugs Nov 16, 2026
995e61e
Test users get phone numbers no other test user of the same database …
omerFixesBugs Nov 16, 2026
356c448
The app login can no longer read users.password_hash (P1-J): SELECT o…
omerFixesBugs Nov 16, 2026
3ca69eb
Every Prisma client leaves users.password_hash out of its reads (P1-J…
omerFixesBugs Nov 16, 2026
30e85f6
Files and the institute profile in the database (P2 task 1): stored_f…
omerFixesBugs Nov 16, 2026
687a83b
CORS_ORIGINS is normalised in env.ts as browsers send Origin (lower-c…
omerFixesBugs Nov 16, 2026
ff8981c
Shared file caps, types and the institute profile schema (P2 task 2):…
omerFixesBugs Nov 16, 2026
917d5eb
The start-up login check also refuses a login with REPLICATION (a rep…
omerFixesBugs Nov 16, 2026
bc6644b
Password login without the hash (P1-J): the API hashes the typed pass…
omerFixesBugs Nov 16, 2026
b0e6315
GET /me/password reads hasPassword from auth_my_password_is_set() (P1…
omerFixesBugs Nov 16, 2026
47fb357
Docs for P1-J: database.md (password_hash not readable by the app, a …
omerFixesBugs Nov 16, 2026
20b29e9
Redis is pinned to one exact version, redis:7.4.11-alpine (the versio…
omerFixesBugs Nov 16, 2026
81bfc26
Docs for the follow-ups: decisions-pending gets the section "Small fo…
omerFixesBugs Nov 16, 2026
9cc9d54
Image processing for uploads (P2 task 3): sharp 0.35.5 (already in th…
omerFixesBugs Nov 16, 2026
b0e010b
FileStore and the per-institute cap (P2 task 4): PostgresFileStore is…
omerFixesBugs Nov 16, 2026
caec9f7
Photo and profile routes (P2 task 5): GET/PUT/DELETE /students/:id/ph…
omerFixesBugs Nov 16, 2026
57cf79f
Web (P2 task 6): Settings → Institute profile (names, EIIN, contact, …
omerFixesBugs Nov 16, 2026
4e4cbb2
Docs for P2 (task 7): docs/files.md, database.md (the three tables an…
omerFixesBugs Nov 16, 2026
724ffb0
The photo dialog's preview URL is made when a file is chosen, not in …
omerFixesBugs Nov 16, 2026
110857d
files.spec: the profile fields by id ("নাম (বাংলা)" is also part of t…
omerFixesBugs Nov 16, 2026
8c3a4f9
After the review (P1-J7): a dedicated login for the password login. j…
omerFixesBugs Nov 16, 2026
72b714b
The password login looks the hash up on its own database login (Login…
omerFixesBugs Nov 16, 2026
06f3236
Docs after the P1-J review: what an injection in an ordinary request …
omerFixesBugs Nov 16, 2026
82f6600
Test phones never wrap and their lock survives races (review of PR #1…
omerFixesBugs Nov 16, 2026
27403c3
The institute-name rule compares passwords and names like the phone r…
omerFixesBugs Nov 16, 2026
7aa31c5
An origin setting with a login, a path, a query or a fragment is no o…
omerFixesBugs Nov 16, 2026
fd6430e
Docs after the review of PR #17: P1-I's title line says it is built h…
omerFixesBugs Nov 16, 2026
9dbee45
P1-J migration after the second review: it first checks that jantrik_…
omerFixesBugs Nov 16, 2026
a980a60
The password login's database login must reach the same database, por…
omerFixesBugs Nov 16, 2026
ff673b8
Docs after the second P1-J review: the server upgrade creates the rol…
omerFixesBugs Nov 16, 2026
13deed2
A file reference is tied to its kind (review R6): UNIQUE (tenant_id, …
omerFixesBugs Nov 16, 2026
cb86722
Uploads hold no database connection while they arrive (review R1): th…
omerFixesBugs Nov 16, 2026
459bcf7
Web after the review: a chosen image is shrunk in the browser to 1600…
omerFixesBugs Nov 16, 2026
944e840
Docs after the review: auth.md (the request pipeline and @OwnTransact…
omerFixesBugs Nov 16, 2026
282c8b6
Review round 2, API: uploads in flight bounded before multer (16 per …
omerFixesBugs Nov 16, 2026
cfd4506
Review round 2, web: the browser asks for the EXIF orientation explic…
omerFixesBugs Nov 16, 2026
73eb83b
Docs for review round 2: auth.md (the upload routes' re-checks, Uploa…
omerFixesBugs Nov 16, 2026
e622e52
The interceptor opens its transaction through an unchecked entry (aro…
omerFixesBugs Nov 16, 2026
3d2c5d5
Review round 3: no upload slot leaks when the client left before Uplo…
omerFixesBugs Nov 16, 2026
de19108
The two new origin tests' development settings also name DATABASE_LOG…
omerFixesBugs Nov 16, 2026
aa0105b
Merge P1-J (#16) into the small follow-ups (#17): the ready resolutio…
omerFixesBugs Nov 16, 2026
b1efceb
Merge remote-tracking branch 'origin/feature/sprint-1-p1j-password-ha…
omerFixesBugs Nov 16, 2026
b5d3697
Merge remote-tracking branch 'origin/feature/sprint-1-p2-files' into …
omerFixesBugs Nov 16, 2026
c857102
Merge remote-tracking branch 'origin/feature/small-followups-after-p1…
omerFixesBugs Nov 16, 2026
9309fa8
Work in progress: a staff guide draft and draft legal texts (terms of…
omerFixesBugs Nov 19, 2026
ed5d56c
Docs only: a plain staff guide draft (signing in, setup, students, gu…
omerFixesBugs Nov 19, 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
Prev Previous commit
Next Next commit
Web after the review: a chosen image is shrunk in the browser to 1600…
… px before upload (JPEG for photos, PNG otherwise; the original when it cannot be decoded), the guardian's report card shows the photo through the guardian's own route (R3, checked in the exams spec), and the IMAGE_BUSY message

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
omerFixesBugs and claude committed Nov 16, 2026
commit 459bcf718a17b03eae5fa84886c61292f9ea2211
10 changes: 10 additions & 0 deletions apps/web/e2e/exams.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
api,
API_URL,
apiLogin,
apiUploadPhoto,
apiOtpLogin,
DEMO,
otpLoginWithBanglaDigits,
Expand Down Expand Up @@ -266,6 +267,12 @@ for (const c of CASES) {
);
await admin.emulateMedia({ media: 'screen' });

// The child gets a photo; the guardian's report card shows it through the guardian's own
// route (/me/children/:id/photo), checked once (sprint 1 P2, from the review).
const office = await apiLogin(DEMO.shaplaOwner);
const photoChild = (await api<StudentsPage>(office, `/students?q=${c.child}`)).items[0]!.id;
if (c.lang === 'bn') await apiUploadPhoto(office, photoChild);

// ── The guardian, 390 px ──
const guardian = await newPage(browser, baseURL, GUARDIAN_PHONE);
await otpLoginWithBanglaDigits(guardian, c.guardian);
Expand All @@ -282,12 +289,15 @@ for (const c of CASES) {
const reportCard = guardian.getByTestId('report-card');
await expect(reportCard).toBeVisible();
await expect(reportCard.getByTestId('report-card-summary')).toBeVisible();
if (c.lang === 'bn') await expect(reportCard.getByTestId('student-photo')).toBeVisible();
expect(await findLayoutProblems(guardian)).toEqual([]);
await guardian.emulateMedia({ media: 'print' });
const pdf = (await guardian.pdf({ preferCSSPageSize: true })).toString('latin1');
expect(pdf.match(/\/Type\s*\/Page[^s]/g)?.length).toBe(1);
expect(pdf).toMatch(/\/MediaBox\s*\[\s*0\s+0\s+(594|595)(\.\d+)?\s+(841|842)(\.\d+)?\s*\]/);
await guardian.emulateMedia({ media: 'screen' });
// The photo goes again, so the other specs see the demo data as seeded.
if (c.lang === 'bn') await api(office, `/students/${photoChild}/photo`, { method: 'DELETE' });
const [, childId, examClassId] = /\/children\/([^/]+)\/results\/([^/?]+)/.exec(guardian.url())!;
expect(examClassId).toBe(ids.examClassId);

Expand Down
18 changes: 18 additions & 0 deletions apps/web/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,21 @@ export async function api<T>(
expect(res.ok, `${init.method ?? 'GET'} ${path} → ${res.status}`).toBe(true);
return (await res.json()) as T;
}

/** A 1 × 1 PNG: the API re-encodes it like any upload (sprint 1 P2). */
export const TINY_PNG = Buffer.from(
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==',
'base64',
);

/** Gives a student a photo through the API (multipart), as an admin would. */
export async function apiUploadPhoto(token: string, studentId: string): Promise<void> {
const form = new FormData();
form.append('file', new Blob([TINY_PNG], { type: 'image/png' }), 'photo.png');
const res = await fetch(`${API_URL}/students/${studentId}/photo`, {
method: 'PUT',
headers: { Authorization: `Bearer ${token}` },
body: form,
});
expect(res.ok, `PUT /students/${studentId}/photo → ${res.status}`).toBe(true);
}
3 changes: 2 additions & 1 deletion apps/web/messages/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"imageTooBig": "ছবিটিতে পিক্সেল খুব বেশি (সর্বোচ্চ ৫০ মেগাপিক্সেল)। আরেকটু ছোট ছবি দিন।",
"imageCannotShrink": "ছবিটি যথেষ্ট ছোট করা গেল না। অন্য একটি ছবি দিন।",
"fileTooLarge": "ফাইলটি ৫ MB-এর বেশি বড়। ছোট একটি ফাইল দিন।",
"storageFull": "প্রতিষ্ঠানের ছবি রাখার জায়গা পূর্ণ। পুরোনো ছবি সরান বা জান্ত্রিককে জানান।"
"storageFull": "প্রতিষ্ঠানের ছবি রাখার জায়গা পূর্ণ। পুরোনো ছবি সরান বা জান্ত্রিককে জানান।",
"imageBusy": "এই মুহূর্তে অনেক ছবি প্রস্তুত হচ্ছে। একটু পরে আবার চেষ্টা করুন।"
},
"login": {
"title": "লগইন করুন",
Expand Down
3 changes: 2 additions & 1 deletion apps/web/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"imageTooBig": "The image has too many pixels (at most 50 megapixels). Choose a smaller one.",
"imageCannotShrink": "This image could not be made small enough. Choose another one.",
"fileTooLarge": "The file is larger than 5 MB. Choose a smaller one.",
"storageFull": "The institute's storage for images is full. Remove old images or contact Jantrik."
"storageFull": "The institute's storage for images is full. Remove old images or contact Jantrik.",
"imageBusy": "Many images are being prepared right now. Try again in a moment."
},
"login": {
"title": "Sign in",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/app/(app)/setup/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ function ImageSlot({ slot, file }: { slot: InstituteImageSlot; file: FileRef | n
disabled={pending}
onChoose={(f) => upload.mutate(f)}
onTooLarge={() => toast.error(tErrors('fileTooLarge'))}
opaque={false}
testId={`image-${slot}-choose`}
>
{file ? t('imageReplace') : t('imageUpload')}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/exams/guardian.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function ChildReportCard({
<p className="text-muted-foreground text-sm print:hidden">
{t('publishedOn', { date: formatDate(q.data.publishedAt, locale) })}
</p>
<ReportCardsPrint data={q.data} />
<ReportCardsPrint data={q.data} as="guardian" />
</>
)}
</div>
Expand Down
22 changes: 19 additions & 3 deletions apps/web/src/components/exams/report-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,32 @@ const WIDE = 'hidden sm:table-cell print:table-cell';
* Bangla first. What a card may show is decided by the API (parents' names only under decision
* #19). Black on white in print whatever the theme.
*/
export function ReportCardsPrint({ data }: { data: ReportCards }) {
export function ReportCardsPrint({
data,
as = 'staff',
}: {
data: ReportCards;
/** Whose view: a guardian's photos come from their own route (/me/children/:id/photo). */
as?: 'staff' | 'guardian';
}) {
return (
<div className="exam-print print-area flex flex-col gap-6" data-testid="report-cards">
{data.cards.map((card) => (
<ReportCardPage key={card.student.id} data={data} card={card} />
<ReportCardPage key={card.student.id} data={data} card={card} as={as} />
))}
</div>
);
}

function ReportCardPage({ data, card }: { data: ReportCards; card: ReportCard }) {
function ReportCardPage({
data,
card,
as,
}: {
data: ReportCards;
card: ReportCard;
as: 'staff' | 'guardian';
}) {
const t = useTranslations('exams.print');
const locale = useLocale() as Locale;
const label = useLabel();
Expand Down Expand Up @@ -95,6 +110,7 @@ function ReportCardPage({ data, card }: { data: ReportCards; card: ReportCard })
<StudentPhoto
studentId={card.student.id}
photoId={card.student.photoId}
as={as}
className="size-24 rounded-md border"
/>
</section>
Expand Down
18 changes: 13 additions & 5 deletions apps/web/src/components/image-upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import { UPLOAD_ACCEPT, UPLOAD_MAX_BYTES } from '@jantrik/shared';
import { ImageUpIcon } from 'lucide-react';
import { useCallback, useEffect, useId, useRef, useState, type ReactNode } from 'react';
import { Button } from '@/components/ui/button';
import { shrinkForUpload } from '@/lib/image-shrink';

/**
* A "choose image" button around a hidden file input. A file over 5 MB is refused here with the
* server's own message, before anything is sent; the server decides the rest by content.
* A "choose image" button around a hidden file input. The chosen image is shrunk in the browser
* first (image-shrink.ts: a phone photo becomes about 300 KB); a file still over 5 MB is refused
* here with the server's own message, before anything is sent. The server decides the rest by
* content. `opaque`: a photo (sent as JPEG); otherwise transparency is kept (PNG).
*/
export function ChooseImageButton({
onChoose,
onTooLarge,
opaque,
children,
variant = 'outline',
size,
Expand All @@ -20,6 +24,7 @@ export function ChooseImageButton({
}: {
onChoose: (file: File) => void;
onTooLarge: () => void;
opaque: boolean;
children: ReactNode;
variant?: 'outline' | 'default' | 'ghost';
size?: 'sm' | 'default';
Expand All @@ -28,6 +33,7 @@ export function ChooseImageButton({
}) {
const input = useRef<HTMLInputElement>(null);
const id = useId();
const [shrinking, setShrinking] = useState(false);
return (
<>
<input
Expand All @@ -42,15 +48,17 @@ export function ChooseImageButton({
const file = e.target.files?.[0];
e.target.value = ''; // the same file can be chosen again after an error
if (!file) return;
if (file.size > UPLOAD_MAX_BYTES) onTooLarge();
else onChoose(file);
setShrinking(true);
void shrinkForUpload(file, opaque)
.then((ready) => (ready.size > UPLOAD_MAX_BYTES ? onTooLarge() : onChoose(ready)))
.finally(() => setShrinking(false));
}}
/>
<Button
type="button"
variant={variant}
size={size}
disabled={disabled}
disabled={disabled || shrinking}
onClick={() => input.current?.click()}
data-testid={testId}
>
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/student-photo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ export function StudentAvatar({
export function StudentPhoto({
studentId,
photoId,
as = 'staff',
className,
}: {
studentId: string;
photoId: string | null;
as?: 'staff' | 'guardian';
className?: string;
}) {
const url = useAuthedImage(studentPhotoPath(studentId, photoId), photoId);
const url = useAuthedImage(studentPhotoPath(studentId, photoId, as), photoId);
if (!url) return null;
return (
// eslint-disable-next-line @next/next/no-img-element
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/students/photo-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export function PhotoDialog({
setFile(f);
}}
onTooLarge={() => setError(tErrors('fileTooLarge'))}
opaque
disabled={pending}
testId="photo-choose"
>
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/lib/authed-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function useImageErrorMessage() {
if (error.code === 'IMAGE_TOO_BIG') return t('imageTooBig');
if (error.code === 'IMAGE_CANNOT_SHRINK') return t('imageCannotShrink');
if (error.code === 'STORAGE_FULL') return t('storageFull');
if (error.code === 'IMAGE_BUSY') return t('imageBusy');
if (error.status === 413) return t('fileTooLarge');
}
return describe(error);
Expand Down
29 changes: 29 additions & 0 deletions apps/web/src/lib/image-shrink.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, expect, it } from 'vitest';
import { fitWithin, shrinkForUpload, UPLOAD_LONG_SIDE } from './image-shrink';

describe('fitWithin (the browser-side shrink before upload)', () => {
it('scales the long side down to the limit, keeping the shape', () => {
expect(fitWithin(4000, 3000, UPLOAD_LONG_SIDE)).toEqual({
width: 1600,
height: 1200,
scaled: true,
});
expect(fitWithin(3024, 4032, 1600)).toEqual({ width: 1200, height: 1600, scaled: true });
});

it('never enlarges a small image', () => {
expect(fitWithin(600, 800, 1600)).toEqual({ width: 600, height: 800, scaled: false });
expect(fitWithin(1, 1, 1600)).toEqual({ width: 1, height: 1, scaled: false });
});

it('keeps at least one pixel a side', () => {
expect(fitWithin(100_000, 10, 1600)).toEqual({ width: 1600, height: 1, scaled: true });
});
});

describe('shrinkForUpload', () => {
it('sends the original when the browser cannot decode images (no createImageBitmap)', async () => {
const file = new File([new Uint8Array(10)], 'a.jpg', { type: 'image/jpeg' });
expect(await shrinkForUpload(file, true)).toBe(file);
});
});
61 changes: 61 additions & 0 deletions apps/web/src/lib/image-shrink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Shrinking a chosen image in the browser before upload (review of P2): a phone's 3-8 MB photo
// becomes about 300 KB, so it uploads in seconds on slow 4G and fits the 5 MB limit. The server
// still decodes, resizes and re-encodes whatever arrives (docs/files.md); this only saves time.

/** The longest side sent: well above every stored box (600 × 800 at most), so nothing is lost. */
export const UPLOAD_LONG_SIDE = 1600;
/** Files at or under this size and within the long side are sent as they are. */
const SMALL_ENOUGH_BYTES = 1_000_000;

/** The size of a width × height image scaled to fit `max` on its longest side (never enlarged). */
export function fitWithin(
width: number,
height: number,
max: number,
): { width: number; height: number; scaled: boolean } {
const scale = Math.min(1, max / Math.max(width, height));
return {
width: Math.max(1, Math.round(width * scale)),
height: Math.max(1, Math.round(height * scale)),
scaled: scale < 1,
};
}

/**
* A smaller copy of `file` to upload: JPEG (quality 0.85) on white for photos (`opaque`), PNG
* otherwise (logos, signatures and seals keep their transparency). The original is returned when
* the browser cannot decode it (the server then says why), when it is small already, or when the
* copy would not be smaller.
*/
export async function shrinkForUpload(file: File, opaque: boolean): Promise<File> {
try {
if (typeof createImageBitmap !== 'function') return file;
const bitmap = await createImageBitmap(file); // EXIF orientation applied by the browser
const size = fitWithin(bitmap.width, bitmap.height, UPLOAD_LONG_SIDE);
if (!size.scaled && file.size <= SMALL_ENOUGH_BYTES) {
bitmap.close();
return file;
}
const canvas = document.createElement('canvas');
canvas.width = size.width;
canvas.height = size.height;
const ctx = canvas.getContext('2d');
if (!ctx) {
bitmap.close();
return file;
}
if (opaque) {
ctx.fillStyle = '#ffffff';
ctx.fillRect(0, 0, size.width, size.height);
}
ctx.drawImage(bitmap, 0, 0, size.width, size.height);
bitmap.close();
const type = opaque ? 'image/jpeg' : 'image/png';
const blob = await new Promise<Blob | null>((done) => canvas.toBlob(done, type, 0.85));
if (!blob || blob.size >= file.size) return file;
const name = file.name.replace(/\.[^.]*$/, '') + (opaque ? '.jpg' : '.png');
return new File([blob], name, { type });
} catch {
return file;
}
}