21 lines
685 B
TypeScript
21 lines
685 B
TypeScript
export type ContentRole = 'admin' | 'editor' | 'user';
|
|
export const CONTENT_ROLES: ContentRole[] = ['admin', 'editor', 'user'];
|
|
|
|
export function isContentRole(value: unknown): value is ContentRole {
|
|
return value === 'admin' || value === 'editor' || value === 'user';
|
|
}
|
|
|
|
/** Admins and editors may author content; plain users are read-only. */
|
|
export function canAuthor(role: unknown): boolean {
|
|
return role === 'admin' || role === 'editor';
|
|
}
|
|
|
|
/** Only admins manage users, roles and the audit log. */
|
|
export function isAdmin(role: unknown): boolean {
|
|
return role === 'admin';
|
|
}
|
|
|
|
export function roleLabel(role: unknown): string {
|
|
return isContentRole(role) ? role : 'user';
|
|
}
|