diff --git a/src/api/getUserSearch.ts b/src/api/getUserSearch.ts index 789e40b..739d5ec 100644 --- a/src/api/getUserSearch.ts +++ b/src/api/getUserSearch.ts @@ -5,11 +5,11 @@ import type { PersonRef, Role } from "./types"; export async function getUserSearch( query: string, signal?: AbortSignal, - role?: Role, + role?: Role | Role[], page?: PageParams, ): Promise> { const params = new URLSearchParams({ q: query }); - if (role) params.set("role", role); + if (role) params.set("role", Array.isArray(role) ? role.join(",") : role); appendPageParams(params, page); const data = await client(`/users/search?${params.toString()}`, { signal }); return normalizePage(data); diff --git a/src/components/layout/route-guard.tsx b/src/components/layout/route-guard.tsx index 054e420..f13eb8b 100644 --- a/src/components/layout/route-guard.tsx +++ b/src/components/layout/route-guard.tsx @@ -3,13 +3,15 @@ import { type ParentProps, Show } from "solid-js"; import type { Role } from "@/api/types"; import { Alert } from "@/components/ui/alert"; import { PageSpinner } from "@/components/ui/page-spinner"; -import { hasExactRole, hasMinRole } from "@/lib/roles"; +import { hasExactRole, roleInRange } from "@/lib/roles"; import { useAuth } from "@/stores/auth-context"; import { useT } from "@/stores/preferences-context"; export function RouteGuard( props: ParentProps<{ minRole?: Role; + /** Inclusive upper bound (e.g. maxRole: "manager" excludes admin). */ + maxRole?: Role; /** When set, only this exact role may enter (e.g. student-only pages). */ exactRole?: Role; }>, @@ -19,7 +21,7 @@ export function RouteGuard( const allowed = (role: Role) => { if (props.exactRole) return hasExactRole(role, props.exactRole); - if (props.minRole) return hasMinRole(role, props.minRole); + if (props.minRole || props.maxRole) return roleInRange(role, props.minRole, props.maxRole); return true; }; diff --git a/src/components/layout/side-nav.tsx b/src/components/layout/side-nav.tsx index 06c3dc7..9300160 100644 --- a/src/components/layout/side-nav.tsx +++ b/src/components/layout/side-nav.tsx @@ -8,7 +8,7 @@ import { } from "@/components/ui/dropdown-menu"; import { useAuth } from "@/stores/auth-context"; import { useT } from "@/stores/preferences-context"; -import { hasExactRole, hasMinRole } from "@/lib/roles"; +import { hasExactRole, hasMinRole, roleInRange } from "@/lib/roles"; import { cn } from "@/lib/cn"; import type { MessageKey } from "@/i18n/messages"; import type { Role } from "@/api/types"; @@ -34,6 +34,8 @@ type NavItem = { labelKey: MessageKey; Icon: Component<{ class?: string }>; minRole?: Role; + /** Inclusive upper bound (e.g. hide from admin with maxRole: "manager"). */ + maxRole?: Role; /** When set, only this exact role sees the item. */ exactRole?: Role; exact?: boolean; @@ -83,7 +85,7 @@ const NAV_GROUPS: NavGroup[] = [ items: [ { to: "/management/student-marks", labelKey: "nav.studentMarks", Icon: IconChart, minRole: "teacher" }, { to: "/management/student-attendance", labelKey: "nav.studentAttendance", Icon: IconClipboardCheck, minRole: "teacher" }, - { to: "/work", labelKey: "nav.work", Icon: IconReportAnalytics, minRole: "teacher" }, + { to: "/work", labelKey: "nav.work", Icon: IconReportAnalytics, minRole: "teacher", maxRole: "manager" }, { to: "/management/staff-work", labelKey: "nav.staffWork", Icon: IconReportAnalytics, minRole: "manager" }, ], }, @@ -161,7 +163,7 @@ export function SideNav(props: { onNavigate?: () => void; collapsed?: boolean }) const itemVisible = (item: NavItem) => { const role = auth.user()?.role; if (item.exactRole) return hasExactRole(role, item.exactRole); - if (item.minRole) return hasMinRole(role, item.minRole); + if (item.minRole || item.maxRole) return roleInRange(role, item.minRole, item.maxRole); return true; }; diff --git a/src/components/users/user-search-select.tsx b/src/components/users/user-search-select.tsx index 83ba3c6..e11beb4 100644 --- a/src/components/users/user-search-select.tsx +++ b/src/components/users/user-search-select.tsx @@ -20,7 +20,7 @@ export function UserSearchSelect(props: { emptyMessage?: string; disabled?: boolean; allowManualValue?: boolean; - role?: Role; + role?: Role | Role[]; }) { let inputRef: HTMLInputElement | undefined; const t = useT(); diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index c0ba99f..5af40b1 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -494,7 +494,9 @@ export type MessageKey = | "work.correctHelp" | "work.cannotEditOpen" | "work.timesRequired" - | "work.deleteSummary"; + | "work.deleteSummary" + | "work.teacherIdentity" + | "work.noTeachers"; type Dict = Record; @@ -998,7 +1000,9 @@ const en: Dict = { "work.closed": "Closed", "work.status": "Status", "work.staffTitle": "Staff work logs", - "work.staffSubtitle": "Look up a staff member, correct closed stints, or delete entries.", + "work.staffSubtitle": "Look up a teacher, correct closed stints, or delete entries.", + "work.teacherIdentity": "Teacher", + "work.noTeachers": "No teachers found.", "work.show": "Show log", "work.forUser": "Log for {user}", "work.correct": "Correct entry", @@ -1508,7 +1512,9 @@ const tr: Dict = { "work.closed": "Kapalı", "work.status": "Durum", "work.staffTitle": "Personel mesai kayıtları", - "work.staffSubtitle": "Personel ara, kapalı mesaileri düzelt veya kayıt sil.", + "work.staffSubtitle": "Öğretmen ara, kapalı mesaileri düzelt veya kayıt sil.", + "work.teacherIdentity": "Öğretmen", + "work.noTeachers": "Öğretmen bulunamadı.", "work.show": "Kaydı göster", "work.forUser": "{user} için kayıtlar", "work.correct": "Kaydı düzelt", diff --git a/src/lib/roles.ts b/src/lib/roles.ts index 6c611cd..3d84176 100644 --- a/src/lib/roles.ts +++ b/src/lib/roles.ts @@ -12,8 +12,25 @@ export function hasMinRole(role: Role | undefined | null, min: Role): boolean { return RANK[role] >= RANK[min]; } +export function hasMaxRole(role: Role | undefined | null, max: Role): boolean { + if (!role) return false; + return RANK[role] <= RANK[max]; +} + export function hasExactRole(role: Role | undefined | null, exact: Role): boolean { return role === exact; } +/** Inclusive role band: minRole <= role <= maxRole. */ +export function roleInRange( + role: Role | undefined | null, + min?: Role, + max?: Role, +): boolean { + if (!role) return false; + if (min && !hasMinRole(role, min)) return false; + if (max && !hasMaxRole(role, max)) return false; + return true; +} + export const ROLES: Role[] = ["student", "teacher", "manager", "admin"]; diff --git a/src/pages/dashboard-page.tsx b/src/pages/dashboard-page.tsx index 065bfe5..c04b214 100644 --- a/src/pages/dashboard-page.tsx +++ b/src/pages/dashboard-page.tsx @@ -206,12 +206,19 @@ function DashboardContent() { { icon: , titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec, statSuffix: "dashboard.records", accent: "amber" }, { icon: , titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc, statSuffix: "dashboard.records", accent: "sky" }, { icon: , titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc, statSuffix: "dashboard.records", accent: "sky" }, - { icon: , titleKey: "nav.work", to: "/work", descKey: "dashboard.portal.workDesc", stat: "", accent: "amber", minRole: "teacher" }, { icon: , titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", stat: "", accent: "mint", minRole: "teacher" }, { icon: , titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", stat: "", accent: "rose", minRole: "teacher" }, { icon: , titleKey: "nav.settings", to: "/management/settings", descKey: "dashboard.portal.settingsDesc", stat: "", accent: "mint", minRole: "manager" }, { icon: , titleKey: "nav.terms", to: "/management/terms", descKey: "dashboard.portal.termsDesc", stat: "", accent: "rose", minRole: "manager" }, ); + if (roleVal === "manager") { + list.push( + { icon: , titleKey: "nav.work", to: "/work", descKey: "dashboard.portal.workDesc", stat: "", accent: "amber", minRole: "teacher" }, + ); + } + list.push( + { icon: , titleKey: "nav.staffWork", to: "/management/staff-work", descKey: "dashboard.portal.workDesc", stat: "", accent: "amber", minRole: "manager" }, + ); if (roleVal === "admin") { list.push( { icon: , titleKey: "nav.users", to: "/admin/users", descKey: "dashboard.portal.usersDesc", stat: "", accent: "rose", minRole: "admin" }, diff --git a/src/pages/staff-work-page.tsx b/src/pages/staff-work-page.tsx index dabe2ca..2d4f2a7 100644 --- a/src/pages/staff-work-page.tsx +++ b/src/pages/staff-work-page.tsx @@ -166,14 +166,15 @@ function StaffWorkContent() { >