✨ school identity is the uuid
Browse files at this commita3eb98c6c92d543d92e6ec2187f308002f1e3bb5Parent: a72b005- feat
- ✨ school identity is the uuid
39 changed files +185 -169
- README.md +1 -1
- docs/auth/role-scope-matrix.md +1 -1
- docs/ui/figma-migration-coverage.md +1 -1
- e2e/auth-shell.spec.ts +9 -2
- src/api/__tests__/auth/auth.test.ts +17 -3
- src/api/__tests__/contract/helpers/live-client.ts +18 -4
- src/api/__tests__/schools/schools.test.ts +27 -26
- src/api/auth/getRegisterSchools.ts +7 -0
- src/api/auth/index.ts +1 -0
- src/api/auth/postLogin.ts +1 -1
- src/api/client/client.ts +0 -4
- src/api/client/types.ts +1 -4
- src/api/schools/deleteSchool.ts +6 -0
- src/api/schools/deleteSchoolBySlug.ts +0 -6
- src/api/schools/deleteSchoolModule.ts +2 -2
- src/api/schools/getSchool.ts +6 -0
- src/api/schools/getSchoolBySlug.ts +0 -6
- src/api/schools/getSchoolModules.ts +2 -2
- src/api/schools/index.ts +3 -3
- src/api/schools/patchSchool.ts +11 -0
- src/api/schools/patchSchoolBySlug.ts +0 -11
- src/api/schools/patchSchoolModules.ts +2 -2
- src/api/schools/postSchool.ts +0 -2
- src/api/schools/postSchoolAdminPassword.ts +2 -2
- src/api/schools/postSchoolEnter.ts +2 -2
- src/api/schools/postSchoolModule.ts +2 -2
- src/components/builder/create-school-panel.tsx +0 -10
- src/components/builder/school-admin-access-panel.tsx +3 -3
- src/i18n/locales/en.ts +1 -4
- src/i18n/locales/tr.ts +1 -4
- src/i18n/messages.ts +1 -4
- src/lib/dev-auto-login.ts +2 -2
- src/pages/builder-school-detail-page.tsx +14 -14
- src/pages/builder-schools-page.tsx +13 -11
- src/pages/login-page.test.tsx +3 -3
- src/pages/login-page.tsx +3 -3
- src/pages/register-page.tsx +20 -23
- src/routes/router.tsx +1 -1
- src/vite-env.d.ts +1 -0
README.mdmodified+1 -1
| @@ -53,7 +53,7 @@ Open [http://localhost:5173](http://localhost:5173) in your browser. | ||
| 53 | 53 | |
| 54 | 54 | > **Proxy Note**: Vite proxies `/api/*` and WebSocket connections to `BACKEND_ORIGIN`, preserving HttpOnly session cookies across same-origin calls. Local development defaults to `https://hezarfen-backend.dizey.sh`, so `bun run dev` works without a backend process on the laptop; use `BACKEND_ORIGIN=http://127.0.0.1:7656 bun run dev` to target one locally. The production Bun server gets its co-located loopback default from the image and can be overridden through `hezarfen_frontend.env` (see "Run in a container" below). |
| 55 | 55 | |
| 56 | -> **Dev auto sign-in**: for local testing, put `VITE_DEV_AUTOLOGIN_USERNAME` and `VITE_DEV_AUTOLOGIN_PASSWORD` (optionally `VITE_DEV_AUTOLOGIN_SCHOOL`, a school slug) in `.env.local`, which git ignores. `bun run dev` then signs in on the first `401`; logging out turns it off for that tab. It lives in `src/lib/dev-auto-login.ts` behind `import.meta.env.DEV`, so `vite build` drops it and the credentials never reach `dist/`. | |
| 56 | +> **Dev auto sign-in**: for local testing, put `VITE_DEV_AUTOLOGIN_USERNAME` and `VITE_DEV_AUTOLOGIN_PASSWORD` (optionally `VITE_DEV_AUTOLOGIN_SCHOOL`, a school uuid) in `.env.local`, which git ignores. `bun run dev` then signs in on the first `401`; logging out turns it off for that tab. It lives in `src/lib/dev-auto-login.ts` behind `import.meta.env.DEV`, so `vite build` drops it and the credentials never reach `dist/`. | |
| 57 | 57 | |
| 58 | 58 | > **Demo sign-in**: set `VITE_DEMO_LOGIN_USERNAME` and `VITE_DEMO_LOGIN_PASSWORD` at build time and the login page opens filled with them, plus a one-click "Demo hesabıyla gir" button (`src/lib/demo-login.ts`). Unlike the dev auto sign-in these values are bundled into `dist/`, so set them only for a demo school's build. |
| 59 | 59 |
docs/auth/role-scope-matrix.mdmodified+1 -1
| @@ -47,7 +47,7 @@ route and a school session is 401 here, so these pages carry their own | ||
| 47 | 47 | |---|---| |
| 48 | 48 | | `/builder/login` | Operator sign-in (linked from the school login footer) | |
| 49 | 49 | | `/builder` | School list: create (with first admin + module set), suspend/activate, delete | |
| 50 | -| `/builder/schools/:slug` | Rename/status, module switchboard (per module + per package), admin password reset, enter as admin | | |
| 50 | +| `/builder/schools/:id` | Rename/status, module switchboard (per module + per package), admin password reset, enter as admin | | |
| 51 | 51 | |
| 52 | 52 | ## Primary Navigation per Role |
| 53 | 53 |
docs/ui/figma-migration-coverage.mdmodified+1 -1
| @@ -162,7 +162,7 @@ Rules the captures follow: | ||
| 162 | 162 | | `/profile/:userId` | ADM-29 Kullanıcı Profili | Captured from the running app | |
| 163 | 163 | | `/builder/login` | BLD-01 Operatör Girişi | Builder session only; linked from the SYS-01/login footer | |
| 164 | 164 | | `/builder` | BLD-02 Okullar, BLD-02a Yeni Okul | Create, suspend/activate, delete | |
| 165 | -| `/builder/schools/:slug` | BLD-03 Okul Detayı, BLD-03a Okula Gir | Module switchboard, password reset, enter as admin | | |
| 165 | +| `/builder/schools/:id` | BLD-03 Okul Detayı, BLD-03a Okula Gir | Module switchboard, password reset, enter as admin | | |
| 166 | 166 | |
| 167 | 167 | ## Figma features blocked by product or backend scope |
| 168 | 168 |
e2e/auth-shell.spec.tsmodified+9 -2
| @@ -1,17 +1,24 @@ | ||
| 1 | 1 | import { expect, test } from "@playwright/test"; |
| 2 | 2 | |
| 3 | -const school = process.env.E2E_SCHOOL_SLUG ?? "demo"; | |
| 3 | +const schoolId = process.env.E2E_SCHOOL_ID; | |
| 4 | 4 | const username = process.env.E2E_ADMIN_USERNAME ?? "admin"; |
| 5 | 5 | const password = process.env.E2E_ADMIN_PASSWORD ?? "admin123"; |
| 6 | 6 | |
| 7 | 7 | test("sign-in reaches the authenticated shell with keyboard-accessible navigation", async ({ page }) => { |
| 8 | 8 | await page.goto("/login"); |
| 9 | 9 | await expect(page.locator("#login-username")).toBeVisible(); |
| 10 | - await page.locator("#login-school").fill(school); | |
| 11 | 10 | await page.locator("#login-username").fill(username); |
| 12 | 11 | await page.locator("#login-password").fill(password); |
| 13 | 12 | await page.locator("form").getByRole("button", { name: /log in|sign in|giriş yap/i }).click(); |
| 14 | 13 | |
| 14 | + const chooser = page.getByRole("heading", { name: /choose your school|okulunu seç/i }); | |
| 15 | + const shell = page.getByRole("main"); | |
| 16 | + await expect(chooser.or(shell)).toBeVisible(); | |
| 17 | + if (await chooser.isVisible()) { | |
| 18 | + if (!schoolId) throw new Error("login returned a school chooser; set E2E_SCHOOL_ID to the school uuid"); | |
| 19 | + await page.getByRole("button", { name: schoolId }).click(); | |
| 20 | + } | |
| 21 | + | |
| 15 | 22 | await expect(page).toHaveURL(/\/$/); |
| 16 | 23 | await expect(page.getByRole("main")).toBeVisible(); |
| 17 | 24 |
src/api/__tests__/auth/auth.test.tsmodified+17 -3
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | import { afterEach, describe, expect, it, vi } from "vitest"; |
| 2 | +import { getRegisterSchools } from "../../auth"; | |
| 2 | 3 | import { postLogin } from "../../auth"; |
| 3 | 4 | import { postLogout } from "../../auth"; |
| 4 | 5 | import { postRegister } from "../../auth"; |
| @@ -27,13 +28,14 @@ describe("auth API", () => { | ||
| 27 | 28 | const mockUser = { id: "u1", username: "test" }; |
| 28 | 29 | mockFetchSuccess(mockUser); |
| 29 | 30 | |
| 30 | - const result = await postSelectSchool({ school: "demo" }); | |
| 31 | + const school = "019732e3-7b00-7000-8000-00000000dead"; | |
| 32 | + const result = await postSelectSchool({ school }); | |
| 31 | 33 | expect(result).toEqual(mockUser); |
| 32 | 34 | |
| 33 | 35 | const [url, init] = lastFetchCall(); |
| 34 | 36 | expect(url).toBe("/api/auth/school"); |
| 35 | 37 | expect(init?.method).toBe("POST"); |
| 36 | - expect(init?.body).toBe(JSON.stringify({ school: "demo" })); | |
| 38 | + expect(init?.body).toBe(JSON.stringify({ school })); | |
| 37 | 39 | }); |
| 38 | 40 | |
| 39 | 41 | it("postLogout calls /auth/logout", async () => { |
| @@ -50,7 +52,7 @@ describe("auth API", () => { | ||
| 50 | 52 | const mockResponse = { username: "newuser", role: "student" }; |
| 51 | 53 | mockFetchSuccess(mockResponse); |
| 52 | 54 | |
| 53 | - const data = { school: "demo", username: "newuser", password: "password" }; | |
| 55 | + const data = { school: "019732e3-7b00-7000-8000-00000000dead", username: "newuser", password: "password" }; | |
| 54 | 56 | const result = await postRegister(data); |
| 55 | 57 | expect(result).toEqual(mockResponse); |
| 56 | 58 | |
| @@ -59,4 +61,16 @@ describe("auth API", () => { | ||
| 59 | 61 | expect(init?.method).toBe("POST"); |
| 60 | 62 | expect(init?.body).toBe(JSON.stringify(data)); |
| 61 | 63 | }); |
| 64 | + | |
| 65 | + it("getRegisterSchools reads active schools for the register picker", async () => { | |
| 66 | + const schools = [{ id: "019732e3-7b00-7000-8000-00000000dead", name: "Hezarfen" }]; | |
| 67 | + mockFetchSuccess(schools); | |
| 68 | + | |
| 69 | + const result = await getRegisterSchools(); | |
| 70 | + expect(result).toEqual(schools); | |
| 71 | + | |
| 72 | + const [url, init] = lastFetchCall(); | |
| 73 | + expect(url).toBe("/api/auth/schools"); | |
| 74 | + expect(init?.method).toBe("GET"); | |
| 75 | + }); | |
| 62 | 76 | }); |
src/api/__tests__/contract/helpers/live-client.tsmodified+18 -4
| @@ -21,6 +21,20 @@ const TIMEOUT_MS = 10_000; | ||
| 21 | 21 | const MAX_RATE_LIMIT_RETRIES = 12; |
| 22 | 22 | let cookie = ""; |
| 23 | 23 | |
| 24 | +const SCHOOL_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; | |
| 25 | + | |
| 26 | +/** School cookie is `session=<uuid>.<token>`; operator cookie stays `session=builder.<token>`. */ | |
| 27 | +function sessionCookie(raw: string): string | null { | |
| 28 | + const pair = raw.split(";")[0] ?? ""; | |
| 29 | + if (!pair.startsWith("session=")) return null; | |
| 30 | + const value = pair.slice("session=".length); | |
| 31 | + const dot = value.indexOf("."); | |
| 32 | + if (dot <= 0 || dot === value.length - 1) return null; | |
| 33 | + const prefix = value.slice(0, dot); | |
| 34 | + if (prefix === "builder" || SCHOOL_UUID.test(prefix)) return pair; | |
| 35 | + return null; | |
| 36 | +} | |
| 37 | + | |
| 24 | 38 | type Init = { method?: string; body?: unknown; headers?: Record<string, string> }; |
| 25 | 39 | |
| 26 | 40 | function retryDelayMs(response: Response, attempt: number): number { |
| @@ -59,8 +73,8 @@ export async function api(path: string, init: Init = {}): Promise<Response> { | ||
| 59 | 73 | |
| 60 | 74 | const setCookies = res!.headers.getSetCookie?.() ?? []; |
| 61 | 75 | for (const raw of setCookies) { |
| 62 | - const pair = raw.split(";")[0]; | |
| 63 | - if (pair.startsWith("session=")) cookie = pair; | |
| 76 | + const pair = sessionCookie(raw); | |
| 77 | + if (pair) cookie = pair; | |
| 64 | 78 | } |
| 65 | 79 | return res!; |
| 66 | 80 | } |
| @@ -77,7 +91,7 @@ export async function json<T>(path: string, init: Init = {}): Promise<T> { | ||
| 77 | 91 | |
| 78 | 92 | /** Log in as the seeded admin; the session cookie lands in the jar. */ |
| 79 | 93 | export async function loginAdmin(): Promise<void> { |
| 80 | - const result = await json<{ id: string } | { schools: Array<{ slug: string }> }>("/auth/login", { | |
| 94 | + const result = await json<{ id: string } | { schools: Array<{ id: string }> }>("/auth/login", { | |
| 81 | 95 | method: "POST", |
| 82 | 96 | body: { |
| 83 | 97 | username: env.ADMIN_USERNAME ?? "admin", |
| @@ -85,7 +99,7 @@ export async function loginAdmin(): Promise<void> { | ||
| 85 | 99 | }, |
| 86 | 100 | }); |
| 87 | 101 | if ("schools" in result) { |
| 88 | - const school = env.SCHOOL_SLUG ?? result.schools[0]?.slug; | |
| 102 | + const school = env.SCHOOL_ID ?? result.schools[0]?.id; | |
| 89 | 103 | if (!school) throw new Error("POST /auth/login returned an empty school choice list"); |
| 90 | 104 | await json("/auth/school", { method: "POST", body: { school } }); |
| 91 | 105 | } |
src/api/__tests__/schools/schools.test.tsmodified+27 -26
| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | import { afterEach, describe, expect, it, vi } from "vitest"; |
| 2 | -import { deleteSchoolBySlug } from "../../schools"; | |
| 2 | +import { deleteSchool } from "../../schools"; | |
| 3 | 3 | import { deleteSchoolModule } from "../../schools"; |
| 4 | -import { getSchoolBySlug } from "../../schools"; | |
| 4 | +import { getSchool } from "../../schools"; | |
| 5 | 5 | import { getSchoolModules } from "../../schools"; |
| 6 | 6 | import { getSchools } from "../../schools"; |
| 7 | -import { patchSchoolBySlug } from "../../schools"; | |
| 7 | +import { patchSchool } from "../../schools"; | |
| 8 | 8 | import { patchSchoolModules } from "../../schools"; |
| 9 | 9 | import { postSchool } from "../../schools"; |
| 10 | 10 | import { postSchoolAdminPassword } from "../../schools"; |
| @@ -12,7 +12,8 @@ import { postSchoolEnter } from "../../schools"; | ||
| 12 | 12 | import { postSchoolModule } from "../../schools"; |
| 13 | 13 | import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; |
| 14 | 14 | |
| 15 | -const school = { slug: "ata-koleji", name: "Ata Koleji", status: "active", created_at: 1, modules: ["courses"] }; | |
| 15 | +const schoolId = "019732e3-7b00-7000-8000-00000000dead"; | |
| 16 | +const school = { id: schoolId, name: "Ata Koleji", status: "active", created_at: 1, modules: ["courses"] }; | |
| 16 | 17 | const modules = { enabled: ["courses"], disabled: ["exams"] }; |
| 17 | 18 | |
| 18 | 19 | describe("schools API", () => { |
| @@ -31,19 +32,19 @@ describe("schools API", () => { | ||
| 31 | 32 | expect(init?.method).toBe("GET"); |
| 32 | 33 | }); |
| 33 | 34 | |
| 34 | - it("getSchoolBySlug reads /schools/{slug}", async () => { | |
| 35 | + it("getSchool reads /schools/{id}", async () => { | |
| 35 | 36 | mockFetchSuccess(school); |
| 36 | 37 | |
| 37 | - await getSchoolBySlug("ata-koleji"); | |
| 38 | + await getSchool(schoolId); | |
| 38 | 39 | |
| 39 | 40 | const [url, init] = lastFetchCall(); |
| 40 | - expect(url).toBe("/api/schools/ata-koleji"); | |
| 41 | + expect(url).toBe(`/api/schools/${schoolId}`); | |
| 41 | 42 | expect(init?.method).toBe("GET"); |
| 42 | 43 | }); |
| 43 | 44 | |
| 44 | 45 | it("postSchool posts the school and its first admin", async () => { |
| 45 | 46 | mockFetchSuccess(school, 201); |
| 46 | - const body = { slug: "ata-koleji", name: "Ata Koleji", admin_username: "admin", admin_password: "secret123", modules: ["courses"] }; | |
| 47 | + const body = { name: "Ata Koleji", admin_username: "admin", admin_password: "secret123", modules: ["courses"] }; | |
| 47 | 48 | |
| 48 | 49 | await postSchool(body); |
| 49 | 50 | |
| @@ -53,34 +54,34 @@ describe("schools API", () => { | ||
| 53 | 54 | expect(init?.body).toBe(JSON.stringify(body)); |
| 54 | 55 | }); |
| 55 | 56 | |
| 56 | - it("patchSchoolBySlug patches name and status", async () => { | |
| 57 | + it("patchSchool patches name and status", async () => { | |
| 57 | 58 | mockFetchSuccess({ ...school, status: "suspended" }); |
| 58 | 59 | |
| 59 | - await patchSchoolBySlug("ata-koleji", { status: "suspended" }); | |
| 60 | + await patchSchool(schoolId, { status: "suspended" }); | |
| 60 | 61 | |
| 61 | 62 | const [url, init] = lastFetchCall(); |
| 62 | - expect(url).toBe("/api/schools/ata-koleji"); | |
| 63 | + expect(url).toBe(`/api/schools/${schoolId}`); | |
| 63 | 64 | expect(init?.method).toBe("PATCH"); |
| 64 | 65 | expect(init?.body).toBe(JSON.stringify({ status: "suspended" })); |
| 65 | 66 | }); |
| 66 | 67 | |
| 67 | - it("deleteSchoolBySlug deletes /schools/{slug}", async () => { | |
| 68 | + it("deleteSchool deletes /schools/{id}", async () => { | |
| 68 | 69 | mockFetch204(); |
| 69 | 70 | |
| 70 | - await deleteSchoolBySlug("ata-koleji"); | |
| 71 | + await deleteSchool(schoolId); | |
| 71 | 72 | |
| 72 | 73 | const [url, init] = lastFetchCall(); |
| 73 | - expect(url).toBe("/api/schools/ata-koleji"); | |
| 74 | + expect(url).toBe(`/api/schools/${schoolId}`); | |
| 74 | 75 | expect(init?.method).toBe("DELETE"); |
| 75 | 76 | }); |
| 76 | 77 | |
| 77 | 78 | it("postSchoolAdminPassword re-keys an admin", async () => { |
| 78 | 79 | mockFetch204(); |
| 79 | 80 | |
| 80 | - await postSchoolAdminPassword("ata-koleji", { username: "admin", password: "newsecret" }); | |
| 81 | + await postSchoolAdminPassword(schoolId, { username: "admin", password: "newsecret" }); | |
| 81 | 82 | |
| 82 | 83 | const [url, init] = lastFetchCall(); |
| 83 | - expect(url).toBe("/api/schools/ata-koleji/admin-password"); | |
| 84 | + expect(url).toBe(`/api/schools/${schoolId}/admin-password`); | |
| 84 | 85 | expect(init?.method).toBe("POST"); |
| 85 | 86 | expect(init?.body).toBe(JSON.stringify({ username: "admin", password: "newsecret" })); |
| 86 | 87 | }); |
| @@ -88,10 +89,10 @@ describe("schools API", () => { | ||
| 88 | 89 | it("postSchoolEnter enters as a named admin", async () => { |
| 89 | 90 | mockFetchSuccess({ id: "u1", username: "admin", role: "admin" }); |
| 90 | 91 | |
| 91 | - await postSchoolEnter("ata-koleji", { username: "admin" }); | |
| 92 | + await postSchoolEnter(schoolId, { username: "admin" }); | |
| 92 | 93 | |
| 93 | 94 | const [url, init] = lastFetchCall(); |
| 94 | - expect(url).toBe("/api/schools/ata-koleji/enter"); | |
| 95 | + expect(url).toBe(`/api/schools/${schoolId}/enter`); | |
| 95 | 96 | expect(init?.method).toBe("POST"); |
| 96 | 97 | expect(init?.body).toBe(JSON.stringify({ username: "admin" })); |
| 97 | 98 | }); |
| @@ -99,11 +100,11 @@ describe("schools API", () => { | ||
| 99 | 100 | it("getSchoolModules reads both halves of the catalog", async () => { |
| 100 | 101 | mockFetchSuccess(modules); |
| 101 | 102 | |
| 102 | - const result = await getSchoolModules("ata-koleji"); | |
| 103 | + const result = await getSchoolModules(schoolId); | |
| 103 | 104 | expect(result).toEqual(modules); |
| 104 | 105 | |
| 105 | 106 | const [url, init] = lastFetchCall(); |
| 106 | - expect(url).toBe("/api/schools/ata-koleji/modules"); | |
| 107 | + expect(url).toBe(`/api/schools/${schoolId}/modules`); | |
| 107 | 108 | expect(init?.method).toBe("GET"); |
| 108 | 109 | }); |
| 109 | 110 | |
| @@ -111,10 +112,10 @@ describe("schools API", () => { | ||
| 111 | 112 | mockFetchSuccess(modules); |
| 112 | 113 | const body = { enable: ["exams"], disable_packages: ["ai"] }; |
| 113 | 114 | |
| 114 | - await patchSchoolModules("ata-koleji", body); | |
| 115 | + await patchSchoolModules(schoolId, body); | |
| 115 | 116 | |
| 116 | 117 | const [url, init] = lastFetchCall(); |
| 117 | - expect(url).toBe("/api/schools/ata-koleji/modules"); | |
| 118 | + expect(url).toBe(`/api/schools/${schoolId}/modules`); | |
| 118 | 119 | expect(init?.method).toBe("PATCH"); |
| 119 | 120 | expect(init?.body).toBe(JSON.stringify(body)); |
| 120 | 121 | }); |
| @@ -122,20 +123,20 @@ describe("schools API", () => { | ||
| 122 | 123 | it("postSchoolModule enables one module", async () => { |
| 123 | 124 | mockFetchSuccess(modules); |
| 124 | 125 | |
| 125 | - await postSchoolModule("ata-koleji", "exams"); | |
| 126 | + await postSchoolModule(schoolId, "exams"); | |
| 126 | 127 | |
| 127 | 128 | const [url, init] = lastFetchCall(); |
| 128 | - expect(url).toBe("/api/schools/ata-koleji/modules/exams"); | |
| 129 | + expect(url).toBe(`/api/schools/${schoolId}/modules/exams`); | |
| 129 | 130 | expect(init?.method).toBe("POST"); |
| 130 | 131 | }); |
| 131 | 132 | |
| 132 | 133 | it("deleteSchoolModule disables one module", async () => { |
| 133 | 134 | mockFetchSuccess(modules); |
| 134 | 135 | |
| 135 | - await deleteSchoolModule("ata-koleji", "exams"); | |
| 136 | + await deleteSchoolModule(schoolId, "exams"); | |
| 136 | 137 | |
| 137 | 138 | const [url, init] = lastFetchCall(); |
| 138 | - expect(url).toBe("/api/schools/ata-koleji/modules/exams"); | |
| 139 | + expect(url).toBe(`/api/schools/${schoolId}/modules/exams`); | |
| 139 | 140 | expect(init?.method).toBe("DELETE"); |
| 140 | 141 | }); |
| 141 | 142 | }); |
src/api/auth/getRegisterSchools.tsadded+7 -0
| @@ -0,0 +1,7 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { SchoolChoice } from "./postLogin"; | |
| 3 | + | |
| 4 | +/** Active schools a new account can join. Unauthenticated, same as register. */ | |
| 5 | +export function getRegisterSchools(signal?: AbortSignal): Promise<SchoolChoice[]> { | |
| 6 | + return client<SchoolChoice[]>("/auth/schools", { signal }); | |
| 7 | +} |
src/api/auth/index.tsmodified+1 -0
| @@ -2,3 +2,4 @@ export * from "./postLogin"; | ||
| 2 | 2 | export * from "./postLogout"; |
| 3 | 3 | export * from "./postRegister"; |
| 4 | 4 | export * from "./postSelectSchool"; |
| 5 | +export * from "./getRegisterSchools"; |
src/api/auth/postLogin.tsmodified+1 -1
| @@ -7,7 +7,7 @@ export type LoginBody = { | ||
| 7 | 7 | }; |
| 8 | 8 | |
| 9 | 9 | export type SchoolChoice = { |
| 10 | - slug: string; | |
| 10 | + id: string; | |
| 11 | 11 | name: string; |
| 12 | 12 | }; |
| 13 | 13 |
src/api/client/client.tsmodified+0 -4
| @@ -133,10 +133,6 @@ const API_ERROR_MESSAGES: Record<string, Record<Locale, string>> = { | ||
| 133 | 133 | tr: "Tekrarlanan müsaitlikler birbiriyle çakışıyor.", |
| 134 | 134 | }, |
| 135 | 135 | // Builder surface (web/builder.rs, tenant.rs) — byte-exact. |
| 136 | - "school slug already taken": { | |
| 137 | - en: "That school code is already taken.", | |
| 138 | - tr: "Bu okul kodu zaten kullanılıyor.", | |
| 139 | - }, | |
| 140 | 136 | "that account is not an admin of this school": { |
| 141 | 137 | en: "That account exists but is not an admin of this school.", |
| 142 | 138 | tr: "Bu hesap var ama bu okulun yöneticisi değil.", |
src/api/client/types.tsmodified+1 -4
| @@ -188,7 +188,7 @@ export type SchoolStatus = "active" | "suspended"; | ||
| 188 | 188 | |
| 189 | 189 | /** One school of the deployment, as the builder surface sees it. */ |
| 190 | 190 | export type School = { |
| 191 | - slug: string; | |
| 191 | + id: string; | |
| 192 | 192 | name: string; |
| 193 | 193 | /** A suspended school refuses every one of its own users, login included. */ |
| 194 | 194 | status: SchoolStatus; |
| @@ -831,11 +831,8 @@ export type Limits = { | ||
| 831 | 831 | max_username_len: number; |
| 832 | 832 | username_separators: string[]; |
| 833 | 833 | reserved_usernames: string[]; |
| 834 | - reserved_slugs: string[]; | |
| 835 | 834 | min_password_len: number; |
| 836 | 835 | max_password_len: number; |
| 837 | - min_slug_len: number; | |
| 838 | - max_slug_len: number; | |
| 839 | 836 | max_school_name_len: number; |
| 840 | 837 | max_name_len: number; |
| 841 | 838 | max_display_name_len: number; |
src/api/schools/deleteSchool.tsadded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | + | |
| 3 | +// Destroys the school's data and uploaded files for good. | |
| 4 | +export function deleteSchool(id: string): Promise<void> { | |
| 5 | + return client<void>(`/schools/${encodeURIComponent(id)}`, { method: "DELETE" }); | |
| 6 | +} |
src/api/schools/deleteSchoolBySlug.tsdeleted+0 -6
| @@ -1,6 +0,0 @@ | ||
| 1 | -import { client } from "../client"; | |
| 2 | - | |
| 3 | -// Destroys the school's data and uploaded files for good. | |
| 4 | -export function deleteSchoolBySlug(slug: string): Promise<void> { | |
| 5 | - return client<void>(`/schools/${encodeURIComponent(slug)}`, { method: "DELETE" }); | |
| 6 | -} |
src/api/schools/deleteSchoolModule.tsmodified+2 -2
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | import { client } from "../client"; |
| 2 | 2 | import type { SchoolModules } from "../client"; |
| 3 | 3 | |
| 4 | -export function deleteSchoolModule(slug: string, module: string): Promise<SchoolModules> { | |
| 5 | - return client<SchoolModules>(`/schools/${encodeURIComponent(slug)}/modules/${encodeURIComponent(module)}`, { | |
| 4 | +export function deleteSchoolModule(id: string, module: string): Promise<SchoolModules> { | |
| 5 | + return client<SchoolModules>(`/schools/${encodeURIComponent(id)}/modules/${encodeURIComponent(module)}`, { | |
| 6 | 6 | method: "DELETE", |
| 7 | 7 | }); |
| 8 | 8 | } |
src/api/schools/getSchool.tsadded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { School } from "../client"; | |
| 3 | + | |
| 4 | +export function getSchool(id: string, signal?: AbortSignal): Promise<School> { | |
| 5 | + return client<School>(`/schools/${encodeURIComponent(id)}`, { signal }); | |
| 6 | +} |
src/api/schools/getSchoolBySlug.tsdeleted+0 -6
| @@ -1,6 +0,0 @@ | ||
| 1 | -import { client } from "../client"; | |
| 2 | -import type { School } from "../client"; | |
| 3 | - | |
| 4 | -export function getSchoolBySlug(slug: string, signal?: AbortSignal): Promise<School> { | |
| 5 | - return client<School>(`/schools/${encodeURIComponent(slug)}`, { signal }); | |
| 6 | -} |
src/api/schools/getSchoolModules.tsmodified+2 -2
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | import { client } from "../client"; |
| 2 | 2 | import type { SchoolModules } from "../client"; |
| 3 | 3 | |
| 4 | -export function getSchoolModules(slug: string, signal?: AbortSignal): Promise<SchoolModules> { | |
| 5 | - return client<SchoolModules>(`/schools/${encodeURIComponent(slug)}/modules`, { signal }); | |
| 4 | +export function getSchoolModules(id: string, signal?: AbortSignal): Promise<SchoolModules> { | |
| 5 | + return client<SchoolModules>(`/schools/${encodeURIComponent(id)}/modules`, { signal }); | |
| 6 | 6 | } |
src/api/schools/index.tsmodified+3 -3
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | export * from "./getSchools"; |
| 2 | -export * from "./getSchoolBySlug"; | |
| 2 | +export * from "./getSchool"; | |
| 3 | 3 | export * from "./postSchool"; |
| 4 | -export * from "./patchSchoolBySlug"; | |
| 5 | -export * from "./deleteSchoolBySlug"; | |
| 4 | +export * from "./patchSchool"; | |
| 5 | +export * from "./deleteSchool"; | |
| 6 | 6 | export * from "./postSchoolAdminPassword"; |
| 7 | 7 | export * from "./postSchoolEnter"; |
| 8 | 8 | export * from "./getSchoolModules"; |
src/api/schools/patchSchool.tsadded+11 -0
| @@ -0,0 +1,11 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { School, SchoolStatus } from "../client"; | |
| 3 | + | |
| 4 | +export type UpdateSchoolBody = { | |
| 5 | + name?: string; | |
| 6 | + status?: SchoolStatus; | |
| 7 | +}; | |
| 8 | + | |
| 9 | +export function patchSchool(id: string, body: UpdateSchoolBody): Promise<School> { | |
| 10 | + return client<School>(`/schools/${encodeURIComponent(id)}`, { method: "PATCH", body }); | |
| 11 | +} |
src/api/schools/patchSchoolBySlug.tsdeleted+0 -11
| @@ -1,11 +0,0 @@ | ||
| 1 | -import { client } from "../client"; | |
| 2 | -import type { School, SchoolStatus } from "../client"; | |
| 3 | - | |
| 4 | -export type UpdateSchoolBody = { | |
| 5 | - name?: string; | |
| 6 | - status?: SchoolStatus; | |
| 7 | -}; | |
| 8 | - | |
| 9 | -export function patchSchoolBySlug(slug: string, body: UpdateSchoolBody): Promise<School> { | |
| 10 | - return client<School>(`/schools/${encodeURIComponent(slug)}`, { method: "PATCH", body }); | |
| 11 | -} |
src/api/schools/patchSchoolModules.tsmodified+2 -2
| @@ -9,6 +9,6 @@ export type PatchSchoolModulesBody = { | ||
| 9 | 9 | }; |
| 10 | 10 | |
| 11 | 11 | // One atomic re-sell: a 409 names every broken dependency and nothing is written. |
| 12 | -export function patchSchoolModules(slug: string, body: PatchSchoolModulesBody): Promise<SchoolModules> { | |
| 13 | - return client<SchoolModules>(`/schools/${encodeURIComponent(slug)}/modules`, { method: "PATCH", body }); | |
| 12 | +export function patchSchoolModules(id: string, body: PatchSchoolModulesBody): Promise<SchoolModules> { | |
| 13 | + return client<SchoolModules>(`/schools/${encodeURIComponent(id)}/modules`, { method: "PATCH", body }); | |
| 14 | 14 | } |
src/api/schools/postSchool.tsmodified+0 -2
| @@ -2,8 +2,6 @@ import { client } from "../client"; | ||
| 2 | 2 | import type { School } from "../client"; |
| 3 | 3 | |
| 4 | 4 | export type CreateSchoolBody = { |
| 5 | - /** Immutable once taken: names the school's database, blobs and cookie prefix. */ | |
| 6 | - slug: string; | |
| 7 | 5 | name: string; |
| 8 | 6 | admin_username: string; |
| 9 | 7 | admin_password: string; |
src/api/schools/postSchoolAdminPassword.tsmodified+2 -2
| @@ -6,6 +6,6 @@ export type SchoolAdminPasswordBody = { | ||
| 6 | 6 | }; |
| 7 | 7 | |
| 8 | 8 | // Re-keys an admin of that school and revokes every session the account held. |
| 9 | -export function postSchoolAdminPassword(slug: string, body: SchoolAdminPasswordBody): Promise<void> { | |
| 10 | - return client<void>(`/schools/${encodeURIComponent(slug)}/admin-password`, { method: "POST", body }); | |
| 9 | +export function postSchoolAdminPassword(id: string, body: SchoolAdminPasswordBody): Promise<void> { | |
| 10 | + return client<void>(`/schools/${encodeURIComponent(id)}/admin-password`, { method: "POST", body }); | |
| 11 | 11 | } |
src/api/schools/postSchoolEnter.tsmodified+2 -2
| @@ -3,6 +3,6 @@ import type { User } from "../client"; | ||
| 3 | 3 | |
| 4 | 4 | // Support access: swaps the builder cookie for an ordinary session of one of |
| 5 | 5 | // the school's admins. Refused (403) on a suspended school. |
| 6 | -export function postSchoolEnter(slug: string, body: { username: string }): Promise<User> { | |
| 7 | - return client<User>(`/schools/${encodeURIComponent(slug)}/enter`, { method: "POST", body }); | |
| 6 | +export function postSchoolEnter(id: string, body: { username: string }): Promise<User> { | |
| 7 | + return client<User>(`/schools/${encodeURIComponent(id)}/enter`, { method: "POST", body }); | |
| 8 | 8 | } |
src/api/schools/postSchoolModule.tsmodified+2 -2
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | import { client } from "../client"; |
| 2 | 2 | import type { SchoolModules } from "../client"; |
| 3 | 3 | |
| 4 | -export function postSchoolModule(slug: string, module: string): Promise<SchoolModules> { | |
| 5 | - return client<SchoolModules>(`/schools/${encodeURIComponent(slug)}/modules/${encodeURIComponent(module)}`, { | |
| 4 | +export function postSchoolModule(id: string, module: string): Promise<SchoolModules> { | |
| 5 | + return client<SchoolModules>(`/schools/${encodeURIComponent(id)}/modules/${encodeURIComponent(module)}`, { | |
| 6 | 6 | method: "POST", |
| 7 | 7 | }); |
| 8 | 8 | } |
src/components/builder/create-school-panel.tsxmodified+0 -10
| @@ -13,8 +13,6 @@ import { Label } from "@/components/ui/label"; | ||
| 13 | 13 | import { SidePanel } from "@/components/ui/side-panel"; |
| 14 | 14 | import { useT } from "@/stores/preferences-context"; |
| 15 | 15 | |
| 16 | -const SLUG_PATTERN = "[a-z0-9][a-z0-9-]+"; | |
| 17 | - | |
| 18 | 16 | /** Creates a school with its first admin and, optionally, a hand-picked module set. */ |
| 19 | 17 | export function CreateSchoolPanel(props: { open: boolean; onOpenChange: (open: boolean) => void; onCreated: (school: School) => void }) { |
| 20 | 18 | const t = useT(); |
| @@ -23,7 +21,6 @@ export function CreateSchoolPanel(props: { open: boolean; onOpenChange: (open: b | ||
| 23 | 21 | () => props.open || undefined, |
| 24 | 22 | () => getLimits().catch(() => null), |
| 25 | 23 | ); |
| 26 | - const [slug, setSlug] = createSignal(""); | |
| 27 | 24 | const [name, setName] = createSignal(""); |
| 28 | 25 | const [adminUsername, setAdminUsername] = createSignal(""); |
| 29 | 26 | const [adminPassword, setAdminPassword] = createSignal(""); |
| @@ -33,7 +30,6 @@ export function CreateSchoolPanel(props: { open: boolean; onOpenChange: (open: b | ||
| 33 | 30 | const [pending, setPending] = createSignal(false); |
| 34 | 31 | |
| 35 | 32 | const reset = () => { |
| 36 | - setSlug(""); | |
| 37 | 33 | setName(""); |
| 38 | 34 | setAdminUsername(""); |
| 39 | 35 | setAdminPassword(""); |
| @@ -50,7 +46,6 @@ export function CreateSchoolPanel(props: { open: boolean; onOpenChange: (open: b | ||
| 50 | 46 | setPending(true); |
| 51 | 47 | try { |
| 52 | 48 | const school = await postSchool({ |
| 53 | - slug: slug().trim(), | |
| 54 | 49 | name: name().trim(), |
| 55 | 50 | admin_username: adminUsername().trim(), |
| 56 | 51 | admin_password: adminPassword(), |
| @@ -83,11 +78,6 @@ export function CreateSchoolPanel(props: { open: boolean; onOpenChange: (open: b | ||
| 83 | 78 | <Alert variant="destructive">{error()}</Alert> |
| 84 | 79 | </Show> |
| 85 | 80 | <div class="grid gap-4 sm:grid-cols-2"> |
| 86 | - <div class="space-y-1.5"> | |
| 87 | - <Label for="school-slug">{t("builder.slug")}</Label> | |
| 88 | - <Input id="school-slug" class="rounded-lg" required pattern={SLUG_PATTERN} minlength={limits()?.user.min_slug_len ?? 2} maxlength={limits()?.user.max_slug_len ?? 32} value={slug()} onInput={(e) => setSlug(e.currentTarget.value.toLowerCase())} /> | |
| 89 | - <p class="text-xs text-text-subtle">{t("builder.slugHint")}</p> | |
| 90 | - </div> | |
| 91 | 81 | <div class="space-y-1.5"> |
| 92 | 82 | <Label for="school-name">{t("builder.schoolName")}</Label> |
| 93 | 83 | <Input id="school-name" class="rounded-lg" required maxlength={limits()?.user.max_school_name_len ?? 120} value={name()} onInput={(e) => setName(e.currentTarget.value)} /> |
src/components/builder/school-admin-access-panel.tsxmodified+3 -3
| @@ -16,7 +16,7 @@ export type AdminAccessMode = "enter" | "password"; | ||
| 16 | 16 | * re-keys the admin and revokes every session it held. |
| 17 | 17 | */ |
| 18 | 18 | export function SchoolAdminAccessPanel(props: { |
| 19 | - slug: string; | |
| 19 | + id: string; | |
| 20 | 20 | mode: AdminAccessMode | null; |
| 21 | 21 | onClose: () => void; |
| 22 | 22 | onEntered: () => void; |
| @@ -40,11 +40,11 @@ export function SchoolAdminAccessPanel(props: { | ||
| 40 | 40 | setPending(true); |
| 41 | 41 | try { |
| 42 | 42 | if (props.mode === "enter") { |
| 43 | - await postSchoolEnter(props.slug, { username: username().trim() }); | |
| 43 | + await postSchoolEnter(props.id, { username: username().trim() }); | |
| 44 | 44 | reset(); |
| 45 | 45 | props.onEntered(); |
| 46 | 46 | } else { |
| 47 | - await postSchoolAdminPassword(props.slug, { username: username().trim(), password: password() }); | |
| 47 | + await postSchoolAdminPassword(props.id, { username: username().trim(), password: password() }); | |
| 48 | 48 | reset(); |
| 49 | 49 | props.onPasswordReset(); |
| 50 | 50 | } |
src/i18n/locales/en.tsmodified+1 -4
| @@ -524,8 +524,6 @@ export const en: Dict = { | ||
| 524 | 524 | "builder.statusSuspended": "Suspended", |
| 525 | 525 | "builder.createSchool": "New school", |
| 526 | 526 | "builder.createSchoolHint": "Creates the school's database and its first admin in one step.", |
| 527 | - "builder.slug": "School code", | |
| 528 | - "builder.slugHint": "Lowercase letters, digits and hyphens. Cannot be changed later.", | |
| 529 | 527 | "builder.schoolName": "School name", |
| 530 | 528 | "builder.adminUsername": "Admin username", |
| 531 | 529 | "builder.adminPassword": "Admin password", |
| @@ -784,7 +782,7 @@ export const en: Dict = { | ||
| 784 | 782 | "auth.register": "Create account", |
| 785 | 783 | "auth.username": "Username", |
| 786 | 784 | "auth.school": "School", |
| 787 | - "auth.schoolHint": "{min}–{max} characters", | |
| 785 | + "auth.noSchoolOpen": "No school is open for registration.", | |
| 788 | 786 | "auth.password": "Password", |
| 789 | 787 | "auth.noAccount": "New here?", |
| 790 | 788 | "auth.hasAccount": "Already registered?", |
| @@ -803,7 +801,6 @@ export const en: Dict = { | ||
| 803 | 801 | "auth.hidePassword": "Hide password", |
| 804 | 802 | "auth.showConfirmPassword": "Show password confirmation", |
| 805 | 803 | "auth.hideConfirmPassword": "Hide password confirmation", |
| 806 | - "auth.schoolCodeHint": "The school code your school gave you (not the school's name): lowercase letters, digits and hyphens, {min}–{max} characters.", | |
| 807 | 804 | "auth.passwordMinHint": "At least {min} characters.", |
| 808 | 805 | "auth.passwordTooShort": "The password needs at least {min} characters.", |
| 809 | 806 | "auth.welcomeBack": "Good to see you again", |
src/i18n/locales/tr.tsmodified+1 -4
| @@ -520,8 +520,6 @@ export const tr: Dict = { | ||
| 520 | 520 | "builder.statusSuspended": "Askıda", |
| 521 | 521 | "builder.createSchool": "Yeni okul", |
| 522 | 522 | "builder.createSchoolHint": "Okulun veritabanını ve ilk yöneticisini tek adımda oluşturur.", |
| 523 | - "builder.slug": "Okul kodu", | |
| 524 | - "builder.slugHint": "Küçük harf, rakam ve tire. Sonradan değiştirilemez.", | |
| 525 | 523 | "builder.schoolName": "Okul adı", |
| 526 | 524 | "builder.adminUsername": "Yönetici kullanıcı adı", |
| 527 | 525 | "builder.adminPassword": "Yönetici şifresi", |
| @@ -780,7 +778,7 @@ export const tr: Dict = { | ||
| 780 | 778 | "auth.register": "Hesap oluştur", |
| 781 | 779 | "auth.username": "Kullanıcı adı", |
| 782 | 780 | "auth.school": "Okul", |
| 783 | - "auth.schoolHint": "{min}–{max} karakter", | |
| 781 | + "auth.noSchoolOpen": "Kayıta açık bir okul yok.", | |
| 784 | 782 | "auth.password": "Şifre", |
| 785 | 783 | "auth.noAccount": "Yeni misin?", |
| 786 | 784 | "auth.hasAccount": "Zaten kayıtlı mısın?", |
| @@ -799,7 +797,6 @@ export const tr: Dict = { | ||
| 799 | 797 | "auth.hidePassword": "Şifreyi gizle", |
| 800 | 798 | "auth.showConfirmPassword": "Şifre onayını göster", |
| 801 | 799 | "auth.hideConfirmPassword": "Şifre onayını gizle", |
| 802 | - "auth.schoolCodeHint": "Okulunun sana ilettiği okul kodu (okul adı değil): küçük harf, rakam ve tire, {min}–{max} karakter.", | |
| 803 | 800 | "auth.passwordMinHint": "En az {min} karakter.", |
| 804 | 801 | "auth.passwordTooShort": "Şifre en az {min} karakter olmalı.", |
| 805 | 802 | "auth.welcomeBack": "Seni yeniden görmek güzel", |
src/i18n/messages.tsmodified+1 -4
| @@ -487,8 +487,6 @@ export type MessageKey = | ||
| 487 | 487 | | "builder.statusSuspended" |
| 488 | 488 | | "builder.createSchool" |
| 489 | 489 | | "builder.createSchoolHint" |
| 490 | - | "builder.slug" | |
| 491 | - | "builder.slugHint" | |
| 492 | 490 | | "builder.schoolName" |
| 493 | 491 | | "builder.adminUsername" |
| 494 | 492 | | "builder.adminPassword" |
| @@ -771,7 +769,7 @@ export type MessageKey = | ||
| 771 | 769 | | "auth.register" |
| 772 | 770 | | "auth.username" |
| 773 | 771 | | "auth.school" |
| 774 | - | "auth.schoolHint" | |
| 772 | + | "auth.noSchoolOpen" | |
| 775 | 773 | | "auth.password" |
| 776 | 774 | | "auth.noAccount" |
| 777 | 775 | | "auth.hasAccount" |
| @@ -790,7 +788,6 @@ export type MessageKey = | ||
| 790 | 788 | | "auth.hidePassword" |
| 791 | 789 | | "auth.showConfirmPassword" |
| 792 | 790 | | "auth.hideConfirmPassword" |
| 793 | - | "auth.schoolCodeHint" | |
| 794 | 791 | | "auth.passwordMinHint" |
| 795 | 792 | | "auth.passwordTooShort" |
| 796 | 793 | | "auth.welcomeBack" |
src/lib/dev-auto-login.tsmodified+2 -2
| @@ -6,7 +6,7 @@ const SKIP_KEY = "hezarfen:dev-auto-login-off"; | ||
| 6 | 6 | /** |
| 7 | 7 | * Development-only sign-in with credentials from `.env.local` |
| 8 | 8 | * (`VITE_DEV_AUTOLOGIN_USERNAME`, `VITE_DEV_AUTOLOGIN_PASSWORD`, optional |
| 9 | - * `VITE_DEV_AUTOLOGIN_SCHOOL`). `import.meta.env.DEV` is a build-time false in | |
| 9 | + * `VITE_DEV_AUTOLOGIN_SCHOOL`, a school uuid). `import.meta.env.DEV` is a build-time false in | |
| 10 | 10 | * `vite build`, so the whole body is dropped from production bundles. |
| 11 | 11 | * An explicit logout turns it off for the rest of the tab. |
| 12 | 12 | */ |
| @@ -18,7 +18,7 @@ export async function devAutoLogin(): Promise<User | null> { | ||
| 18 | 18 | try { |
| 19 | 19 | const result = await postLogin({ username, password }); |
| 20 | 20 | if (!("schools" in result)) return result; |
| 21 | - const school = import.meta.env.VITE_DEV_AUTOLOGIN_SCHOOL || result.schools[0]?.slug; | |
| 21 | + const school = import.meta.env.VITE_DEV_AUTOLOGIN_SCHOOL || result.schools[0]?.id; | |
| 22 | 22 | return school ? await postSelectSchool({ school }) : null; |
| 23 | 23 | } catch (err) { |
| 24 | 24 | console.warn("Dev auto-login failed:", err); |
src/pages/builder-school-detail-page.tsxmodified+14 -14
| @@ -3,11 +3,11 @@ import { createResource } from "@/lib/create-resource"; | ||
| 3 | 3 | import { useNavigate, useParams } from "@tanstack/solid-router"; |
| 4 | 4 | import { getModulesCatalog } from "@/api/modules"; |
| 5 | 5 | import { |
| 6 | - deleteSchoolBySlug, | |
| 6 | + deleteSchool, | |
| 7 | 7 | deleteSchoolModule, |
| 8 | - getSchoolBySlug, | |
| 8 | + getSchool, | |
| 9 | 9 | getSchoolModules, |
| 10 | - patchSchoolBySlug, | |
| 10 | + patchSchool, | |
| 11 | 11 | patchSchoolModules, |
| 12 | 12 | postSchoolModule, |
| 13 | 13 | } from "@/api/schools"; |
| @@ -51,12 +51,12 @@ function BuilderSchoolDetailContent() { | ||
| 51 | 51 | const { locale } = usePreferences(); |
| 52 | 52 | const auth = useAuth(); |
| 53 | 53 | const navigate = useNavigate(); |
| 54 | - const params = useParams({ from: "/builder/schools/$slug" }); | |
| 55 | - const slug = () => params().slug; | |
| 54 | + const params = useParams({ from: "/builder/schools/$id" }); | |
| 55 | + const id = () => params().id; | |
| 56 | 56 | |
| 57 | - const [school, { refetch: refetchSchool }] = createResource(slug, (value) => getSchoolBySlug(value)); | |
| 57 | + const [school, { refetch: refetchSchool }] = createResource(id, (value) => getSchool(value)); | |
| 58 | 58 | const [catalog] = createResource(() => getModulesCatalog()); |
| 59 | - const [modules] = createResource(slug, (value) => getSchoolModules(value)); | |
| 59 | + const [modules] = createResource(id, (value) => getSchoolModules(value)); | |
| 60 | 60 | |
| 61 | 61 | // The switchboard owns a local copy: each switch is one write whose response |
| 62 | 62 | // is the school's whole new set, so there is nothing to refetch. |
| @@ -105,7 +105,7 @@ function BuilderSchoolDetailContent() { | ||
| 105 | 105 | event.preventDefault(); |
| 106 | 106 | setEditError(""); |
| 107 | 107 | try { |
| 108 | - await patchSchoolBySlug(slug(), { name: name().trim(), status: status() }); | |
| 108 | + await patchSchool(id(), { name: name().trim(), status: status() }); | |
| 109 | 109 | setEditOpen(false); |
| 110 | 110 | await refetchSchool(); |
| 111 | 111 | setFlash(t("common.saved")); |
| @@ -127,7 +127,7 @@ function BuilderSchoolDetailContent() { | ||
| 127 | 127 | <PageHeader |
| 128 | 128 | eyebrow={t("builder.schools")} |
| 129 | 129 | title={current().name} |
| 130 | - description={`${current().slug} · ${t("builder.createdAt")}: ${formatDateTime(current().created_at, locale())}`} | |
| 130 | + description={`${current().id} · ${t("builder.createdAt")}: ${formatDateTime(current().created_at, locale())}`} | |
| 131 | 131 | actions={ |
| 132 | 132 | <div class="flex flex-wrap items-center gap-2"> |
| 133 | 133 | <SchoolStatusBadge status={current().status} /> |
| @@ -180,10 +180,10 @@ function BuilderSchoolDetailContent() { | ||
| 180 | 180 | enabled={enabled()} |
| 181 | 181 | disabled={modulesSaving()} |
| 182 | 182 | onToggle={(module, next) => |
| 183 | - void writeModules(() => (next ? postSchoolModule(slug(), module) : deleteSchoolModule(slug(), module))) | |
| 183 | + void writeModules(() => (next ? postSchoolModule(id(), module) : deleteSchoolModule(id(), module))) | |
| 184 | 184 | } |
| 185 | 185 | onTogglePackage={(pkg, next) => |
| 186 | - void writeModules(() => patchSchoolModules(slug(), next ? { enable_packages: [pkg] } : { disable_packages: [pkg] })) | |
| 186 | + void writeModules(() => patchSchoolModules(id(), next ? { enable_packages: [pkg] } : { disable_packages: [pkg] })) | |
| 187 | 187 | } |
| 188 | 188 | /> |
| 189 | 189 | )} |
| @@ -223,7 +223,7 @@ function BuilderSchoolDetailContent() { | ||
| 223 | 223 | </SidePanel> |
| 224 | 224 | |
| 225 | 225 | <SchoolAdminAccessPanel |
| 226 | - slug={slug()} | |
| 226 | + id={id()} | |
| 227 | 227 | mode={accessMode()} |
| 228 | 228 | onClose={() => setAccessMode(null)} |
| 229 | 229 | onPasswordReset={() => { |
| @@ -244,10 +244,10 @@ function BuilderSchoolDetailContent() { | ||
| 244 | 244 | title={t("builder.deleteSchool")} |
| 245 | 245 | description={t("builder.deleteSchoolWarning")} |
| 246 | 246 | variant="destructive" |
| 247 | - summary={school() ? `${school()!.name} · ${school()!.slug}` : ""} | |
| 247 | + summary={school() ? `${school()!.name} · ${school()!.id}` : ""} | |
| 248 | 248 | onConfirm={async () => { |
| 249 | 249 | try { |
| 250 | - await deleteSchoolBySlug(slug()); | |
| 250 | + await deleteSchool(id()); | |
| 251 | 251 | void navigate({ to: "/builder" }); |
| 252 | 252 | } catch (err) { |
| 253 | 253 | setError(formatApiError(err)); |
src/pages/builder-schools-page.tsxmodified+13 -11
| @@ -2,7 +2,7 @@ import { Show, Suspense, createMemo, createSignal } from "solid-js"; | ||
| 2 | 2 | import { createResource } from "@/lib/create-resource"; |
| 3 | 3 | import { useNavigate } from "@tanstack/solid-router"; |
| 4 | 4 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 5 | -import { deleteSchoolBySlug, getSchools, patchSchoolBySlug } from "@/api/schools"; | |
| 5 | +import { deleteSchool, getSchools, patchSchool } from "@/api/schools"; | |
| 6 | 6 | import { formatApiError, type School } from "@/api/client"; |
| 7 | 7 | import { BuilderGuard } from "@/components/builder/builder-guard"; |
| 8 | 8 | import { BuilderHeader } from "@/components/builder/builder-header"; |
| @@ -42,12 +42,12 @@ function BuilderSchoolsContent() { | ||
| 42 | 42 | const [error, setError] = createSignal(""); |
| 43 | 43 | const [flash, setFlash] = createFlash(); |
| 44 | 44 | |
| 45 | - const open = (school: School) => void navigate({ to: "/builder/schools/$slug", params: { slug: school.slug } }); | |
| 45 | + const open = (school: School) => void navigate({ to: "/builder/schools/$id", params: { id: school.id } }); | |
| 46 | 46 | |
| 47 | 47 | const setStatus = async (school: School, status: School["status"]) => { |
| 48 | 48 | setError(""); |
| 49 | 49 | try { |
| 50 | - await patchSchoolBySlug(school.slug, { status }); | |
| 50 | + await patchSchool(school.id, { status }); | |
| 51 | 51 | await refetch(); |
| 52 | 52 | setFlash(t("common.saved")); |
| 53 | 53 | } catch (err) { |
| @@ -59,12 +59,14 @@ function BuilderSchoolsContent() { | ||
| 59 | 59 | { |
| 60 | 60 | accessorKey: "name", |
| 61 | 61 | header: t("builder.schoolName"), |
| 62 | - cell: (cell) => <span class="font-medium">{cell.row.original.name}</span>, | |
| 63 | - }, | |
| 64 | - { | |
| 65 | - accessorKey: "slug", | |
| 66 | - header: t("builder.slug"), | |
| 67 | - cell: (cell) => <span class="mono text-sm">{cell.row.original.slug}</span>, | |
| 62 | + cell: (cell) => ( | |
| 63 | + <span class="block min-w-0"> | |
| 64 | + <span class="block font-medium">{cell.row.original.name}</span> | |
| 65 | + <span class="block truncate font-mono text-xs text-text-subtle" title={cell.row.original.id}> | |
| 66 | + {cell.row.original.id.slice(0, 8)} | |
| 67 | + </span> | |
| 68 | + </span> | |
| 69 | + ), | |
| 68 | 70 | }, |
| 69 | 71 | { |
| 70 | 72 | accessorKey: "status", |
| @@ -157,12 +159,12 @@ function BuilderSchoolsContent() { | ||
| 157 | 159 | title={t("builder.deleteSchool")} |
| 158 | 160 | description={t("builder.deleteSchoolWarning")} |
| 159 | 161 | variant="destructive" |
| 160 | - summary={deleteTarget() ? `${deleteTarget()!.name} · ${deleteTarget()!.slug}` : ""} | |
| 162 | + summary={deleteTarget() ? `${deleteTarget()!.name} · ${deleteTarget()!.id}` : ""} | |
| 161 | 163 | onConfirm={async () => { |
| 162 | 164 | const school = deleteTarget(); |
| 163 | 165 | if (!school) return; |
| 164 | 166 | try { |
| 165 | - await deleteSchoolBySlug(school.slug); | |
| 167 | + await deleteSchool(school.id); | |
| 166 | 168 | await refetch(); |
| 167 | 169 | setFlash(t("common.deleted")); |
| 168 | 170 | } catch (err) { |
src/pages/login-page.test.tsxmodified+3 -3
| @@ -54,8 +54,8 @@ test("logs in without a school and completes the multi-school selection", async | ||
| 54 | 54 | postLogin.mockResolvedValue({ |
| 55 | 55 | username: "ada", |
| 56 | 56 | schools: [ |
| 57 | - { slug: "alpha", name: "Alpha School" }, | |
| 58 | - { slug: "beta", name: "Beta School" }, | |
| 57 | + { id: "019732e3-7b00-7000-8000-00000000dead", name: "Alpha School" }, | |
| 58 | + { id: "019732e3-7b00-7000-8000-00000000beef", name: "Beta School" }, | |
| 59 | 59 | ], |
| 60 | 60 | }); |
| 61 | 61 | postSelectSchool.mockResolvedValue({ id: "u1", username: "ada", role: "student" }); |
| @@ -74,7 +74,7 @@ test("logs in without a school and completes the multi-school selection", async | ||
| 74 | 74 | fireEvent.click(screen.getByText("Alpha School").closest("button")!); |
| 75 | 75 | |
| 76 | 76 | await waitFor(() => { |
| 77 | - expect(postSelectSchool).toHaveBeenCalledWith({ school: "alpha" }); | |
| 77 | + expect(postSelectSchool).toHaveBeenCalledWith({ school: "019732e3-7b00-7000-8000-00000000dead" }); | |
| 78 | 78 | expect(refresh).toHaveBeenCalledOnce(); |
| 79 | 79 | expect(navigate).toHaveBeenCalledWith({ to: "/" }); |
| 80 | 80 | }); |
src/pages/login-page.tsxmodified+3 -3
| @@ -205,14 +205,14 @@ function LoginForm() { | ||
| 205 | 205 | variant="outline" |
| 206 | 206 | class="h-auto w-full justify-start px-4 py-3 text-left" |
| 207 | 207 | disabled={pending()} |
| 208 | - onClick={() => void handleSchoolSelect(school.slug)} | |
| 208 | + onClick={() => void handleSchoolSelect(school.id)} | |
| 209 | 209 | > |
| 210 | 210 | <IconSchool class="h-5 w-5 shrink-0 text-primary-text" /> |
| 211 | 211 | <span class="min-w-0 flex-1"> |
| 212 | 212 | <span class="block truncate font-semibold text-text-strong">{school.name}</span> |
| 213 | - <span class="block truncate text-xs font-normal text-text-subtle">{school.slug}</span> | |
| 213 | + <span class="block truncate text-xs font-normal text-text-subtle">{school.id}</span> | |
| 214 | 214 | </span> |
| 215 | - <Show when={selectingSchool() === school.slug}> | |
| 215 | + <Show when={selectingSchool() === school.id}> | |
| 216 | 216 | <span class="text-xs font-normal text-text-subtle">{t("common.loading")}</span> |
| 217 | 217 | </Show> |
| 218 | 218 | </Button> |
src/pages/register-page.tsxmodified+20 -23
| @@ -1,13 +1,14 @@ | ||
| 1 | 1 | import { Link, useNavigate } from "@tanstack/solid-router"; |
| 2 | -import { createSignal, Show } from "solid-js"; | |
| 2 | +import { For, Show, createSignal } from "solid-js"; | |
| 3 | 3 | import { createResource } from "@/lib/create-resource"; |
| 4 | -import { postRegister } from "@/api/auth"; | |
| 4 | +import { getRegisterSchools, postRegister } from "@/api/auth"; | |
| 5 | 5 | import { getLimits } from "@/api/limits"; |
| 6 | 6 | import { formatApiError } from "@/api/client"; |
| 7 | 7 | import { AuthPageShell } from "@/components/auth/auth-page-shell"; |
| 8 | 8 | import { Button } from "@/components/ui/button"; |
| 9 | 9 | import { Input } from "@/components/ui/input"; |
| 10 | 10 | import { Label } from "@/components/ui/label"; |
| 11 | +import { Select } from "@/components/ui/select"; | |
| 11 | 12 | import { GuestGuard } from "@/components/layout/guest-guard"; |
| 12 | 13 | import { IconEye, IconEyeOff } from "@/components/ui/icons"; |
| 13 | 14 | import { useT } from "@/stores/preferences-context"; |
| @@ -34,8 +35,8 @@ function RegisterForm() { | ||
| 34 | 35 | const [error, setError] = createSignal(""); |
| 35 | 36 | const [pending, setPending] = createSignal(false); |
| 36 | 37 | const [limits] = createResource(() => getLimits().catch(() => null)); |
| 37 | - const minSchoolSlugLength = () => limits()?.user.min_slug_len ?? 2; | |
| 38 | - const maxSchoolSlugLength = () => limits()?.user.max_slug_len ?? 32; | |
| 38 | + const [schools] = createResource(() => getRegisterSchools()); | |
| 39 | + const noSchoolOpen = () => schools.state === "ready" && !schools.error && (schools() ?? []).length === 0; | |
| 39 | 40 | const minPasswordLength = () => limits()?.user.min_password_len ?? 6; |
| 40 | 41 | // Inline checks wait until the reader has left the field (or, for the |
| 41 | 42 | // confirmation, typed as many characters as the password) so they never |
| @@ -53,13 +54,10 @@ function RegisterForm() { | ||
| 53 | 54 | const handleSubmit = async (e: SubmitEvent) => { |
| 54 | 55 | e.preventDefault(); |
| 55 | 56 | const s = school().trim(); |
| 57 | + if (!s) return; | |
| 56 | 58 | const u = username().trim(); |
| 57 | 59 | const p = password(); |
| 58 | 60 | const cp = confirmPassword(); |
| 59 | - if (s.length < minSchoolSlugLength() || s.length > maxSchoolSlugLength()) { | |
| 60 | - setError(t("auth.schoolHint", { min: minSchoolSlugLength(), max: maxSchoolSlugLength() })); | |
| 61 | - return; | |
| 62 | - } | |
| 63 | 61 | const userLimits = limits()?.user; |
| 64 | 62 | if (userLimits && (u.length < userLimits.min_username_len || u.length > userLimits.max_username_len)) { |
| 65 | 63 | setError(t("auth.usernameHint")); |
| @@ -97,24 +95,23 @@ function RegisterForm() { | ||
| 97 | 95 | <form class="space-y-5" onSubmit={handleSubmit}> |
| 98 | 96 | <div class="space-y-2"> |
| 99 | 97 | <Label for="register-school">{t("auth.school")}</Label> |
| 100 | - <Input | |
| 98 | + <Select | |
| 101 | 99 | id="register-school" |
| 102 | 100 | class="h-9" |
| 103 | - autocapitalize="none" | |
| 104 | - autocomplete="off" | |
| 105 | - spellcheck={false} | |
| 106 | - minlength={minSchoolSlugLength()} | |
| 107 | - maxlength={maxSchoolSlugLength()} | |
| 108 | 101 | required |
| 109 | - aria-describedby="register-school-hint" | |
| 102 | + disabled={schools.loading || noSchoolOpen() || Boolean(schools.error)} | |
| 110 | 103 | value={school()} |
| 111 | - // A school code (slug) is lowercase; folding here saves a | |
| 112 | - // round trip for "Ata-Koleji". | |
| 113 | - onInput={(e) => setSchool(e.currentTarget.value.toLowerCase())} | |
| 114 | - /> | |
| 115 | - <p id="register-school-hint" class="text-xs text-text-subtle"> | |
| 116 | - {t("auth.schoolCodeHint", { min: minSchoolSlugLength(), max: maxSchoolSlugLength() })} | |
| 117 | - </p> | |
| 104 | + onChange={(e) => setSchool(e.currentTarget.value)} | |
| 105 | + > | |
| 106 | + <option value="">{t("auth.chooseSchoolTitle")}</option> | |
| 107 | + <For each={schools() ?? []}>{(item) => <option value={item.id}>{item.name}</option>}</For> | |
| 108 | + </Select> | |
| 109 | + <Show when={noSchoolOpen()}> | |
| 110 | + <p class="text-sm text-text-subtle">{t("auth.noSchoolOpen")}</p> | |
| 111 | + </Show> | |
| 112 | + <Show when={schools.error}> | |
| 113 | + <p class="text-sm text-destructive-text">{formatApiError(schools.error)}</p> | |
| 114 | + </Show> | |
| 118 | 115 | </div> |
| 119 | 116 | |
| 120 | 117 | <div class="space-y-2"> |
| @@ -206,7 +203,7 @@ function RegisterForm() { | ||
| 206 | 203 | <p class="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive-text">{error()}</p> |
| 207 | 204 | )} |
| 208 | 205 | |
| 209 | - <Button type="submit" class="h-9 w-full text-sm" disabled={pending()}> | |
| 206 | + <Button type="submit" class="h-9 w-full text-sm" disabled={pending() || schools.loading || noSchoolOpen() || Boolean(schools.error) || !school()}> | |
| 210 | 207 | {pending() ? t("common.loading") : t("auth.register")} |
| 211 | 208 | </Button> |
| 212 | 209 | </form> |
src/routes/router.tsxmodified+1 -1
| @@ -542,7 +542,7 @@ const builderSchoolsRoute = createRoute({ | ||
| 542 | 542 | |
| 543 | 543 | const builderSchoolDetailRoute = createRoute({ |
| 544 | 544 | getParentRoute: () => rootRoute, |
| 545 | - path: "/builder/schools/$slug", | |
| 545 | + path: "/builder/schools/$id", | |
| 546 | 546 | component: BuilderSchoolDetailPage, |
| 547 | 547 | }); |
| 548 | 548 |
src/vite-env.d.tsmodified+1 -0
| @@ -4,6 +4,7 @@ interface ImportMetaEnv { | ||
| 4 | 4 | /** Dev-only auto sign-in (see src/lib/dev-auto-login.ts); set in .env.local, never committed. */ |
| 5 | 5 | readonly VITE_DEV_AUTOLOGIN_USERNAME?: string; |
| 6 | 6 | readonly VITE_DEV_AUTOLOGIN_PASSWORD?: string; |
| 7 | + /** Optional school uuid when login returns a choice list. */ | |
| 7 | 8 | readonly VITE_DEV_AUTOLOGIN_SCHOOL?: string; |
| 8 | 9 | /** Demo account prefilled on the login page (see src/lib/demo-login.ts); bundled when set. */ |
| 9 | 10 | readonly VITE_DEMO_LOGIN_USERNAME?: string; |