Backend+Admin+App: RBAC faza 1 - silnik rol platformowych (tabele Role/UserRoleGrant z addytywna migracja i backfillem z isAdmin, katalog 9 uprawnien, bramy per endpoint + guardy STAFF_MUTATION_FORBIDDEN/LAST_ROLES_MANAGER/PII_FORBIDDEN, redakcja PII po stronie serwera, panel Role i moderator w adminie, link panelu w apce wg platformRoles; login/me/DTO zwracaja platformRoles+permissions)
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
AppWindow,
|
||||
Building2,
|
||||
Dumbbell,
|
||||
KeyRound,
|
||||
LogOut,
|
||||
Megaphone,
|
||||
Menu,
|
||||
@@ -33,6 +34,8 @@ interface NavItem {
|
||||
end: boolean;
|
||||
/** Link na inny origin (np. aplikacja) — <a href>, nie <NavLink>. */
|
||||
external?: boolean;
|
||||
/** Uprawnienie wymagane do wyświetlenia pozycji (RBAC); brak = widoczna dla każdego staffu. */
|
||||
perm?: string;
|
||||
}
|
||||
|
||||
interface NavSection {
|
||||
@@ -44,24 +47,61 @@ const SECTIONS: NavSection[] = [
|
||||
{
|
||||
labelKey: 'nav.management',
|
||||
items: [
|
||||
{ to: '/gyms', labelKey: 'nav.gyms', icon: Building2, end: false },
|
||||
{ to: '/verifications', labelKey: 'nav.verifications', icon: ShieldCheck, end: false },
|
||||
{ to: '/users', labelKey: 'nav.users', icon: Users, end: false },
|
||||
{ to: '/announcements', labelKey: 'nav.announcements', icon: Megaphone, end: false },
|
||||
{ to: '/gyms', labelKey: 'nav.gyms', icon: Building2, end: false, perm: 'gyms:manage' },
|
||||
{
|
||||
to: '/verifications',
|
||||
labelKey: 'nav.verifications',
|
||||
icon: ShieldCheck,
|
||||
end: false,
|
||||
perm: 'verifications:view',
|
||||
},
|
||||
{ to: '/users', labelKey: 'nav.users', icon: Users, end: false, perm: 'users:read' },
|
||||
{
|
||||
to: '/roles',
|
||||
labelKey: 'nav.roles',
|
||||
icon: KeyRound,
|
||||
end: false,
|
||||
perm: 'roles:manage',
|
||||
},
|
||||
{
|
||||
to: '/announcements',
|
||||
labelKey: 'nav.announcements',
|
||||
icon: Megaphone,
|
||||
end: false,
|
||||
perm: 'announcements:manage',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
labelKey: 'nav.dictionaries',
|
||||
items: [
|
||||
{ to: '/focus-areas', labelKey: 'nav.focusAreas', icon: Target, end: false },
|
||||
{ to: '/exercises', labelKey: 'nav.exercises', icon: Dumbbell, end: false },
|
||||
{ to: '/equipment', labelKey: 'nav.equipment', icon: Wrench, end: false },
|
||||
{
|
||||
to: '/focus-areas',
|
||||
labelKey: 'nav.focusAreas',
|
||||
icon: Target,
|
||||
end: false,
|
||||
perm: 'catalog:manage',
|
||||
},
|
||||
{
|
||||
to: '/exercises',
|
||||
labelKey: 'nav.exercises',
|
||||
icon: Dumbbell,
|
||||
end: false,
|
||||
perm: 'catalog:manage',
|
||||
},
|
||||
{
|
||||
to: '/equipment',
|
||||
labelKey: 'nav.equipment',
|
||||
icon: Wrench,
|
||||
end: false,
|
||||
perm: 'catalog:manage',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
labelKey: 'nav.system',
|
||||
items: [
|
||||
{ to: '/logs', labelKey: 'nav.logs', icon: ScrollText, end: true },
|
||||
{ to: '/logs', labelKey: 'nav.logs', icon: ScrollText, end: true, perm: 'logs:view' },
|
||||
// Powrót do aplikacji użytkownika — zawsze na końcu, inny origin (aplikacja
|
||||
// wznowi sesję z własnego ciastka fitos_refresh, panelu nie dotyka).
|
||||
{ to: APP_URL, labelKey: 'nav.application', icon: AppWindow, end: false, external: true },
|
||||
@@ -155,9 +195,14 @@ function NavLinks({
|
||||
|
||||
function NavSections({ collapsed, onNavigate }: { collapsed: boolean; onNavigate?: () => void }) {
|
||||
const { t } = useTranslation();
|
||||
const perms = useAuth((s) => s.user?.permissions) ?? [];
|
||||
const visible = SECTIONS.map((section) => ({
|
||||
...section,
|
||||
items: section.items.filter((item) => !item.perm || perms.includes(item.perm)),
|
||||
})).filter((section) => section.items.length > 0);
|
||||
return (
|
||||
<div className={cn('flex flex-col', collapsed ? 'gap-2' : 'gap-4')}>
|
||||
{SECTIONS.map((section) => (
|
||||
{visible.map((section) => (
|
||||
<div key={section.labelKey}>
|
||||
{!collapsed && (
|
||||
<div className="mb-1 px-6 text-[10.5px] font-bold uppercase tracking-[0.13em] text-dim/80">
|
||||
@@ -195,9 +240,11 @@ export default function Layout() {
|
||||
user?.nickname ||
|
||||
user?.email ||
|
||||
'?';
|
||||
const platformRoleNames = (user?.platformRoles ?? []).map((k) => t(`roles:names.${k}`, k));
|
||||
const roles = [
|
||||
user?.isAdmin ? t('nav.roleAdmin') : null,
|
||||
isTrainer ? t('nav.roleTrainer') : t('nav.roleMember'),
|
||||
...platformRoleNames,
|
||||
// bez ról platformowych widać kontekst siłowni; z rolami nie dodajemy "Ćwiczącego"
|
||||
isTrainer ? t('nav.roleTrainer') : platformRoleNames.length ? null : t('nav.roleMember'),
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' · ');
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { ActivityLog } from '../api/types';
|
||||
import { Badge, type BadgeColor } from './ui';
|
||||
import i18n from '../i18n';
|
||||
import { fmtDate, fmtDateTime, fmtTime, maskEmail } from '../lib/format';
|
||||
import { fmtDate, fmtDateTime, fmtTime } from '../lib/format';
|
||||
|
||||
const t = (key: string, options?: Record<string, unknown>): string =>
|
||||
String(i18n.t(`logs:${key}`, options as never));
|
||||
@@ -27,7 +27,8 @@ export function formatLogDate(iso: string) {
|
||||
|
||||
export function actorName(log: ActivityLog) {
|
||||
const { firstName, lastName, email } = log.actor;
|
||||
return [firstName, lastName].filter(Boolean).join(' ') || maskEmail(email);
|
||||
// e-mail w actorze jest już zredagowany po stronie serwera (bez pii:read zamaskowany)
|
||||
return [firstName, lastName].filter(Boolean).join(' ') || email;
|
||||
}
|
||||
|
||||
/** Nazwa obiektu z szczegółów wpisu (tytuł planu, nazwa siłowni, nazwa obwodu). */
|
||||
@@ -52,7 +53,6 @@ const HIDDEN_DETAIL_KEYS = new Set([
|
||||
]);
|
||||
|
||||
function formatDetailValue(log: ActivityLog, key: string, value: unknown): string {
|
||||
if (key === 'email' && typeof value === 'string') return maskEmail(value);
|
||||
if (Array.isArray(value)) return value.map((v) => String(v)).join(', ');
|
||||
if (value && typeof value === 'object') {
|
||||
return Object.entries(value)
|
||||
@@ -123,7 +123,7 @@ export function LogTable({ logs }: { logs: ActivityLog[] }) {
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
<div className="font-semibold">{actorName(log)}</div>
|
||||
<div className="text-[0.875rem] text-dim">{maskEmail(log.actor.email)}</div>
|
||||
<div className="text-[0.875rem] text-dim">{log.actor.email}</div>
|
||||
<div className="font-mono text-[0.75rem] text-dim/70" title={log.actor.id}>
|
||||
{log.actor.id}
|
||||
</div>
|
||||
|
||||
@@ -2,10 +2,9 @@ import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Search, X } from 'lucide-react';
|
||||
import type { User } from '../api/types';
|
||||
import { maskEmail } from '../lib/format';
|
||||
|
||||
export function userLabel(u: User): string {
|
||||
return [u.firstName, u.lastName].filter(Boolean).join(' ') || maskEmail(u.email);
|
||||
return [u.firstName, u.lastName].filter(Boolean).join(' ') || u.email;
|
||||
}
|
||||
|
||||
/** Przeszukiwalny wybór użytkownika (listę pobiera strona) — wzór: GymPicker z członkostw. */
|
||||
@@ -103,7 +102,7 @@ export function UserPicker({
|
||||
>
|
||||
<span className="min-w-0 truncate">{userLabel(u)}</span>
|
||||
{u.firstName && (
|
||||
<span className="shrink-0 text-[0.875rem] text-dim">{maskEmail(u.email)}</span>
|
||||
<span className="shrink-0 text-[0.875rem] text-dim">{u.email}</span>
|
||||
)}
|
||||
</button>
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user