Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-school (push) Successful in 25s
CI / test-go-edu-search (push) Successful in 26s
CI / test-python-klausur (push) Failing after 1m55s
CI / test-python-agent-core (push) Successful in 16s
CI / test-nodejs-website (push) Successful in 18s
- Voice-Service von Core nach Lehrer verschoben (bp-lehrer-voice-service) - 4 Jitsi-Services + 2 Synapse-Services in docker-compose.yml aufgenommen - Camunda komplett gelöscht: workflow pages, workflow-config.ts, bpmn-js deps - CAMUNDA_URL aus backend-lehrer environment entfernt - Sidebar: Kategorie "Compliance SDK" + "Katalogverwaltung" entfernt - Sidebar: Neue Kategorie "Kommunikation" mit Video & Chat, Voice Service, Alerts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
101 lines
2.7 KiB
TypeScript
101 lines
2.7 KiB
TypeScript
/**
|
|
* Role-based Access System for Admin v2
|
|
*
|
|
* Roles determine which categories and modules are visible
|
|
*/
|
|
|
|
import { CategoryId } from './navigation'
|
|
|
|
export type RoleId = 'developer' | 'manager' | 'auditor' | 'dsb'
|
|
|
|
export interface Role {
|
|
id: RoleId
|
|
name: string
|
|
description: string
|
|
icon: string
|
|
visibleCategories: CategoryId[]
|
|
color: string
|
|
}
|
|
|
|
export const roles: Role[] = [
|
|
{
|
|
id: 'developer',
|
|
name: 'Entwickler',
|
|
description: 'Voller Zugriff auf alle Bereiche',
|
|
icon: 'code',
|
|
visibleCategories: ['communication', 'ai', 'education', 'website'],
|
|
color: 'bg-primary-100 border-primary-300 text-primary-700',
|
|
},
|
|
{
|
|
id: 'manager',
|
|
name: 'Manager',
|
|
description: 'Executive Uebersicht',
|
|
icon: 'chart',
|
|
visibleCategories: ['communication', 'website'],
|
|
color: 'bg-blue-100 border-blue-300 text-blue-700',
|
|
},
|
|
{
|
|
id: 'auditor',
|
|
name: 'Auditor',
|
|
description: 'Compliance Pruefung',
|
|
icon: 'clipboard',
|
|
visibleCategories: ['communication'],
|
|
color: 'bg-amber-100 border-amber-300 text-amber-700',
|
|
},
|
|
{
|
|
id: 'dsb',
|
|
name: 'DSB',
|
|
description: 'Datenschutzbeauftragter',
|
|
icon: 'shield',
|
|
visibleCategories: ['communication'],
|
|
color: 'bg-purple-100 border-purple-300 text-purple-700',
|
|
},
|
|
]
|
|
|
|
// Storage key for localStorage
|
|
const ROLE_STORAGE_KEY = 'admin-v2-selected-role'
|
|
|
|
// Get role by ID
|
|
export function getRoleById(id: RoleId): Role | undefined {
|
|
return roles.find(role => role.id === id)
|
|
}
|
|
|
|
// Check if category is visible for a role
|
|
export function isCategoryVisibleForRole(categoryId: CategoryId, roleId: RoleId): boolean {
|
|
const role = getRoleById(roleId)
|
|
return role ? role.visibleCategories.includes(categoryId) : false
|
|
}
|
|
|
|
// Get stored role from localStorage (client-side only)
|
|
export function getStoredRole(): RoleId | null {
|
|
if (typeof window === 'undefined') return null
|
|
const stored = localStorage.getItem(ROLE_STORAGE_KEY)
|
|
if (stored && roles.some(r => r.id === stored)) {
|
|
return stored as RoleId
|
|
}
|
|
return null
|
|
}
|
|
|
|
// Store role in localStorage
|
|
export function storeRole(roleId: RoleId): void {
|
|
if (typeof window === 'undefined') return
|
|
localStorage.setItem(ROLE_STORAGE_KEY, roleId)
|
|
}
|
|
|
|
// Clear stored role
|
|
export function clearStoredRole(): void {
|
|
if (typeof window === 'undefined') return
|
|
localStorage.removeItem(ROLE_STORAGE_KEY)
|
|
}
|
|
|
|
// Check if this is a first-time visitor (no role stored)
|
|
export function isFirstTimeVisitor(): boolean {
|
|
return getStoredRole() === null
|
|
}
|
|
|
|
// Get visible categories for a role
|
|
export function getVisibleCategoriesForRole(roleId: RoleId): CategoryId[] {
|
|
const role = getRoleById(roleId)
|
|
return role ? role.visibleCategories : []
|
|
}
|