Files
pipu-music/apps/web/src/shared/lib/policy.ts
T
mrleo1nidandClaude Opus 5.5 978f03b8f8
ci / api / api (push) Successful in 40s
ci / contract / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 55s
ci / mobile / mobile (Metro-бандл Android) (push) Successful in 1m10s
ci / db / db (push) Successful in 2m35s
ci / ts / ts (packages + web) (push) Successful in 1m23s
feat(admin): reset a user's recommendations from the users panel
- POST /admin/users/{id}/reset-recommendations clears the taste profile
  (onboarding, CF vector, bandit), play stats and wave impressions; likes,
  dislikes and history stay, wave sessions stay so a playing wave keeps going
- moderators may reset plain users, admins anyone including themselves;
  the reset is written to the audit log
- users panel gets the menu action with a confirmation; docs updated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 08:52:31 +03:00

24 lines
1.1 KiB
TypeScript

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 [];
}