Fix admin white screen from circular imports and route guards.

Break teamRoles/adminAccess cycle and restrict reduced navigation to Content Manager only so legacy team roles no longer redirect-loop on dashboard.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Yared Yemane 2026-08-05 12:14:42 +03:00
parent cd490c3dd9
commit feea83a588
3 changed files with 29 additions and 27 deletions

View File

@ -2,13 +2,6 @@ import { getNormalizedSessionTeamRole } from "./teamRole"
export const FULL_PANEL_TEAM_ROLES = new Set(["SUPER_ADMIN", "ADMIN"]) export const FULL_PANEL_TEAM_ROLES = new Set(["SUPER_ADMIN", "ADMIN"])
/** The three assignable staff roles for the admin panel. */
export const STAFF_TEAM_ROLE_OPTIONS = [
{ value: "SUPER_ADMIN", label: "Super Admin" },
{ value: "ADMIN", label: "Admin" },
{ value: "CONTENT_MANAGER", label: "Content Manager" },
] as const
const CONTENT_MANAGER_PATH_PREFIXES = [ const CONTENT_MANAGER_PATH_PREFIXES = [
"/new-content", "/new-content",
"/personas", "/personas",
@ -16,34 +9,38 @@ const CONTENT_MANAGER_PATH_PREFIXES = [
"/content", "/content",
] ]
function normalizedTeamRole(role?: string): string {
return (role ?? getNormalizedSessionTeamRole()).toUpperCase()
}
/** Only Content Manager gets a reduced admin panel; all other roles keep full navigation. */
export function isContentManagerPanelRole(role?: string): boolean {
return normalizedTeamRole(role) === "CONTENT_MANAGER"
}
export function hasFullAdminPanelAccess(role?: string): boolean { export function hasFullAdminPanelAccess(role?: string): boolean {
const r = (role ?? getNormalizedSessionTeamRole()).toUpperCase() const r = normalizedTeamRole(role)
return FULL_PANEL_TEAM_ROLES.has(r) if (!r) return true
return !isContentManagerPanelRole(r)
} }
export function isContentManagerRole(role?: string): boolean { export function isContentManagerRole(role?: string): boolean {
const r = (role ?? getNormalizedSessionTeamRole()).toUpperCase() return isContentManagerPanelRole(role)
return r === "CONTENT_MANAGER"
} }
export function canSendTeamInvitations(role?: string): boolean { export function canSendTeamInvitations(role?: string): boolean {
const r = (role ?? getNormalizedSessionTeamRole()).toUpperCase() return normalizedTeamRole(role) === "SUPER_ADMIN"
return r === "SUPER_ADMIN"
} }
export function isPathAllowedForTeamRole(pathname: string, role?: string): boolean { export function isPathAllowedForTeamRole(pathname: string, role?: string): boolean {
const r = (role ?? getNormalizedSessionTeamRole()).toUpperCase() if (!isContentManagerPanelRole(role)) return true
if (!r || hasFullAdminPanelAccess(r)) return true
if (isContentManagerRole(r)) {
return CONTENT_MANAGER_PATH_PREFIXES.some( return CONTENT_MANAGER_PATH_PREFIXES.some(
(p) => pathname === p || pathname.startsWith(`${p}/`), (p) => pathname === p || pathname.startsWith(`${p}/`),
) )
} }
return pathname === "/profile" || pathname.startsWith("/profile/")
}
export function getDefaultAppHome(role?: string): string { export function getDefaultAppHome(role?: string): string {
if (isContentManagerRole(role)) return "/new-content" if (isContentManagerPanelRole(role)) return "/new-content"
return "/dashboard" return "/dashboard"
} }
@ -61,9 +58,7 @@ export function isNavEntryAllowedForTeamRole(
entry: FilterableNavEntry, entry: FilterableNavEntry,
role?: string, role?: string,
): boolean { ): boolean {
const r = (role ?? getNormalizedSessionTeamRole()).toUpperCase() if (!isContentManagerPanelRole(role)) return true
if (!r || hasFullAdminPanelAccess(r)) return true
if (!isContentManagerRole(r)) return false
if (entry.kind === "section") { if (entry.kind === "section") {
return entry.label === "Learning content" || entry.label === "Account" return entry.label === "Learning content" || entry.label === "Account"

View File

@ -1,5 +1,11 @@
import type { Role } from "../types/rbac.types" import type { Role } from "../types/rbac.types"
import { STAFF_TEAM_ROLE_OPTIONS } from "./adminAccess"
/** The three assignable staff roles for the admin panel. */
export const STAFF_TEAM_ROLE_OPTIONS = [
{ value: "SUPER_ADMIN", label: "Super Admin" },
{ value: "ADMIN", label: "Admin" },
{ value: "CONTENT_MANAGER", label: "Content Manager" },
] as const
export const TEAM_ROLE_OPTIONS = [...STAFF_TEAM_ROLE_OPTIONS] export const TEAM_ROLE_OPTIONS = [...STAFF_TEAM_ROLE_OPTIONS]

View File

@ -43,8 +43,9 @@ import { DEFAULT_TABLE_PAGE_SIZE, TABLE_PAGE_SIZE_OPTIONS } from "../../lib/tabl
import { toast } from "sonner" import { toast } from "sonner"
import { SpinnerIcon } from "../../components/ui/spinner-icon" import { SpinnerIcon } from "../../components/ui/spinner-icon"
import { InviteTeamMemberDialog } from "./components/InviteTeamMemberDialog" import { InviteTeamMemberDialog } from "./components/InviteTeamMemberDialog"
import { canSendTeamInvitations, STAFF_TEAM_ROLE_OPTIONS } from "../../lib/adminAccess" import { canSendTeamInvitations } from "../../lib/adminAccess"
import { getNormalizedSessionTeamRole } from "../../lib/teamRole" import { getNormalizedSessionTeamRole } from "../../lib/teamRole"
import { STAFF_TEAM_ROLE_OPTIONS } from "../../lib/teamRoles"
export function RolesListPage() { export function RolesListPage() {
const navigate = useNavigate() const navigate = useNavigate()