Files
breakpilot-core/admin-core/lib/roles.ts
Benjamin Boenisch 97373580a8 Add admin-core frontend (Port 3008)
Next.js admin frontend for Core with 3 categories
(Communication, Infrastructure, Development), 13 modules,
2 roles (developer, ops), and 11 API proxy routes.
Includes docker-compose service and nginx SSL config.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 14:44:37 +01:00

85 lines
2.3 KiB
TypeScript

/**
* Role-based Access System for Admin Core
*
* Roles: developer (full access), ops (infra + communication)
*/
import { CategoryId } from './navigation'
export type RoleId = 'developer' | 'ops'
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', 'infrastructure', 'development'],
color: 'bg-primary-100 border-primary-300 text-primary-700',
},
{
id: 'ops',
name: 'Operations',
description: 'Infrastruktur & Kommunikation',
icon: 'server',
visibleCategories: ['communication', 'infrastructure'],
color: 'bg-orange-100 border-orange-300 text-orange-700',
},
]
// Storage key for localStorage
const ROLE_STORAGE_KEY = 'admin-core-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 : []
}