import type { components } from '@pipu/api-client'; export type Role = components['schemas']['Role']; export type UserAction = 'reset_password' | 'reset_recommendations' | 'block' | 'change_role' | 'delete'; /** * Копия матрицы прав (docs/auth-and-roles.md, services/api/internal/auth/policy.go) — только для UI: * какие действия показывать. Решает всё равно сервер. */ export function canManageUser(actor: { id: string; role: Role }, target: { id: string; role: Role }, action: UserAction) { const self = actor.id === target.id; if (self && (action === 'block' || action === 'change_role' || action === 'delete')) return false; if (actor.role === 'admin') return true; if (actor.role === 'moderator') return action !== 'change_role' && action !== 'delete' && target.role === 'user'; return false; } /** Роли, которые actor может выдать при создании. */ export function assignableRoles(actor: Role): Role[] { if (actor === 'admin') return ['user', 'moderator', 'admin']; if (actor === 'moderator') return ['user']; return []; }