Admin: maskowanie e-maili userow w panelu (jan@fitos.pl -> j*n@f****.pl; lista, konsola, sirownie, wnioski, logi; pelny adres zna tylko user)
This commit is contained in:
@@ -24,6 +24,7 @@ import { Topbar } from '../topbar';
|
||||
import { Brandmark } from './Brandmark';
|
||||
import { Avatar } from './Avatar';
|
||||
import { buildInfo } from '../lib/build-info';
|
||||
import { maskEmail } from '../lib/format';
|
||||
import { cn } from '../lib/utils';
|
||||
|
||||
interface NavItem {
|
||||
@@ -191,7 +192,9 @@ export default function Layout() {
|
||||
const isTrainer = useIsTrainer();
|
||||
const build = buildInfo();
|
||||
const fullName =
|
||||
[user?.firstName, user?.lastName].filter(Boolean).join(' ') || user?.email || '?';
|
||||
[user?.firstName, user?.lastName].filter(Boolean).join(' ') ||
|
||||
user?.nickname ||
|
||||
(user ? maskEmail(user.email) : '?');
|
||||
const roles = [
|
||||
user?.isAdmin ? t('nav.roleAdmin') : null,
|
||||
isTrainer ? t('nav.roleTrainer') : t('nav.roleMember'),
|
||||
@@ -210,7 +213,9 @@ export default function Layout() {
|
||||
<div className="mb-3 flex items-center gap-2.5">
|
||||
<Avatar name={fullName} size={32} />
|
||||
<div className="min-w-0">
|
||||
<div className="truncate text-[13px] font-bold">{user?.firstName || user?.email}</div>
|
||||
<div className="truncate text-[13px] font-bold">
|
||||
{user?.firstName || user?.nickname || (user ? maskEmail(user.email) : '')}
|
||||
</div>
|
||||
<div className="text-[11.5px] text-dim">{roles}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { ActivityLog } from '../api/types';
|
||||
import { Badge, type BadgeColor } from './ui';
|
||||
import i18n from '../i18n';
|
||||
import { fmtDate, fmtDateTime, fmtTime } from '../lib/format';
|
||||
import { fmtDate, fmtDateTime, fmtTime, maskEmail } from '../lib/format';
|
||||
|
||||
const t = (key: string, options?: Record<string, unknown>): string =>
|
||||
String(i18n.t(`logs:${key}`, options as never));
|
||||
@@ -27,7 +27,7 @@ export function formatLogDate(iso: string) {
|
||||
|
||||
export function actorName(log: ActivityLog) {
|
||||
const { firstName, lastName, email } = log.actor;
|
||||
return [firstName, lastName].filter(Boolean).join(' ') || email;
|
||||
return [firstName, lastName].filter(Boolean).join(' ') || maskEmail(email);
|
||||
}
|
||||
|
||||
/** Nazwa obiektu z szczegółów wpisu (tytuł planu, nazwa siłowni, nazwa obwodu). */
|
||||
@@ -111,7 +111,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">{log.actor.email}</div>
|
||||
<div className="text-[0.875rem] text-dim">{maskEmail(log.actor.email)}</div>
|
||||
<div className="font-mono text-[0.75rem] text-dim/70" title={log.actor.id}>
|
||||
{log.actor.id}
|
||||
</div>
|
||||
|
||||
@@ -2,9 +2,10 @@ 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(' ') || u.email;
|
||||
return [u.firstName, u.lastName].filter(Boolean).join(' ') || maskEmail(u.email);
|
||||
}
|
||||
|
||||
/** Przeszukiwalny wybór użytkownika (listę pobiera strona) — wzór: GymPicker z członkostw. */
|
||||
@@ -102,7 +103,7 @@ export function UserPicker({
|
||||
>
|
||||
<span className="min-w-0 truncate">{userLabel(u)}</span>
|
||||
{u.firstName && (
|
||||
<span className="shrink-0 text-[0.875rem] text-dim">{u.email}</span>
|
||||
<span className="shrink-0 text-[0.875rem] text-dim">{maskEmail(u.email)}</span>
|
||||
)}
|
||||
</button>
|
||||
))
|
||||
|
||||
@@ -15,6 +15,27 @@ export function displayName(
|
||||
return u.nickname || [u.firstName, u.lastName].filter(Boolean).join(' ') || fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maska adresu e-mail do wyświetlania w panelu admina: pierwsza i ostatnia litera
|
||||
* local part, pierwsza litera domeny i TLD — reszta jako gwiazdki (np. jan@fitos.pl → j*n@f****.pl).
|
||||
*/
|
||||
export function maskEmail(email: string | null | undefined): string {
|
||||
if (!email) return '—';
|
||||
const at = email.indexOf('@');
|
||||
if (at < 1) return '*';
|
||||
const local = email.slice(0, at);
|
||||
const localMask =
|
||||
local.length <= 2
|
||||
? `${local.slice(0, 1)}${'*'.repeat(Math.max(local.length - 1, 1))}`
|
||||
: `${local.slice(0, 1)}${'*'.repeat(local.length - 2)}${local.slice(-1)}`;
|
||||
const domain = email.slice(at + 1);
|
||||
const dot = domain.indexOf('.');
|
||||
const firstLabel = dot < 0 ? domain : domain.slice(0, dot);
|
||||
const rest = dot < 0 ? '' : domain.slice(dot);
|
||||
const domainMask = `${firstLabel.slice(0, 1)}${'*'.repeat(Math.max(firstLabel.length - 1, 1))}${rest}`;
|
||||
return `${localMask}@${domainMask}`;
|
||||
}
|
||||
|
||||
export function fmtDate(iso: string | null | undefined): string {
|
||||
if (!iso) return '—';
|
||||
return new Date(iso).toLocaleDateString(currentTag(), {
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
import type { BadgeColor } from '../components/ui';
|
||||
import { Avatar } from '../components/Avatar';
|
||||
import { formatAvailability } from '../lib/availability';
|
||||
import { fmtDate } from '../lib/format';
|
||||
import { fmtDate, maskEmail } from '../lib/format';
|
||||
import i18n from '../i18n';
|
||||
import { useTopbar } from '../topbar';
|
||||
|
||||
@@ -47,7 +47,7 @@ function claimTypeLabel(claim: GymClaim) {
|
||||
|
||||
function applicantName(claim: GymClaim) {
|
||||
const { firstName, lastName, email } = claim.user;
|
||||
return [firstName, lastName].filter(Boolean).join(' ') || email;
|
||||
return [firstName, lastName].filter(Boolean).join(' ') || maskEmail(email);
|
||||
}
|
||||
|
||||
/** Pobranie pliku przez `apiBlob` (Bearer + rotacja 401) → tymczasowy <a download>. */
|
||||
@@ -284,7 +284,7 @@ export function VerificationDetail() {
|
||||
<InfoItem label={tr('companyNameLabel')}>{claim.companyName || '—'}</InfoItem>
|
||||
<InfoItem label={tr('nipLabel')}>{claim.nip || '—'}</InfoItem>
|
||||
<InfoItem label={tr('phoneLabel')}>{claim.phone || '—'}</InfoItem>
|
||||
<InfoItem label={tr('emailLabel')}>{claim.email || '—'}</InfoItem>
|
||||
<InfoItem label={tr('emailLabel')}>{claim.email ? maskEmail(claim.email) : '—'}</InfoItem>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
@@ -297,7 +297,7 @@ export function VerificationDetail() {
|
||||
{applicantName(claim)}
|
||||
</span>
|
||||
</InfoItem>
|
||||
<InfoItem label={tr('emailLabel')}>{claim.user.email}</InfoItem>
|
||||
<InfoItem label={tr('emailLabel')}>{maskEmail(claim.user.email)}</InfoItem>
|
||||
{claim.user.phone != null && (
|
||||
<InfoItem label={tr('phoneLabel')}>{claim.user.phone}</InfoItem>
|
||||
)}
|
||||
|
||||
@@ -32,7 +32,7 @@ import {
|
||||
} from '../../components/ui';
|
||||
import { AvailabilityEditor } from '../../components/AvailabilityEditor';
|
||||
import { dayFull, formatDayRangeClock, normalizeAvailability } from '../../lib/availability';
|
||||
import { fmtDate, fmtDateTime } from '../../lib/format';
|
||||
import { fmtDate, fmtDateTime, maskEmail } from '../../lib/format';
|
||||
import { GYM_ROLE_META, GYM_ROLE_ORDER } from '../../lib/roles';
|
||||
import { useAdminUsers } from '../users/user-queries';
|
||||
import { useGymAuditLogs, useGymMembers, useGymRelated } from '../../api/queries';
|
||||
@@ -70,7 +70,16 @@ function HoursList({ gym }: { gym: Gym }) {
|
||||
}
|
||||
|
||||
function memberLabel(m: AdminGymMemberItem): string {
|
||||
return [m.user.firstName, m.user.lastName].filter(Boolean).join(' ') || m.user.email;
|
||||
return personName(m.user);
|
||||
}
|
||||
|
||||
/* Nazwa osoby; fallback na zamaskowany e-mail. */
|
||||
function personName(p: {
|
||||
firstName?: string | null;
|
||||
lastName?: string | null;
|
||||
email: string;
|
||||
}): string {
|
||||
return [p.firstName, p.lastName].filter(Boolean).join(' ') || maskEmail(p.email);
|
||||
}
|
||||
|
||||
/* Rola jako pigułki — te same etykiety co na członkostwach usera. */
|
||||
@@ -122,7 +131,7 @@ function MembersTable({
|
||||
>
|
||||
<td className="px-3 py-2.5 align-top">
|
||||
<div className="font-semibold">{memberLabel(m)}</div>
|
||||
<div className="text-[0.78rem] text-dim">{m.user.email}</div>
|
||||
<div className="text-[0.78rem] text-dim">{maskEmail(m.user.email)}</div>
|
||||
</td>
|
||||
<td className="px-3 py-2.5 align-top">
|
||||
<RoleBadges roles={m.roles} />
|
||||
@@ -590,8 +599,7 @@ export default function GymDetail() {
|
||||
to={`/users/${c.user.id}`}
|
||||
className="font-semibold hover:text-accent-text"
|
||||
>
|
||||
{[c.user.firstName, c.user.lastName].filter(Boolean).join(' ') ||
|
||||
c.user.email}
|
||||
{personName(c.user)}
|
||||
</Link>
|
||||
<Badge
|
||||
color={
|
||||
@@ -631,14 +639,10 @@ export default function GymDetail() {
|
||||
to={`/users/${inv.user.id}`}
|
||||
className="font-semibold hover:text-accent-text"
|
||||
>
|
||||
{[inv.user.firstName, inv.user.lastName].filter(Boolean).join(' ') ||
|
||||
inv.user.email}
|
||||
{personName(inv.user)}
|
||||
</Link>
|
||||
<span className="text-[0.76rem] text-dim">
|
||||
{t('invitedBy')}{' '}
|
||||
{[inv.invitedBy.firstName, inv.invitedBy.lastName]
|
||||
.filter(Boolean)
|
||||
.join(' ') || inv.invitedBy.email}
|
||||
{t('invitedBy')} {personName(inv.invitedBy)}
|
||||
</span>
|
||||
<Badge
|
||||
color={
|
||||
|
||||
@@ -8,10 +8,10 @@ import { Badge, Card, EmptyState, ErrorText, Loading, Select } from '../../compo
|
||||
import { formatDayRangeClock, normalizeAvailability } from '../../lib/availability';
|
||||
import { useListSearch } from '../../store/list-search';
|
||||
import { useTopbar } from '../../topbar';
|
||||
import { fmtDate } from '../../lib/format';
|
||||
import { fmtDate, maskEmail } from '../../lib/format';
|
||||
|
||||
function ownerLabel(o: AdminGymListItem['owners'][number]): string {
|
||||
return [o.firstName, o.lastName].filter(Boolean).join(' ') || o.email;
|
||||
return [o.firstName, o.lastName].filter(Boolean).join(' ') || maskEmail(o.email);
|
||||
}
|
||||
|
||||
/* Wiersz listy — klik na całej szerokości prowadzi do konsoli siłowni w panelu admina;
|
||||
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
Loading,
|
||||
StatCell,
|
||||
} from '../../components/ui';
|
||||
import { fmtDate, fmtDateTime, displayName } from '../../lib/format';
|
||||
import { fmtDate, fmtDateTime, displayName, maskEmail } from '../../lib/format';
|
||||
import {
|
||||
detailsText,
|
||||
actionLabel,
|
||||
@@ -39,14 +39,14 @@ import { GYM_ROLE_META, GYM_ROLE_ORDER } from '../../lib/roles';
|
||||
import { UserRestrictionModal } from './UserRestrictionModal';
|
||||
import { useAdminUser, useUserActivity, useUserClaims } from './user-queries';
|
||||
|
||||
/** Nazwa wyświetlana użytkownika (nick → imię+nazwisko → e-mail). */
|
||||
/** Nazwa wyświetlana użytkownika (nick → imię+nazwisko → zamaskowany e-mail). */
|
||||
export function userDisplayName(u: {
|
||||
nickname?: string | null;
|
||||
firstName?: string | null;
|
||||
lastName?: string | null;
|
||||
email: string;
|
||||
}): string {
|
||||
return displayName(u) === '—' ? u.email : displayName(u);
|
||||
return displayName(u) === '—' ? maskEmail(u.email) : displayName(u);
|
||||
}
|
||||
|
||||
/* Rola jako pigułki — te same etykiety co w konsoli siłowni. */
|
||||
@@ -150,7 +150,7 @@ export default function UserDetail() {
|
||||
<div className="flex flex-wrap items-center gap-x-4 gap-y-2 border-b border-line px-4 py-3 text-[0.85rem] text-dim sm:px-5">
|
||||
<span className="flex items-center gap-2.5">
|
||||
<Avatar name={name} size={30} />
|
||||
<b className="text-ink">{user.email}</b>
|
||||
<b className="text-ink">{maskEmail(user.email)}</b>
|
||||
</span>
|
||||
<span className="flex flex-wrap items-center gap-1.5">
|
||||
{user.status === 'SUSPENDED' && (
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Building2, Check, ChevronDown, ShieldCheck, Trash2, UserPlus } from 'lu
|
||||
import { api } from '../../api/client';
|
||||
import type { Gym, GymRole, User } from '../../api/types';
|
||||
import { ADMIN_ROLE_META, GYM_ROLE_META } from '../../lib/roles';
|
||||
import { todayStr } from '../../lib/format';
|
||||
import { todayStr, maskEmail } from '../../lib/format';
|
||||
import { GymPicker } from '../../components/GymPicker';
|
||||
import { GymRolePicker } from '../../components/GymRolePicker';
|
||||
import {
|
||||
@@ -222,7 +222,8 @@ export default function UserForm() {
|
||||
return;
|
||||
}
|
||||
|
||||
// EDYCJA: PATCH konta (tożsamość/dostęp), potem porządkowanie członkostw
|
||||
// EDYCJA: PATCH konta (tożsamość/dostęp), potem porządkowanie członkostw.
|
||||
// E-mail w edycji jest ukryty (zna go tylko user) — PATCH przenosi niezmieniony adres.
|
||||
const patchBody: Record<string, unknown> = {
|
||||
email: form.email.trim(),
|
||||
firstName: form.firstName || null,
|
||||
@@ -315,12 +316,18 @@ export default function UserForm() {
|
||||
/>
|
||||
</Field>
|
||||
<Field label={t('auth:email')}>
|
||||
<Input
|
||||
type="email"
|
||||
value={form.email}
|
||||
onChange={(e) => setForm({ ...form, email: e.target.value })}
|
||||
required
|
||||
/>
|
||||
{isEdit ? (
|
||||
// w edycji e-mail jest zamaskowany i tylko do odczytu (zna go tylko user);
|
||||
// PATCH poniżej przenosi niezmieniony, pełny adres z formularza
|
||||
<Input value={maskEmail(form.email)} readOnly disabled />
|
||||
) : (
|
||||
<Input
|
||||
type="email"
|
||||
value={form.email}
|
||||
onChange={(e) => setForm({ ...form, email: e.target.value })}
|
||||
required
|
||||
/>
|
||||
)}
|
||||
</Field>
|
||||
<Field label={t('birthDate')}>
|
||||
<Input
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Badge, Card, EmptyState, ErrorText, ListRow, Loading } from '../../comp
|
||||
import { Avatar } from '../../components/Avatar';
|
||||
import { useListSearch } from '../../store/list-search';
|
||||
import { useTopbar } from '../../topbar';
|
||||
import { ageFromBirthDate, fmtDate } from '../../lib/format';
|
||||
import { ageFromBirthDate, fmtDate, maskEmail } from '../../lib/format';
|
||||
import { userDisplayName } from './UserDetail';
|
||||
|
||||
export default function UsersList() {
|
||||
@@ -65,7 +65,7 @@ export default function UsersList() {
|
||||
}
|
||||
meta={
|
||||
<>
|
||||
{u.email}
|
||||
{maskEmail(u.email)}
|
||||
{ageFromBirthDate(u.birthDate) != null
|
||||
? ` · ${t('ageWord', { age: ageFromBirthDate(u.birthDate) })}`
|
||||
: ''}
|
||||
|
||||
Reference in New Issue
Block a user