DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(auth): surface teacher and student roles in web UI
Bingxi Zhao (Frank)038b6513ed93
diff --git a/deeptutor/services/auth.py b/deeptutor/services/auth.pyindex 47595e191..a4a952b95 100644--- a/deeptutor/services/auth.py+++ b/deeptutor/services/auth.py@@ -200,7 +200,7 @@ def set_role(username: str, role: str) -> bool:"""Change the role for an existing user. Returns True on success.- Valid roles are the entries of ``VALID_ROLES`` (currently 'admin', 'user').+ Valid roles are the entries of ``VALID_ROLES``."""from deeptutor.multi_user.models import VALID_ROLESdiff --git a/web/app/(admin)/admin/users/page.tsx b/web/app/(admin)/admin/users/page.tsxindex de3c06756..2b9d9795c 100644--- a/web/app/(admin)/admin/users/page.tsx+++ b/web/app/(admin)/admin/users/page.tsx@@ -22,6 +22,7 @@ import { GuardianRelationshipsEditor } from "@/features/multi-user/components/Guimport { UserAvatar } from "@/components/UserAvatar";import { ConfirmDialog } from "@/components/ui/ConfirmDialog";import { filterUsersByQuery } from "@/lib/admin-users";+import { accountRoleLabelKey } from "@/lib/account-role";import {Search,Shield,@@ -562,7 +563,7 @@ export default function AdminUsersPage() {{isAdmin && (<ShieldCheck size={11} strokeWidth={2} />)}- {isAdmin ? t("Admin") : t("User")}+ {t(accountRoleLabelKey(user.role))}</span>{!isAdmin && user.preset && (<span className="mt-1 block text-[11px] text-[var(--muted-foreground)]">@@ -725,10 +726,7 @@ export default function AdminUsersPage() {</p><p className="text-xs text-[var(--muted-foreground)]">{t("{{role}} · joined {{date}}", {- role:- confirmTarget.user.role === "admin"- ? t("Admin")- : t("User"),+ role: t(accountRoleLabelKey(confirmTarget.user.role)),date: formatDate(confirmTarget.user.created_at, lang),})}</p>diff --git a/web/app/(utility)/profile/page.tsx b/web/app/(utility)/profile/page.tsxindex 903d4e43d..a4f9df246 100644--- a/web/app/(utility)/profile/page.tsx+++ b/web/app/(utility)/profile/page.tsx@@ -24,6 +24,7 @@ import {} from "@/components/UserAvatar";import { parseAvatarMarker } from "@/lib/avatar";import { formatDate, type Language } from "@/lib/datetime";+import { accountRoleLabelKey } from "@/lib/account-role";const AVATAR_OUTPUT_SIZE = 256;// Decoding a huge photo just to throw away most pixels wastes memory; the@@ -262,7 +263,7 @@ export default function ProfilePage() {}`}>{isAdmin && <ShieldCheck size={11} strokeWidth={2} />}- {isAdmin ? t("Administrator") : t("User")}+ {isAdmin ? t("Administrator") : t(accountRoleLabelKey(profile.role))}</span></div>{joined && (diff --git a/web/features/multi-user/components/GuardianRelationshipsEditor.tsx b/web/features/multi-user/components/GuardianRelationshipsEditor.tsxindex 93eeecd60..cbf5f0789 100644--- a/web/features/multi-user/components/GuardianRelationshipsEditor.tsx+++ b/web/features/multi-user/components/GuardianRelationshipsEditor.tsx@@ -89,7 +89,7 @@ export function GuardianRelationshipsEditor({);const candidates = users.filter((user) =>- user.role === "user" &&+ user.role !== "admin" &&user.id !== learnerId &&user.preset !== "learner" &&!activeGuardianIds.has(user.id),diff --git a/web/lib/account-role.ts b/web/lib/account-role.tsnew file mode 100644index 000000000..b5544be0c--- /dev/null+++ b/web/lib/account-role.ts@@ -0,0 +1,13 @@+/** Account roles accepted by the local user store. Only admin grants elevation. */+export type AccountRole = "admin" | "teacher" | "student" | "user";++const LABEL_KEYS: Record<AccountRole, "Admin" | "Teacher" | "Student" | "User"> = {+ admin: "Admin",+ teacher: "Teacher",+ student: "Student",+ user: "User",+};++export function accountRoleLabelKey(role: AccountRole): string {+ return LABEL_KEYS[role];+}diff --git a/web/lib/admin-api.ts b/web/lib/admin-api.tsindex 0480beac5..a1b1868c2 100644--- a/web/lib/admin-api.ts+++ b/web/lib/admin-api.ts@@ -1,11 +1,12 @@import { apiFetch, apiUrl } from "@/lib/api";+import type { AccountRole } from "@/lib/account-role";export type AccountPreset = "standard" | "learner" | "custom";export interface UserRecord {id: string;username: string;- role: "admin" | "user";+ role: AccountRole;created_at: string;disabled?: boolean;/** Avatar marker: "", "icon:<name>:<color>", or "img:<version>". */@@ -142,7 +143,7 @@ export async function deleteUsers(export async function setUserRole(username: string,- role: "admin" | "user",+ role: AccountRole,): Promise<void> {const res = await apiFetch(apiUrl(`/api/auth/users/${encodeURIComponent(username)}/role`),@@ -161,7 +162,7 @@ export async function setUserRole(export interface CreatedUser {user_id: string;username: string;- role: "admin" | "user";+ role: AccountRole;is_admin: boolean;preset: AccountPreset;}diff --git a/web/lib/profile-api.ts b/web/lib/profile-api.tsindex bb79daf71..bdf10d4ef 100644--- a/web/lib/profile-api.ts+++ b/web/lib/profile-api.ts@@ -1,4 +1,5 @@import { apiFetch, apiUrl } from "@/lib/api";+import type { AccountRole } from "@/lib/account-role";export interface LearnerProfile {age?: number;@@ -36,7 +37,7 @@ export async function setOwnLearnerProfile(export interface ProfileInfo {id: string;username: string;- role: "admin" | "user";+ role: AccountRole;created_at: string;disabled?: boolean;/** Avatar marker: "", "icon:<name>:<color>", or "img:<version>". */diff --git a/web/locales/de/app.json b/web/locales/de/app.jsonindex 41478138a..a2847e439 100644--- a/web/locales/de/app.json+++ b/web/locales/de/app.json@@ -330,6 +330,7 @@"Open navigation": "Navigation öffnen","Chat Session": "Chat-Sitzung","User": "Benutzer",+ "Student": "Schüler","Assistant": "Assistent","Select Source (Cross-Notebook)": "Quelle auswählen (Notebook-übergreifend)","Clear": "Leeren",diff --git a/web/locales/en/app.json b/web/locales/en/app.jsonindex 67039a330..e2164f521 100644--- a/web/locales/en/app.json+++ b/web/locales/en/app.json@@ -330,6 +330,7 @@"Open navigation": "Open navigation","Chat Session": "Chat Session","User": "User",+ "Student": "Student","Assistant": "Assistant","Select Source (Cross-Notebook)": "Select Source (Cross-Notebook)","Clear": "Clear",diff --git a/web/locales/fr/app.json b/web/locales/fr/app.jsonindex b7bb09308..a14a6975c 100644--- a/web/locales/fr/app.json+++ b/web/locales/fr/app.json@@ -420,6 +420,8 @@"No records in this notebook": "Aucune fiche dans ce carnet","Chat Session": "Session de conversation","User": "Utilisateur",+ "Teacher": "Enseignant",+ "Student": "Élève","Assistant": "Assistant","Multi-agent reasoning": "Raisonnement multi-agents","Auto-validated quizzes": "Quiz à validation automatique",diff --git a/web/locales/uk/app.json b/web/locales/uk/app.jsonindex 3ab0b9c92..0754ecaff 100644--- a/web/locales/uk/app.json+++ b/web/locales/uk/app.json@@ -316,6 +316,7 @@"Open navigation": "Відкрити навігацію","Chat Session": "Сесія чату","User": "Користувач",+ "Student": "Учень","Assistant": "Асистент","Select Source (Cross-Notebook)": "Вибрати джерело (між робочими зошитами)","Clear": "Очистити",diff --git a/web/locales/zh/app.json b/web/locales/zh/app.jsonindex 6d5562b3a..be072f4ac 100644--- a/web/locales/zh/app.json+++ b/web/locales/zh/app.json@@ -330,6 +330,7 @@"Open navigation": "打开导航","Chat Session": "聊天会话","User": "用户",+ "Student": "学生","Assistant": "助手","Select Source (Cross-Notebook)": "选择来源(跨笔记本)","Clear": "清空",diff --git a/web/tests/account-role.test.ts b/web/tests/account-role.test.tsnew file mode 100644index 000000000..fffccddc7--- /dev/null+++ b/web/tests/account-role.test.ts@@ -0,0 +1,23 @@+import assert from "node:assert/strict";+import { readFileSync } from "node:fs";+import path from "node:path";+import test from "node:test";++import { accountRoleLabelKey } from "../lib/account-role";++test("all account roles retain distinct display labels", () => {+ assert.equal(accountRoleLabelKey("admin"), "Admin");+ assert.equal(accountRoleLabelKey("teacher"), "Teacher");+ assert.equal(accountRoleLabelKey("student"), "Student");+ assert.equal(accountRoleLabelKey("user"), "User");++ for (const language of ["en", "zh", "de", "fr", "uk"]) {+ const labels = JSON.parse(+ readFileSync(path.resolve(process.cwd(), `locales/${language}/app.json`), "utf8"),+ ) as Record<string, string>;+ for (const role of ["Teacher", "Student"]) {+ assert.ok(labels[role], `${language} is missing ${role}`);+ assert.notEqual(labels[role], labels.User, `${language} displays ${role} as User`);+ }+ }+});