Files
electric-cherry/src/lib/auth.ts
T

47 lines
1.3 KiB
TypeScript

export type UserRole = 'admin' | 'super_viewer' | 'operator' | 'moderator' | 'viewer';
export const moderatorMaximumRestrictionMs = 7 * 24 * 60 * 60 * 1000;
/** Reserved identity for work requested by the controller. */
export const systemUsername = 'Maxis';
export interface AuthUser {
id: string;
username: string;
displayName: string;
role: UserRole;
disabled: boolean;
mustChangePassword: boolean;
createdAt: string;
updatedAt: string;
lastLoginAt: string | null;
}
export const roleLabels: Record<UserRole, string> = {
admin: 'Administrator',
super_viewer: 'Super Viewer',
operator: 'Operator',
moderator: 'Moderator',
viewer: 'Viewer'
};
export function canOperate(role: UserRole | null | undefined): boolean {
return role === 'admin' || role === 'operator';
}
export function canReadAdmin(role: UserRole | null | undefined): boolean {
return role === 'admin' || role === 'super_viewer';
}
export function canReadSensitive(role: UserRole | null | undefined): boolean {
return canOperate(role) || role === 'super_viewer';
}
export function canModerate(role: UserRole | null | undefined): boolean {
return role === 'admin' || role === 'moderator';
}
export function canReadModeration(role: UserRole | null | undefined): boolean {
return canModerate(role) || role === 'super_viewer';
}