Avant de tester le retrait et le dépôt en crypto réel
This commit is contained in:
parent
5b9306fba3
commit
b866f91973
@ -112,3 +112,85 @@ export async function getMyPermissions(req: AuthRequest, res: Response): Promise
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
|
||||
export async function listAdminUsers(req: AuthRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const q = req.query as Record<string, string | undefined>;
|
||||
const exceptionRaw = q.exception ?? 'all';
|
||||
const exception =
|
||||
exceptionRaw === 'any' ||
|
||||
exceptionRaw === 'allow' ||
|
||||
exceptionRaw === 'deny' ||
|
||||
exceptionRaw === 'none' ||
|
||||
exceptionRaw === 'all'
|
||||
? exceptionRaw
|
||||
: 'all';
|
||||
const data = await rbacService.listAdminUsers({
|
||||
search: q.search,
|
||||
role: q.role,
|
||||
exception,
|
||||
permission: q.permission,
|
||||
limit: q.limit ? parseInt(q.limit, 10) : 50,
|
||||
offset: q.offset ? parseInt(q.offset, 10) : 0,
|
||||
});
|
||||
res.json(data);
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to list admin users';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAdminUser(req: AuthRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const userId = req.params.userId;
|
||||
const data = await rbacService.getAdminUser(userId);
|
||||
if (!data) {
|
||||
res.status(404).json({ error: 'User not found' });
|
||||
return;
|
||||
}
|
||||
res.json(data);
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to load admin user';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAdminUserPermissions(req: AuthRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const userId = req.params.userId;
|
||||
const data = await rbacService.getAdminUser(userId);
|
||||
if (!data) {
|
||||
res.status(404).json({ error: 'User not found' });
|
||||
return;
|
||||
}
|
||||
res.json({
|
||||
user: data.user,
|
||||
permissions: data.permissions,
|
||||
categories: data.categories,
|
||||
});
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to load permissions';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateAdminUserPermissions(req: AuthRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const userId = req.params.userId;
|
||||
const body = req.body as {
|
||||
permissionKey?: string;
|
||||
action?: 'allow' | 'deny' | 'reset';
|
||||
changes?: Array<{ key: string; action: 'allow' | 'deny' | 'reset' }>;
|
||||
};
|
||||
const changes =
|
||||
body.changes ??
|
||||
(body.permissionKey && body.action
|
||||
? [{ key: body.permissionKey, action: body.action }]
|
||||
: []);
|
||||
const data = await rbacService.applyUserPermissionChanges(userId, changes, req.user!.userId);
|
||||
res.json(data);
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to update permissions';
|
||||
res.status(400).json({ error: msg });
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,6 +104,22 @@ CREATE TABLE IF NOT EXISTS user_roles (
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_user_roles_role ON user_roles(role_id);
|
||||
|
||||
-- Per-user permission exceptions (allow / deny) layered on top of role grants
|
||||
CREATE TABLE IF NOT EXISTS user_permission_overrides (
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
permission_id INTEGER NOT NULL REFERENCES permissions(id) ON DELETE CASCADE,
|
||||
effect VARCHAR(8) NOT NULL CHECK (effect IN ('allow', 'deny')),
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
updated_by UUID REFERENCES users(id),
|
||||
PRIMARY KEY (user_id, permission_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_user_permission_overrides_permission
|
||||
ON user_permission_overrides(permission_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_user_permission_overrides_effect
|
||||
ON user_permission_overrides(effect);
|
||||
|
||||
-- Backfill user_roles from legacy users.role_id
|
||||
INSERT INTO user_roles (user_id, role_id)
|
||||
SELECT u.id, u.role_id FROM users u
|
||||
@ -2467,7 +2483,8 @@ INSERT INTO system_settings (key, value) VALUES
|
||||
('sybil_auto_suspend_accounts', 'true'),
|
||||
('login_risk_auto_suspend_accounts', 'false'),
|
||||
('login_risk_auto_suspend_threshold', '70'),
|
||||
('encryption_key_rotated_at', '')
|
||||
('encryption_key_rotated_at', ''),
|
||||
('engine_audit_log_retention_days', '7')
|
||||
ON CONFLICT (key) DO NOTHING;
|
||||
|
||||
-- Referral commissions on each validated prediction (stake-based)
|
||||
|
||||
@ -8,6 +8,7 @@ import * as settingsRepository from '../../repositories/settingsRepository';
|
||||
import { assertPositiveStakeAmount, parseStakeAmountFromBody } from '../../utils/stakeAmountValidation';
|
||||
import { queueUserAdminStatsRefresh } from '../../services/userAdminStatsService';
|
||||
import * as predictionAuditService from '../../services/predictionAuditService';
|
||||
import { startEngineAuditRetentionJob } from '../../services/engineAuditRetentionService';
|
||||
import { processPredictionReferralCommissions } from '../../services/referralService';
|
||||
import {
|
||||
generateSyntheticCandle,
|
||||
@ -2497,4 +2498,5 @@ export function startCandlePredictEngine(): void {
|
||||
setTimeout(run, tickMs);
|
||||
};
|
||||
setTimeout(run, 5000);
|
||||
startEngineAuditRetentionJob();
|
||||
}
|
||||
|
||||
@ -27,6 +27,8 @@ export interface SystemSettings {
|
||||
candle_predict_backfill_max_per_tick: number;
|
||||
candle_predict_backfill_interval_ms: number;
|
||||
candle_predict_backfill_seed_max: number;
|
||||
/** Days to keep engine-only audit rows such as prediction_round_settled (0 = never purge). */
|
||||
engine_audit_log_retention_days: number;
|
||||
/** Network fee deducted from user USDT balance per withdrawal (6-decimal micro units). */
|
||||
withdrawal_network_fee_usdt_micro: number;
|
||||
/** When true, admin/super_admin routes require TOTP to be enabled. */
|
||||
|
||||
@ -49,3 +49,18 @@ export function userHasAllPermissions(userPerms: string[], required: string[]):
|
||||
export function userHasAnyPermission(userPerms: string[], required: string[]): boolean {
|
||||
return required.some((p) => userHasPermission(userPerms, p));
|
||||
}
|
||||
|
||||
/**
|
||||
* Effective permissions = role grants ∪ individual allows − individual denies.
|
||||
* Deny always wins over inherited and direct allow.
|
||||
*/
|
||||
export function mergePermissionSets(
|
||||
inherited: string[],
|
||||
directAllow: string[],
|
||||
directDeny: string[]
|
||||
): string[] {
|
||||
const set = new Set(inherited);
|
||||
for (const key of directAllow) set.add(key);
|
||||
for (const key of directDeny) set.delete(key);
|
||||
return [...set].sort();
|
||||
}
|
||||
|
||||
@ -24,6 +24,26 @@ export async function syncPermissionCatalog(): Promise<void> {
|
||||
ALTER TABLE permissions ADD COLUMN IF NOT EXISTS is_system BOOLEAN NOT NULL DEFAULT TRUE;
|
||||
`);
|
||||
|
||||
await query(`
|
||||
CREATE TABLE IF NOT EXISTS user_permission_overrides (
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
permission_id INTEGER NOT NULL REFERENCES permissions(id) ON DELETE CASCADE,
|
||||
effect VARCHAR(8) NOT NULL CHECK (effect IN ('allow', 'deny')),
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
updated_by UUID REFERENCES users(id),
|
||||
PRIMARY KEY (user_id, permission_id)
|
||||
)
|
||||
`);
|
||||
await query(`
|
||||
CREATE INDEX IF NOT EXISTS idx_user_permission_overrides_permission
|
||||
ON user_permission_overrides(permission_id)
|
||||
`);
|
||||
await query(`
|
||||
CREATE INDEX IF NOT EXISTS idx_user_permission_overrides_effect
|
||||
ON user_permission_overrides(effect)
|
||||
`);
|
||||
|
||||
// Mark system roles
|
||||
for (const name of SYSTEM_ROLE_NAMES) {
|
||||
await query(`UPDATE roles SET is_system = TRUE WHERE name = $1`, [name]);
|
||||
|
||||
@ -53,9 +53,30 @@ export type AuditLogRow = {
|
||||
created_at: Date;
|
||||
};
|
||||
|
||||
export const ENGINE_AUDIT_ACTIONS = ['prediction_round_settled'] as const;
|
||||
|
||||
export async function deleteEngineAuditLogsOlderThan(cutoff: Date, batchSize = 5000): Promise<number> {
|
||||
const result = await query<{ count: string }[]>(
|
||||
`WITH deleted AS (
|
||||
DELETE FROM audit_logs
|
||||
WHERE ctid IN (
|
||||
SELECT ctid FROM audit_logs
|
||||
WHERE action = ANY($1::text[])
|
||||
AND created_at < $2
|
||||
LIMIT $3
|
||||
)
|
||||
RETURNING 1
|
||||
)
|
||||
SELECT COUNT(*)::text AS count FROM deleted`,
|
||||
[ENGINE_AUDIT_ACTIONS, cutoff, Math.min(Math.max(batchSize, 100), 20_000)]
|
||||
);
|
||||
return parseInt(result[0]?.count ?? '0', 10);
|
||||
}
|
||||
|
||||
export async function listAuditLogs(filters: {
|
||||
action?: string;
|
||||
actions?: string[];
|
||||
excludeActions?: string[];
|
||||
userId?: string;
|
||||
from?: Date;
|
||||
to?: Date;
|
||||
@ -72,6 +93,9 @@ export async function listAuditLogs(filters: {
|
||||
} else if (filters.actions?.length) {
|
||||
conditions.push(`action = ANY($${i++})`);
|
||||
params.push(filters.actions);
|
||||
} else if (filters.excludeActions?.length) {
|
||||
conditions.push(`NOT (action = ANY($${i++}))`);
|
||||
params.push(filters.excludeActions);
|
||||
}
|
||||
if (filters.userId) {
|
||||
conditions.push(`user_id = $${i++}`);
|
||||
@ -110,6 +134,7 @@ export async function listAuditLogs(filters: {
|
||||
export async function exportAuditLogsCsv(filters: {
|
||||
action?: string;
|
||||
actions?: string[];
|
||||
excludeActions?: string[];
|
||||
userId?: string;
|
||||
from?: Date;
|
||||
to?: Date;
|
||||
|
||||
@ -2,10 +2,10 @@
|
||||
* Roles, permissions, and user_roles (many-to-many).
|
||||
*/
|
||||
|
||||
import { query } from '../db/connection';
|
||||
import { beginAuthorizedTransaction, getClient, query } from '../db/connection';
|
||||
import type { RoleName } from '../models';
|
||||
import { SYSTEM_ROLE_NAMES, isSystemRole } from '../rbac/permissionCatalog';
|
||||
import { userHasPermission as resolvePermission } from '../rbac/permissionResolver';
|
||||
import { userHasPermission as resolvePermission, mergePermissionSets } from '../rbac/permissionResolver';
|
||||
|
||||
const ALL_ROLE_NAMES: RoleName[] = ['user', 'moderator', 'admin', 'super_admin'];
|
||||
|
||||
@ -160,7 +160,7 @@ export async function getUserRoleNames(userId: string): Promise<string[]> {
|
||||
return legacy[0] ? [legacy[0].name] : ['user'];
|
||||
}
|
||||
|
||||
export async function getUserPermissions(userId: string): Promise<string[]> {
|
||||
export async function getUserInheritedPermissionKeys(userId: string): Promise<string[]> {
|
||||
const rows = await query<{ key: string }[]>(
|
||||
`SELECT DISTINCT p.key
|
||||
FROM user_roles ur
|
||||
@ -177,12 +177,374 @@ export async function getUserPermissions(userId: string): Promise<string[]> {
|
||||
JOIN role_permissions rp ON rp.role_id = u.role_id
|
||||
JOIN permissions p ON p.id = rp.permission_id
|
||||
WHERE u.id = $1
|
||||
AND NOT EXISTS (SELECT 1 FROM user_roles ur WHERE ur.user_id = u.id)
|
||||
ORDER BY p.key`,
|
||||
[userId]
|
||||
);
|
||||
return legacy.map((r) => r.key);
|
||||
}
|
||||
|
||||
export type PermissionOverrideRow = {
|
||||
key: string;
|
||||
effect: 'allow' | 'deny';
|
||||
};
|
||||
|
||||
export async function getUserPermissionOverrides(userId: string): Promise<PermissionOverrideRow[]> {
|
||||
const rows = await query<PermissionOverrideRow[]>(
|
||||
`SELECT p.key, o.effect
|
||||
FROM user_permission_overrides o
|
||||
JOIN permissions p ON p.id = o.permission_id
|
||||
WHERE o.user_id = $1
|
||||
ORDER BY p.key`,
|
||||
[userId]
|
||||
);
|
||||
return rows;
|
||||
}
|
||||
|
||||
export async function getUserPermissions(userId: string): Promise<string[]> {
|
||||
const [inherited, overrides] = await Promise.all([
|
||||
getUserInheritedPermissionKeys(userId),
|
||||
getUserPermissionOverrides(userId),
|
||||
]);
|
||||
const allow = overrides.filter((o) => o.effect === 'allow').map((o) => o.key);
|
||||
const deny = overrides.filter((o) => o.effect === 'deny').map((o) => o.key);
|
||||
return mergePermissionSets(inherited, allow, deny);
|
||||
}
|
||||
|
||||
export async function setUserPermissionOverride(
|
||||
userId: string,
|
||||
permissionKey: string,
|
||||
effect: 'allow' | 'deny',
|
||||
actorUserId: string
|
||||
): Promise<void> {
|
||||
const result = await query<{ id: number }[]>(
|
||||
`INSERT INTO user_permission_overrides (user_id, permission_id, effect, updated_by, updated_at)
|
||||
SELECT $1, p.id, $3, $4, NOW()
|
||||
FROM permissions p
|
||||
WHERE p.key = $2
|
||||
ON CONFLICT (user_id, permission_id) DO UPDATE SET
|
||||
effect = EXCLUDED.effect,
|
||||
updated_by = EXCLUDED.updated_by,
|
||||
updated_at = NOW()
|
||||
RETURNING permission_id AS id`,
|
||||
[userId, permissionKey, effect, actorUserId]
|
||||
);
|
||||
if (!result[0]) throw new Error(`Unknown permission: ${permissionKey}`);
|
||||
}
|
||||
|
||||
export async function deleteUserPermissionOverride(userId: string, permissionKey: string): Promise<void> {
|
||||
await query(
|
||||
`DELETE FROM user_permission_overrides o
|
||||
USING permissions p
|
||||
WHERE o.permission_id = p.id AND o.user_id = $1 AND p.key = $2`,
|
||||
[userId, permissionKey]
|
||||
);
|
||||
}
|
||||
|
||||
export async function applyUserPermissionOverrideChanges(
|
||||
userId: string,
|
||||
changes: Array<{ key: string; action: 'allow' | 'deny' | 'reset' }>,
|
||||
actorUserId: string
|
||||
): Promise<void> {
|
||||
const client = await getClient();
|
||||
try {
|
||||
await beginAuthorizedTransaction(client);
|
||||
for (const change of changes) {
|
||||
if (change.action === 'reset') {
|
||||
await client.query(
|
||||
`DELETE FROM user_permission_overrides o
|
||||
USING permissions p
|
||||
WHERE o.permission_id = p.id AND o.user_id = $1 AND p.key = $2`,
|
||||
[userId, change.key]
|
||||
);
|
||||
continue;
|
||||
}
|
||||
const result = await client.query(
|
||||
`INSERT INTO user_permission_overrides (user_id, permission_id, effect, updated_by, updated_at)
|
||||
SELECT $1, p.id, $3, $4, NOW()
|
||||
FROM permissions p
|
||||
WHERE p.key = $2
|
||||
ON CONFLICT (user_id, permission_id) DO UPDATE SET
|
||||
effect = EXCLUDED.effect,
|
||||
updated_by = EXCLUDED.updated_by,
|
||||
updated_at = NOW()
|
||||
RETURNING permission_id`,
|
||||
[userId, change.key, change.action, actorUserId]
|
||||
);
|
||||
if (!result.rows[0]) throw new Error(`Unknown permission: ${change.key}`);
|
||||
}
|
||||
await client.query('COMMIT');
|
||||
} catch (e) {
|
||||
await client.query('ROLLBACK').catch(() => undefined);
|
||||
throw e;
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
}
|
||||
|
||||
export type PermissionBreakdownRow = {
|
||||
key: string;
|
||||
description: string | null;
|
||||
category: string | null;
|
||||
inherited: boolean;
|
||||
directAllow: boolean;
|
||||
directDeny: boolean;
|
||||
sources: string[];
|
||||
};
|
||||
|
||||
export async function getUserPermissionBreakdown(userId: string): Promise<PermissionBreakdownRow[]> {
|
||||
const [catalog, inherited, overrides, sources] = await Promise.all([
|
||||
listAllPermissions(),
|
||||
getUserInheritedPermissionKeys(userId),
|
||||
getUserPermissionOverrides(userId),
|
||||
query<{ key: string; role_name: string }[]>(
|
||||
`SELECT DISTINCT p.key, r.name AS role_name
|
||||
FROM user_roles ur
|
||||
JOIN roles r ON r.id = ur.role_id
|
||||
JOIN role_permissions rp ON rp.role_id = ur.role_id
|
||||
JOIN permissions p ON p.id = rp.permission_id
|
||||
WHERE ur.user_id = $1`,
|
||||
[userId]
|
||||
),
|
||||
]);
|
||||
const inheritedSet = new Set(inherited);
|
||||
const allowSet = new Set(overrides.filter((o) => o.effect === 'allow').map((o) => o.key));
|
||||
const denySet = new Set(overrides.filter((o) => o.effect === 'deny').map((o) => o.key));
|
||||
const sourcesByKey = new Map<string, string[]>();
|
||||
for (const row of sources) {
|
||||
const list = sourcesByKey.get(row.key) ?? [];
|
||||
list.push(row.role_name);
|
||||
sourcesByKey.set(row.key, list);
|
||||
}
|
||||
return catalog.map((p) => ({
|
||||
key: p.key,
|
||||
description: p.description,
|
||||
category: p.category,
|
||||
inherited: inheritedSet.has(p.key),
|
||||
directAllow: allowSet.has(p.key),
|
||||
directDeny: denySet.has(p.key),
|
||||
sources: sourcesByKey.get(p.key) ?? [],
|
||||
}));
|
||||
}
|
||||
|
||||
export type RoleAssignedUserRow = {
|
||||
id: string;
|
||||
email_encrypted: string | null;
|
||||
first_name: string | null;
|
||||
last_name: string | null;
|
||||
};
|
||||
|
||||
export async function listUsersForRole(roleId: number): Promise<RoleAssignedUserRow[]> {
|
||||
return query<RoleAssignedUserRow[]>(
|
||||
`SELECT u.id, u.email_encrypted, u.first_name, u.last_name
|
||||
FROM user_roles ur
|
||||
JOIN users u ON u.id = ur.user_id
|
||||
WHERE ur.role_id = $1 AND u.deleted_at IS NULL
|
||||
ORDER BY u.created_at DESC
|
||||
LIMIT 100`,
|
||||
[roleId]
|
||||
);
|
||||
}
|
||||
|
||||
export type AdminStaffListFilters = {
|
||||
searchHash?: string | null;
|
||||
searchText?: string | null;
|
||||
role?: string | null;
|
||||
exception?: 'all' | 'any' | 'allow' | 'deny' | 'none';
|
||||
permission?: string | null;
|
||||
limit: number;
|
||||
offset: number;
|
||||
};
|
||||
|
||||
export type AdminStaffListRow = {
|
||||
id: string;
|
||||
email_encrypted: string | null;
|
||||
first_name: string | null;
|
||||
last_name: string | null;
|
||||
is_enabled: boolean;
|
||||
roles: string[];
|
||||
inherited_count: number;
|
||||
allow_count: number;
|
||||
deny_count: number;
|
||||
effective_count: number;
|
||||
};
|
||||
|
||||
export async function listAdministrativeUsers(
|
||||
filters: AdminStaffListFilters
|
||||
): Promise<{ users: AdminStaffListRow[]; total: number }> {
|
||||
const conditions: string[] = ['u.deleted_at IS NULL'];
|
||||
const values: unknown[] = [];
|
||||
let i = 1;
|
||||
|
||||
conditions.push(`(
|
||||
EXISTS (
|
||||
SELECT 1 FROM user_roles urx
|
||||
JOIN roles rx ON rx.id = urx.role_id
|
||||
WHERE urx.user_id = u.id AND rx.name <> 'user'
|
||||
)
|
||||
OR EXISTS (SELECT 1 FROM user_permission_overrides ox WHERE ox.user_id = u.id)
|
||||
)`);
|
||||
|
||||
if (filters.role?.trim()) {
|
||||
conditions.push(`EXISTS (
|
||||
SELECT 1 FROM user_roles urf
|
||||
JOIN roles rf ON rf.id = urf.role_id
|
||||
WHERE urf.user_id = u.id AND rf.name = $${i++}
|
||||
)`);
|
||||
values.push(filters.role.trim().toLowerCase());
|
||||
}
|
||||
|
||||
if (filters.searchHash) {
|
||||
conditions.push(`u.email_hash = $${i++}`);
|
||||
values.push(filters.searchHash);
|
||||
} else if (filters.searchText) {
|
||||
conditions.push(`(
|
||||
u.first_name ILIKE $${i} OR u.last_name ILIKE $${i} OR u.id::text ILIKE $${i}
|
||||
)`);
|
||||
values.push(`%${filters.searchText}%`);
|
||||
i++;
|
||||
}
|
||||
|
||||
if (filters.exception === 'any') {
|
||||
conditions.push(`EXISTS (SELECT 1 FROM user_permission_overrides o WHERE o.user_id = u.id)`);
|
||||
} else if (filters.exception === 'allow') {
|
||||
conditions.push(
|
||||
`EXISTS (SELECT 1 FROM user_permission_overrides o WHERE o.user_id = u.id AND o.effect = 'allow')`
|
||||
);
|
||||
} else if (filters.exception === 'deny') {
|
||||
conditions.push(
|
||||
`EXISTS (SELECT 1 FROM user_permission_overrides o WHERE o.user_id = u.id AND o.effect = 'deny')`
|
||||
);
|
||||
} else if (filters.exception === 'none') {
|
||||
conditions.push(`NOT EXISTS (SELECT 1 FROM user_permission_overrides o WHERE o.user_id = u.id)`);
|
||||
}
|
||||
|
||||
if (filters.permission?.trim()) {
|
||||
conditions.push(`(
|
||||
(
|
||||
EXISTS (
|
||||
SELECT 1 FROM user_roles urp
|
||||
JOIN role_permissions rpp ON rpp.role_id = urp.role_id
|
||||
JOIN permissions pp ON pp.id = rpp.permission_id
|
||||
WHERE urp.user_id = u.id AND pp.key = $${i}
|
||||
)
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM user_permission_overrides oa
|
||||
JOIN permissions pa ON pa.id = oa.permission_id
|
||||
WHERE oa.user_id = u.id AND oa.effect = 'allow' AND pa.key = $${i}
|
||||
)
|
||||
)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM user_permission_overrides od
|
||||
JOIN permissions pd ON pd.id = od.permission_id
|
||||
WHERE od.user_id = u.id AND od.effect = 'deny' AND pd.key = $${i}
|
||||
)
|
||||
)`);
|
||||
values.push(filters.permission.trim());
|
||||
i++;
|
||||
}
|
||||
|
||||
const where = conditions.join(' AND ');
|
||||
const countRows = await query<{ count: string }[]>(
|
||||
`SELECT COUNT(*)::text AS count FROM users u WHERE ${where}`,
|
||||
values
|
||||
);
|
||||
const total = parseInt(countRows[0]?.count ?? '0', 10);
|
||||
|
||||
const limit = Math.min(Math.max(filters.limit, 1), 100);
|
||||
const offset = Math.max(filters.offset, 0);
|
||||
const listValues = [...values, limit, offset];
|
||||
const limitIdx = i;
|
||||
const offsetIdx = i + 1;
|
||||
|
||||
const rows = await query<
|
||||
{
|
||||
id: string;
|
||||
email_encrypted: string | null;
|
||||
first_name: string | null;
|
||||
last_name: string | null;
|
||||
is_enabled: boolean;
|
||||
roles: string[] | null;
|
||||
inherited_count: string;
|
||||
allow_count: string;
|
||||
deny_count: string;
|
||||
effective_count: string;
|
||||
}[]
|
||||
>(
|
||||
`SELECT u.id, u.email_encrypted, u.first_name, u.last_name, u.is_enabled,
|
||||
COALESCE((
|
||||
SELECT array_agg(r.name ORDER BY r.is_system DESC, r.name)
|
||||
FROM user_roles ur JOIN roles r ON r.id = ur.role_id
|
||||
WHERE ur.user_id = u.id
|
||||
), ARRAY[]::text[]) AS roles,
|
||||
COALESCE((
|
||||
SELECT COUNT(DISTINCT p.id)::text
|
||||
FROM user_roles ur
|
||||
JOIN role_permissions rp ON rp.role_id = ur.role_id
|
||||
JOIN permissions p ON p.id = rp.permission_id
|
||||
WHERE ur.user_id = u.id
|
||||
), '0') AS inherited_count,
|
||||
COALESCE((
|
||||
SELECT COUNT(*)::text FROM user_permission_overrides o
|
||||
WHERE o.user_id = u.id AND o.effect = 'allow'
|
||||
), '0') AS allow_count,
|
||||
COALESCE((
|
||||
SELECT COUNT(*)::text FROM user_permission_overrides o
|
||||
WHERE o.user_id = u.id AND o.effect = 'deny'
|
||||
), '0') AS deny_count,
|
||||
COALESCE((
|
||||
SELECT COUNT(*)::text FROM (
|
||||
SELECT p.key
|
||||
FROM user_roles ur
|
||||
JOIN role_permissions rp ON rp.role_id = ur.role_id
|
||||
JOIN permissions p ON p.id = rp.permission_id
|
||||
WHERE ur.user_id = u.id
|
||||
UNION
|
||||
SELECT p.key
|
||||
FROM user_permission_overrides oa
|
||||
JOIN permissions p ON p.id = oa.permission_id
|
||||
WHERE oa.user_id = u.id AND oa.effect = 'allow'
|
||||
) combined
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM user_permission_overrides od
|
||||
JOIN permissions pd ON pd.id = od.permission_id
|
||||
WHERE od.user_id = u.id AND od.effect = 'deny' AND pd.key = combined.key
|
||||
)
|
||||
), '0') AS effective_count
|
||||
FROM users u
|
||||
WHERE ${where}
|
||||
ORDER BY u.created_at DESC
|
||||
LIMIT $${limitIdx} OFFSET $${offsetIdx}`,
|
||||
listValues
|
||||
);
|
||||
|
||||
return {
|
||||
total,
|
||||
users: rows.map((r) => ({
|
||||
id: r.id,
|
||||
email_encrypted: r.email_encrypted,
|
||||
first_name: r.first_name,
|
||||
last_name: r.last_name,
|
||||
is_enabled: r.is_enabled,
|
||||
roles: Array.isArray(r.roles) ? r.roles : [],
|
||||
inherited_count: parseInt(r.inherited_count, 10) || 0,
|
||||
allow_count: parseInt(r.allow_count, 10) || 0,
|
||||
deny_count: parseInt(r.deny_count, 10) || 0,
|
||||
effective_count: parseInt(r.effective_count, 10) || 0,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
export async function getUserNameFields(
|
||||
userId: string
|
||||
): Promise<{ first_name: string | null; last_name: string | null } | null> {
|
||||
const rows = await query<{ first_name: string | null; last_name: string | null }[]>(
|
||||
`SELECT first_name, last_name FROM users WHERE id = $1 AND deleted_at IS NULL`,
|
||||
[userId]
|
||||
);
|
||||
return rows[0] ?? null;
|
||||
}
|
||||
|
||||
export async function userHasPermission(userId: string, permissionKey: string): Promise<boolean> {
|
||||
const perms = await getUserPermissions(userId);
|
||||
return resolvePermission(perms, permissionKey);
|
||||
|
||||
@ -61,6 +61,7 @@ function buildDefaults(): SystemSettings {
|
||||
candle_predict_backfill_interval_ms: config.candlePredict.backfillIntervalMs,
|
||||
|
||||
candle_predict_backfill_seed_max: config.candlePredict.backfillSeedMax,
|
||||
engine_audit_log_retention_days: 7,
|
||||
|
||||
withdrawal_network_fee_usdt_micro: config.withdrawal.networkFeeUsdtMicro,
|
||||
|
||||
@ -136,6 +137,8 @@ const INTEGER_KEYS = new Set([
|
||||
|
||||
'candle_predict_backfill_seed_max',
|
||||
|
||||
'engine_audit_log_retention_days',
|
||||
|
||||
'withdrawal_network_fee_usdt_micro',
|
||||
|
||||
'login_max_failed_attempts',
|
||||
@ -264,6 +267,8 @@ const UPDATABLE_KEYS = [
|
||||
|
||||
'candle_predict_backfill_seed_max',
|
||||
|
||||
'engine_audit_log_retention_days',
|
||||
|
||||
'withdrawal_network_fee_usdt_micro',
|
||||
|
||||
'require_admin_2fa',
|
||||
|
||||
@ -283,6 +283,10 @@ router.get('/admin/rbac/roles/:roleId', requireRoles('admin'), requirePermission
|
||||
router.post('/admin/rbac/roles', requireRoles('admin'), requirePermissions('admin.rbac.manage'), asyncHandler(rbacController.createRole));
|
||||
router.patch('/admin/rbac/roles/:roleId', requireRoles('admin'), requirePermissions('admin.rbac.manage'), asyncHandler(rbacController.updateRole));
|
||||
router.delete('/admin/rbac/roles/:roleId', requireRoles('admin'), requirePermissions('admin.rbac.manage'), asyncHandler(rbacController.deleteRole));
|
||||
router.get('/admin/rbac/admin-users', requireRoles('admin'), requirePermissions('admin.rbac.view'), asyncHandler(rbacController.listAdminUsers));
|
||||
router.get('/admin/rbac/admin-users/:userId/permissions', requireRoles('admin'), requirePermissions('admin.rbac.view'), asyncHandler(rbacController.getAdminUserPermissions));
|
||||
router.patch('/admin/rbac/admin-users/:userId/permissions', requireRoles('admin'), requirePermissions('admin.rbac.manage'), asyncHandler(rbacController.updateAdminUserPermissions));
|
||||
router.get('/admin/rbac/admin-users/:userId', requireRoles('admin'), requirePermissions('admin.rbac.view'), asyncHandler(rbacController.getAdminUser));
|
||||
router.get('/admin/rbac/me', authMiddleware, asyncHandler(rbacController.getMyPermissions));
|
||||
router.delete(
|
||||
'/admin/users/:userId',
|
||||
|
||||
43
backend/src/services/engineAuditRetentionService.ts
Normal file
43
backend/src/services/engineAuditRetentionService.ts
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Periodically deletes engine-only audit rows (prediction_round_settled)
|
||||
* older than the configured retention window.
|
||||
*/
|
||||
import * as settingsRepository from '../repositories/settingsRepository';
|
||||
import * as auditLogRepository from '../repositories/auditLogRepository';
|
||||
|
||||
const PURGE_INTERVAL_MS = 15 * 60 * 1000;
|
||||
const MAX_BATCHES_PER_RUN = 20;
|
||||
|
||||
let started = false;
|
||||
|
||||
export async function purgeExpiredEngineAuditLogs(): Promise<number> {
|
||||
const settings = await settingsRepository.getSettings();
|
||||
const days = settings.engine_audit_log_retention_days;
|
||||
if (!Number.isFinite(days) || days <= 0) return 0;
|
||||
|
||||
const cutoff = new Date(Date.now() - days * 24 * 60 * 60 * 1000);
|
||||
let deleted = 0;
|
||||
for (let i = 0; i < MAX_BATCHES_PER_RUN; i += 1) {
|
||||
const batch = await auditLogRepository.deleteEngineAuditLogsOlderThan(cutoff);
|
||||
deleted += batch;
|
||||
if (batch === 0) break;
|
||||
}
|
||||
if (deleted > 0) {
|
||||
console.log(`[engine-audit-retention] purged ${deleted} prediction_round_settled row(s) older than ${days} day(s)`);
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
|
||||
export function startEngineAuditRetentionJob(): void {
|
||||
if (started) return;
|
||||
started = true;
|
||||
const run = async () => {
|
||||
try {
|
||||
await purgeExpiredEngineAuditLogs();
|
||||
} catch (e) {
|
||||
console.error('[engine-audit-retention] purge failed:', e);
|
||||
}
|
||||
setTimeout(run, PURGE_INTERVAL_MS);
|
||||
};
|
||||
setTimeout(run, 20_000);
|
||||
}
|
||||
@ -6,6 +6,7 @@ import * as roleRepository from '../repositories/roleRepository';
|
||||
import * as auditLogRepository from '../repositories/auditLogRepository';
|
||||
import * as userRepository from '../repositories/userRepository';
|
||||
import { isSystemRole, PERMISSION_CATALOG } from '../rbac/permissionCatalog';
|
||||
import { decrypt, hashForIndex } from '../utils/crypto';
|
||||
|
||||
export type RoleDto = {
|
||||
id: number;
|
||||
@ -59,11 +60,14 @@ export async function listRoles(): Promise<RoleDto[]> {
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function getRole(roleId: number): Promise<RoleDto | null> {
|
||||
export async function getRole(roleId: number): Promise<(RoleDto & {
|
||||
assignedUsers: Array<{ id: string; email: string | null; fullName: string | null }>;
|
||||
}) | null> {
|
||||
const role = await roleRepository.findRoleById(roleId);
|
||||
if (!role) return null;
|
||||
const permissionKeys = await roleRepository.getRolePermissionKeys(roleId);
|
||||
const userCount = await roleRepository.countUsersWithRoleId(roleId);
|
||||
const assigned = await roleRepository.listUsersForRole(roleId);
|
||||
return {
|
||||
id: role.id,
|
||||
name: role.name,
|
||||
@ -71,6 +75,11 @@ export async function getRole(roleId: number): Promise<RoleDto | null> {
|
||||
isSystem: role.is_system,
|
||||
permissionKeys,
|
||||
userCount,
|
||||
assignedUsers: assigned.map((u) => ({
|
||||
id: u.id,
|
||||
email: decryptEmail(u.email_encrypted),
|
||||
fullName: fullName(u.first_name, u.last_name),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
@ -136,13 +145,17 @@ export async function updateRole(
|
||||
|
||||
let newName = role.name;
|
||||
if (input.name !== undefined) {
|
||||
const normalizedIncoming = input.name.trim().toLowerCase().replace(/\s+/g, '_');
|
||||
if (role.is_system) {
|
||||
throw new Error('System role names cannot be changed');
|
||||
}
|
||||
newName = validateCustomRoleName(input.name);
|
||||
const existing = await roleRepository.findRoleByName(newName);
|
||||
if (existing && existing.id !== roleId) {
|
||||
throw new Error('A role with this name already exists');
|
||||
if (normalizedIncoming !== role.name) {
|
||||
throw new Error('System role names cannot be changed');
|
||||
}
|
||||
} else {
|
||||
newName = validateCustomRoleName(input.name);
|
||||
const existing = await roleRepository.findRoleByName(newName);
|
||||
if (existing && existing.id !== roleId) {
|
||||
throw new Error('A role with this name already exists');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,3 +213,187 @@ async function bumpTokenVersionForRoleUsers(roleId: number): Promise<void> {
|
||||
export async function bumpUserTokenOnRoleChange(userId: string): Promise<void> {
|
||||
await userRepository.incrementTokenVersion(userId);
|
||||
}
|
||||
|
||||
function decryptEmail(encrypted: string | null): string | null {
|
||||
if (!encrypted) return null;
|
||||
try {
|
||||
return decrypt(encrypted);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function fullName(first: string | null, last: string | null): string | null {
|
||||
const name = [first, last].filter(Boolean).join(' ').trim();
|
||||
return name || null;
|
||||
}
|
||||
|
||||
async function assertAdministrativeUser(userId: string): Promise<string[]> {
|
||||
const user = await userRepository.getForAdmin(userId);
|
||||
if (!user) throw new Error('User not found');
|
||||
const roles = await roleRepository.getUserRoleNames(userId);
|
||||
const overrides = await roleRepository.getUserPermissionOverrides(userId);
|
||||
const isAdminStaff = roles.some((r) => r !== 'user') || overrides.length > 0;
|
||||
if (!isAdminStaff) {
|
||||
throw new Error('Permission overrides can only be applied to administrative users');
|
||||
}
|
||||
return roles;
|
||||
}
|
||||
|
||||
export type AdminStaffUserDto = {
|
||||
id: string;
|
||||
email: string | null;
|
||||
fullName: string | null;
|
||||
isEnabled: boolean;
|
||||
roles: string[];
|
||||
inheritedCount: number;
|
||||
allowCount: number;
|
||||
denyCount: number;
|
||||
effectiveCount: number;
|
||||
};
|
||||
|
||||
export async function listAdminUsers(filters: {
|
||||
search?: string;
|
||||
role?: string;
|
||||
exception?: 'all' | 'any' | 'allow' | 'deny' | 'none';
|
||||
permission?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
}): Promise<{ users: AdminStaffUserDto[]; total: number }> {
|
||||
const search = filters.search?.trim() ?? '';
|
||||
let searchHash: string | null = null;
|
||||
let searchText: string | null = null;
|
||||
if (search.includes('@')) {
|
||||
searchHash = hashForIndex(search.toLowerCase());
|
||||
} else if (search) {
|
||||
searchText = search;
|
||||
}
|
||||
|
||||
const result = await roleRepository.listAdministrativeUsers({
|
||||
searchHash,
|
||||
searchText,
|
||||
role: filters.role ?? null,
|
||||
exception: filters.exception ?? 'all',
|
||||
permission: filters.permission ?? null,
|
||||
limit: filters.limit ?? 50,
|
||||
offset: filters.offset ?? 0,
|
||||
});
|
||||
|
||||
return {
|
||||
total: result.total,
|
||||
users: result.users.map((u) => ({
|
||||
id: u.id,
|
||||
email: decryptEmail(u.email_encrypted),
|
||||
fullName: fullName(u.first_name, u.last_name),
|
||||
isEnabled: u.is_enabled,
|
||||
roles: u.roles,
|
||||
inheritedCount: u.inherited_count,
|
||||
allowCount: u.allow_count,
|
||||
denyCount: u.deny_count,
|
||||
effectiveCount: u.effective_count,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
export type UserPermissionItemDto = {
|
||||
key: string;
|
||||
description: string | null;
|
||||
category: string | null;
|
||||
inherited: boolean;
|
||||
directAllow: boolean;
|
||||
directDeny: boolean;
|
||||
effective: boolean;
|
||||
sources: string[];
|
||||
};
|
||||
|
||||
export async function getAdminUser(userId: string): Promise<{
|
||||
user: AdminStaffUserDto;
|
||||
permissions: UserPermissionItemDto[];
|
||||
categories: Record<string, UserPermissionItemDto[]>;
|
||||
} | null> {
|
||||
const user = await userRepository.getForAdmin(userId);
|
||||
if (!user) return null;
|
||||
const [roles, inherited, overrides, breakdown, names] = await Promise.all([
|
||||
roleRepository.getUserRoleNames(userId),
|
||||
roleRepository.getUserInheritedPermissionKeys(userId),
|
||||
roleRepository.getUserPermissionOverrides(userId),
|
||||
roleRepository.getUserPermissionBreakdown(userId),
|
||||
roleRepository.getUserNameFields(userId),
|
||||
]);
|
||||
const allow = overrides.filter((o) => o.effect === 'allow');
|
||||
const deny = overrides.filter((o) => o.effect === 'deny');
|
||||
const items: UserPermissionItemDto[] = breakdown.map((p) => ({
|
||||
key: p.key,
|
||||
description: p.description,
|
||||
category: p.category,
|
||||
inherited: p.inherited,
|
||||
directAllow: p.directAllow,
|
||||
directDeny: p.directDeny,
|
||||
effective: (p.inherited || p.directAllow) && !p.directDeny,
|
||||
sources: p.sources,
|
||||
}));
|
||||
const categories: Record<string, UserPermissionItemDto[]> = {};
|
||||
for (const item of items) {
|
||||
const cat = item.category ?? 'other';
|
||||
if (!categories[cat]) categories[cat] = [];
|
||||
categories[cat].push(item);
|
||||
}
|
||||
return {
|
||||
user: {
|
||||
id: user.id,
|
||||
email: decryptEmail(user.email_encrypted),
|
||||
fullName: fullName(names?.first_name ?? null, names?.last_name ?? null),
|
||||
isEnabled: user.is_enabled,
|
||||
roles,
|
||||
inheritedCount: inherited.length,
|
||||
allowCount: allow.length,
|
||||
denyCount: deny.length,
|
||||
effectiveCount: items.filter((p) => p.effective).length,
|
||||
},
|
||||
permissions: items,
|
||||
categories,
|
||||
};
|
||||
}
|
||||
|
||||
export async function applyUserPermissionChanges(
|
||||
userId: string,
|
||||
changes: Array<{ key: string; action: 'allow' | 'deny' | 'reset' }>,
|
||||
actorUserId: string
|
||||
): Promise<{
|
||||
user: AdminStaffUserDto;
|
||||
permissions: UserPermissionItemDto[];
|
||||
categories: Record<string, UserPermissionItemDto[]>;
|
||||
}> {
|
||||
if (!changes.length) throw new Error('At least one permission change is required');
|
||||
await assertAdministrativeUser(userId);
|
||||
const catalogKeys = new Set(PERMISSION_CATALOG.map((p) => p.key));
|
||||
|
||||
for (const change of changes) {
|
||||
if (!catalogKeys.has(change.key)) {
|
||||
throw new Error(`Unknown permission: ${change.key}`);
|
||||
}
|
||||
}
|
||||
|
||||
await roleRepository.applyUserPermissionOverrideChanges(userId, changes, actorUserId);
|
||||
await bumpUserTokenOnRoleChange(userId);
|
||||
|
||||
for (const change of changes) {
|
||||
const action =
|
||||
change.action === 'allow'
|
||||
? 'admin_user_permission_override_added'
|
||||
: change.action === 'deny'
|
||||
? 'admin_user_permission_override_removed'
|
||||
: 'admin_user_permission_override_reset';
|
||||
await auditLogRepository.create({
|
||||
userId: actorUserId,
|
||||
action,
|
||||
resourceType: 'user',
|
||||
resourceId: userId,
|
||||
metadata: { permissionKey: change.key, effect: change.action },
|
||||
});
|
||||
}
|
||||
|
||||
const updated = await getAdminUser(userId);
|
||||
if (!updated) throw new Error('User not found');
|
||||
return updated;
|
||||
}
|
||||
|
||||
@ -127,6 +127,20 @@ function validateUpdates(updates: Partial<SystemSettings>): void {
|
||||
|
||||
}
|
||||
|
||||
if (updates.engine_audit_log_retention_days !== undefined) {
|
||||
|
||||
updates.engine_audit_log_retention_days = clampInt(
|
||||
|
||||
updates.engine_audit_log_retention_days,
|
||||
|
||||
0,
|
||||
|
||||
365
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (updates.withdrawal_network_fee_usdt_micro !== undefined) {
|
||||
|
||||
updates.withdrawal_network_fee_usdt_micro = clampInt(
|
||||
@ -309,6 +323,12 @@ export function parseSettingsUpdates(body: Record<string, unknown>): Partial<Sys
|
||||
|
||||
}
|
||||
|
||||
if (typeof body.engine_audit_log_retention_days === 'number') {
|
||||
|
||||
updates.engine_audit_log_retention_days = body.engine_audit_log_retention_days;
|
||||
|
||||
}
|
||||
|
||||
if (typeof body.withdrawal_network_fee_usdt_micro === 'number') {
|
||||
|
||||
updates.withdrawal_network_fee_usdt_micro = body.withdrawal_network_fee_usdt_micro;
|
||||
|
||||
41
backend/src/tests/permissionMerge.test.ts
Normal file
41
backend/src/tests/permissionMerge.test.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { describe, test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import { mergePermissionSets } from '../rbac/permissionResolver';
|
||||
|
||||
describe('mergePermissionSets', () => {
|
||||
test('adds individual allows on top of inherited role permissions', () => {
|
||||
const effective = mergePermissionSets(
|
||||
['admin.users.view', 'admin.reports.view'],
|
||||
['admin.treasury.view'],
|
||||
[]
|
||||
);
|
||||
assert.deepEqual(effective, ['admin.reports.view', 'admin.treasury.view', 'admin.users.view']);
|
||||
});
|
||||
|
||||
test('individual deny removes an inherited permission without affecting others', () => {
|
||||
const effective = mergePermissionSets(
|
||||
['admin.users.view', 'admin.users.edit', 'admin.users.delete'],
|
||||
[],
|
||||
['admin.users.delete']
|
||||
);
|
||||
assert.deepEqual(effective, ['admin.users.edit', 'admin.users.view']);
|
||||
});
|
||||
|
||||
test('deny wins over a matching direct allow', () => {
|
||||
const effective = mergePermissionSets(
|
||||
['admin.users.view'],
|
||||
['admin.users.delete'],
|
||||
['admin.users.delete']
|
||||
);
|
||||
assert.deepEqual(effective, ['admin.users.view']);
|
||||
});
|
||||
|
||||
test('reset is represented by omitting the key from allow and deny', () => {
|
||||
const inherited = ['admin.users.view', 'admin.reports.view'];
|
||||
const afterDeny = mergePermissionSets(inherited, [], ['admin.reports.view']);
|
||||
assert.deepEqual(afterDeny, ['admin.users.view']);
|
||||
const afterReset = mergePermissionSets(inherited, [], []);
|
||||
assert.deepEqual(afterReset, inherited.slice().sort());
|
||||
});
|
||||
});
|
||||
@ -101,6 +101,7 @@ export const paginationQuerySchema = z.object({
|
||||
export const auditLogQuerySchema = paginationQuerySchema.extend({
|
||||
action: z.string().trim().max(128).optional(),
|
||||
actions: commaActionsQuery,
|
||||
excludeActions: commaActionsQuery,
|
||||
userId: optionalUuidQuery,
|
||||
from: optionalIsoDateQuery,
|
||||
to: optionalIsoDateQuery,
|
||||
|
||||
@ -38,6 +38,8 @@ import { FaqPublicPage } from '../../features/faq/FaqPublicPage';
|
||||
import { FaqPage } from '../../features/faq/FaqPage';
|
||||
import { FaqAdminPage } from '../../features/faq/FaqAdminPage';
|
||||
import { RoleManagementPage } from '../../features/rbac/RoleManagementPage';
|
||||
import { AdminUsersPage } from '../../features/rbac/AdminUsersPage';
|
||||
import { AdminUserPermissionsPage } from '../../features/rbac/AdminUserPermissionsPage';
|
||||
import { GamePlayRoute } from '../../features/games/GamePlayRoute';
|
||||
|
||||
/** Browser router instance with login, dashboard, options, and admin route trees. */
|
||||
@ -116,6 +118,8 @@ export const router = createBrowserRouter([
|
||||
{ path: 'admin/countries', element: <CountriesAdminPage /> },
|
||||
{ path: 'admin/network', element: <NetworkStatusPage /> },
|
||||
{ path: 'admin/rbac', element: <RoleManagementPage /> },
|
||||
{ path: 'admin/admin-users', element: <AdminUsersPage /> },
|
||||
{ path: 'admin/admin-users/:userId/permissions', element: <AdminUserPermissionsPage /> },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@ -6,6 +6,10 @@ import { createTheme, type ThemeOptions } from '@mui/material/styles';
|
||||
import { enUS, frFR } from '@mui/material/locale';
|
||||
import { normalizeLocale } from '../../shared/i18n';
|
||||
|
||||
const SURFACE_BORDER = '1px solid rgba(255,255,255,0.12)';
|
||||
const SURFACE_BG = '#1B2438';
|
||||
const NESTED_SURFACE_BG = 'rgba(255,255,255,0.045)';
|
||||
|
||||
const baseThemeOptions: ThemeOptions = {
|
||||
palette: {
|
||||
mode: 'dark',
|
||||
@ -13,10 +17,10 @@ const baseThemeOptions: ThemeOptions = {
|
||||
secondary: { main: '#7C5CFF' }, // bonus / accent purple
|
||||
background: {
|
||||
default: '#0B0F1A',
|
||||
paper: '#12182B',
|
||||
paper: SURFACE_BG,
|
||||
},
|
||||
},
|
||||
shape: { borderRadius: 14 },
|
||||
shape: { borderRadius: 8 },
|
||||
typography: {
|
||||
fontFamily: [
|
||||
'system-ui',
|
||||
@ -28,16 +32,73 @@ const baseThemeOptions: ThemeOptions = {
|
||||
].join(','),
|
||||
},
|
||||
components: {
|
||||
MuiPaper: {
|
||||
styleOverrides: {
|
||||
root: {
|
||||
backgroundImage: 'none',
|
||||
backgroundColor: SURFACE_BG,
|
||||
borderRadius: 12,
|
||||
'&:not(.MuiDrawer-paper):not(.MuiAppBar-root):not(.MuiDialog-paper):not(.MuiAccordion-root):not(.MuiPopover-paper)':
|
||||
{
|
||||
border: SURFACE_BORDER,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
MuiCard: {
|
||||
styleOverrides: {
|
||||
root: {
|
||||
border: '1px solid rgba(255,255,255,0.06)',
|
||||
borderRadius: 12,
|
||||
border: SURFACE_BORDER,
|
||||
backgroundImage: 'none',
|
||||
backgroundColor: SURFACE_BG,
|
||||
},
|
||||
},
|
||||
},
|
||||
MuiAccordion: {
|
||||
defaultProps: { disableGutters: true, elevation: 0 },
|
||||
styleOverrides: {
|
||||
root: {
|
||||
backgroundImage: 'none',
|
||||
backgroundColor: NESTED_SURFACE_BG,
|
||||
border: SURFACE_BORDER,
|
||||
borderRadius: 12,
|
||||
overflow: 'hidden',
|
||||
'&:before': { display: 'none' },
|
||||
'&:not(:last-of-type)': { marginBottom: 8 },
|
||||
},
|
||||
},
|
||||
},
|
||||
MuiAccordionSummary: {
|
||||
styleOverrides: {
|
||||
root: {
|
||||
minHeight: 64,
|
||||
},
|
||||
},
|
||||
},
|
||||
MuiAlert: {
|
||||
styleOverrides: {
|
||||
root: {
|
||||
border: SURFACE_BORDER,
|
||||
},
|
||||
},
|
||||
},
|
||||
MuiDialog: {
|
||||
styleOverrides: {
|
||||
paper: {
|
||||
borderRadius: 12,
|
||||
border: SURFACE_BORDER,
|
||||
backgroundImage: 'none',
|
||||
},
|
||||
},
|
||||
},
|
||||
MuiButton: {
|
||||
defaultProps: { disableElevation: true },
|
||||
styleOverrides: {
|
||||
root: {
|
||||
borderRadius: 10,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@ -76,7 +76,7 @@ export function VerifyEmailPage() {
|
||||
width: '100%',
|
||||
maxWidth: 480,
|
||||
p: { xs: 3, sm: 4 },
|
||||
borderRadius: 4,
|
||||
borderRadius: 2,
|
||||
border: '1px solid rgba(255,255,255,0.08)',
|
||||
}}
|
||||
>
|
||||
|
||||
@ -608,7 +608,7 @@ export function CandlePredictPage() {
|
||||
<Stack spacing={2} sx={{ minWidth: 0, height: '100%' }}>
|
||||
{isAdmin && <AdminPoolInsights config={config} interval={interval} round={round} />}
|
||||
|
||||
<Paper sx={{ p: { xs: 1.5, sm: 2 }, borderRadius: 3, display: { xs: 'block', lg: 'none' } }}>
|
||||
<Paper sx={{ p: { xs: 1.5, sm: 2 }, borderRadius: 2, display: { xs: 'block', lg: 'none' } }}>
|
||||
{renderBettingPanels()}
|
||||
</Paper>
|
||||
|
||||
|
||||
@ -299,7 +299,7 @@ export function AutoPredictionPanel({
|
||||
<Box
|
||||
sx={{
|
||||
p: { xs: 1.5, md: 2 },
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
border: '1px solid rgba(255,255,255,0.08)',
|
||||
background: 'rgba(124,92,255,0.04)',
|
||||
}}
|
||||
@ -342,7 +342,7 @@ export function AutoPredictionPanel({
|
||||
<Box
|
||||
sx={{
|
||||
p: { xs: 1.5, md: 2 },
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
border: '1px solid rgba(124,92,255,0.35)',
|
||||
background: 'rgba(124,92,255,0.08)',
|
||||
}}
|
||||
@ -407,7 +407,7 @@ export function AutoPredictionPanel({
|
||||
<Box
|
||||
sx={{
|
||||
p: { xs: 2, md: 2.5 },
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
border: '1px solid rgba(255,255,255,0.08)',
|
||||
background: 'rgba(124,92,255,0.06)',
|
||||
}}
|
||||
|
||||
@ -80,7 +80,7 @@ export function BettingPanel({
|
||||
<Box
|
||||
sx={{
|
||||
p: { xs: 2, md: 2.5 },
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
border: '1px solid rgba(255,255,255,0.08)',
|
||||
background: 'linear-gradient(145deg, rgba(214,178,94,0.08), rgba(18,23,36,0.92))',
|
||||
}}
|
||||
|
||||
@ -237,7 +237,7 @@ export const CandlestickChart = memo(function CandlestickChart({
|
||||
sx={{
|
||||
width: '100%',
|
||||
...(fillHeight ? { height: '100%', minHeight: height } : { minHeight: height }),
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
overflow: 'hidden',
|
||||
border: '1px solid rgba(255,255,255,0.08)',
|
||||
background:
|
||||
|
||||
@ -124,7 +124,7 @@ export function MultiCandleBettingPanel({
|
||||
<Box
|
||||
sx={{
|
||||
p: { xs: 2, md: 2.5 },
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
border: '1px solid rgba(255,255,255,0.08)',
|
||||
background: 'linear-gradient(145deg, rgba(94,178,214,0.1), rgba(18,23,36,0.92))',
|
||||
}}
|
||||
@ -167,7 +167,7 @@ export function MultiCandleBettingPanel({
|
||||
<Box
|
||||
sx={{
|
||||
p: { xs: 2, md: 2.5 },
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
border: '1px solid rgba(255,255,255,0.08)',
|
||||
background: 'linear-gradient(145deg, rgba(94,178,214,0.1), rgba(18,23,36,0.92))',
|
||||
}}
|
||||
|
||||
@ -29,7 +29,7 @@ export function PoolBar({ round, poolWinnerRule }: Props) {
|
||||
<Box
|
||||
sx={{
|
||||
p: 2,
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
border: '1px solid rgba(255,255,255,0.08)',
|
||||
background: 'rgba(18,23,36,0.85)',
|
||||
}}
|
||||
@ -53,9 +53,9 @@ export function PoolBar({ round, poolWinnerRule }: Props) {
|
||||
value={shortPct}
|
||||
sx={{
|
||||
height: 8,
|
||||
borderRadius: 4,
|
||||
borderRadius: '4px',
|
||||
backgroundColor: alpha('#EF5350', 0.15),
|
||||
'& .MuiLinearProgress-bar': { backgroundColor: '#EF5350', borderRadius: 4 },
|
||||
'& .MuiLinearProgress-bar': { backgroundColor: '#EF5350', borderRadius: '4px' },
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
@ -74,9 +74,9 @@ export function PoolBar({ round, poolWinnerRule }: Props) {
|
||||
value={longPct}
|
||||
sx={{
|
||||
height: 8,
|
||||
borderRadius: 4,
|
||||
borderRadius: '4px',
|
||||
backgroundColor: alpha('#4CAF50', 0.15),
|
||||
'& .MuiLinearProgress-bar': { backgroundColor: '#4CAF50', borderRadius: 4 },
|
||||
'& .MuiLinearProgress-bar': { backgroundColor: '#4CAF50', borderRadius: '4px' },
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
@ -425,7 +425,7 @@ export function RecentPredictionsPanel({
|
||||
const cols = 'candlePredict.recentPredictions.columns';
|
||||
|
||||
return (
|
||||
<Paper sx={{ p: 2, borderRadius: 3, minWidth: 0 }}>
|
||||
<Paper sx={{ p: 2, borderRadius: 2, minWidth: 0 }}>
|
||||
<Stack
|
||||
direction="row"
|
||||
spacing={1}
|
||||
|
||||
@ -56,7 +56,7 @@ export function CandlePredictMultiLevelsPanel() {
|
||||
};
|
||||
|
||||
return (
|
||||
<Paper sx={{ p: 2.5, borderRadius: 3, mt: 3 }}>
|
||||
<Paper sx={{ p: 2.5, borderRadius: 2, mt: 3 }}>
|
||||
<Stack spacing={2}>
|
||||
<Box>
|
||||
<Typography variant="h6" sx={{ fontWeight: 900 }}>
|
||||
|
||||
@ -266,7 +266,7 @@ export function CatalogAdminPage() {
|
||||
}}
|
||||
>
|
||||
{sortedGames.map((game) => (
|
||||
<Card key={game.id} variant="outlined" sx={{ borderRadius: 3 }}>
|
||||
<Card key={game.id} variant="outlined" sx={{ borderRadius: 2 }}>
|
||||
<CardContent>
|
||||
<Stack spacing={1}>
|
||||
<Stack
|
||||
@ -354,7 +354,7 @@ export function CatalogAdminPage() {
|
||||
}}
|
||||
>
|
||||
{sortedAds.map((ad) => (
|
||||
<Card key={ad.id} variant="outlined" sx={{ borderRadius: 3 }}>
|
||||
<Card key={ad.id} variant="outlined" sx={{ borderRadius: 2 }}>
|
||||
<CardContent>
|
||||
<Stack spacing={1}>
|
||||
<Stack
|
||||
|
||||
@ -27,6 +27,7 @@ import { api } from '../../shared/services/api';
|
||||
import { useAuth } from '../../shared/auth/AuthContext';
|
||||
import { ScrollableTable } from '../../shared/components/ScrollableTable';
|
||||
import { PermissionGate } from '../../shared/auth/PermissionGate';
|
||||
import { fetchAdminCountries, adminCountryItems } from './useCountryNames';
|
||||
|
||||
type CountryRow = {
|
||||
code: string;
|
||||
@ -44,11 +45,13 @@ export function CountriesAdminPage() {
|
||||
|
||||
const q = useQuery({
|
||||
queryKey: ['admin-countries'],
|
||||
queryFn: async () => {
|
||||
const res = await api.get<{ items: CountryRow[]; total: number }>('/api/v1/admin/countries');
|
||||
return res.data;
|
||||
},
|
||||
queryFn: fetchAdminCountries,
|
||||
});
|
||||
const countryRows: CountryRow[] = adminCountryItems(q.data).map((c) => ({
|
||||
code: c.code,
|
||||
name: c.name,
|
||||
registrationAllowed: c.registrationAllowed !== false,
|
||||
}));
|
||||
|
||||
const syncMut = useMutation({
|
||||
mutationFn: async () => {
|
||||
@ -69,16 +72,15 @@ export function CountriesAdminPage() {
|
||||
});
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
const items = q.data?.items ?? [];
|
||||
const term = search.trim().toLowerCase();
|
||||
return items.filter((c) => {
|
||||
return countryRows.filter((c) => {
|
||||
if (showBlockedOnly && c.registrationAllowed) return false;
|
||||
if (!term) return true;
|
||||
return c.name.toLowerCase().includes(term) || c.code.toLowerCase().includes(term);
|
||||
});
|
||||
}, [q.data?.items, search, showBlockedOnly]);
|
||||
}, [countryRows, search, showBlockedOnly]);
|
||||
|
||||
const blockedCount = (q.data?.items ?? []).filter((c) => !c.registrationAllowed).length;
|
||||
const blockedCount = countryRows.filter((c) => !c.registrationAllowed).length;
|
||||
|
||||
return (
|
||||
<Box sx={{ minWidth: 0 }}>
|
||||
@ -138,13 +140,13 @@ export function CountriesAdminPage() {
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{q.data?.total === 0 && (
|
||||
{countryRows.length === 0 && !q.isLoading && !q.isError && (
|
||||
<Alert severity="warning" sx={{ mb: 2 }}>
|
||||
{t('admin.countries.emptyDb')}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent>
|
||||
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={1.5} sx={{ mb: 2 }}>
|
||||
<TextField
|
||||
|
||||
@ -4,26 +4,62 @@ import { api } from '../../shared/services/api';
|
||||
|
||||
const UNKNOWN_COUNTRY_CODE = 'XX';
|
||||
|
||||
export type AdminCountryItem = {
|
||||
code: string;
|
||||
name: string;
|
||||
registrationAllowed?: boolean;
|
||||
};
|
||||
|
||||
export type AdminCountriesPayload = {
|
||||
items: AdminCountryItem[];
|
||||
total: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Shared fetch for the admin country catalog.
|
||||
* Always returns `{ items, total }` so every `['admin-countries']` consumer
|
||||
* shares the same React Query cache shape.
|
||||
*/
|
||||
export async function fetchAdminCountries(): Promise<AdminCountriesPayload> {
|
||||
const res = await api.get<{ items?: AdminCountryItem[]; total?: number } | AdminCountryItem[]>(
|
||||
'/api/v1/admin/countries'
|
||||
);
|
||||
return normalizeAdminCountries(res.data);
|
||||
}
|
||||
|
||||
export function normalizeAdminCountries(
|
||||
data: { items?: AdminCountryItem[]; total?: number } | AdminCountryItem[] | undefined
|
||||
): AdminCountriesPayload {
|
||||
if (Array.isArray(data)) {
|
||||
return { items: data, total: data.length };
|
||||
}
|
||||
const items = Array.isArray(data?.items) ? data.items : [];
|
||||
return { items, total: typeof data?.total === 'number' ? data.total : items.length };
|
||||
}
|
||||
|
||||
export function adminCountryItems(
|
||||
data: AdminCountriesPayload | AdminCountryItem[] | undefined
|
||||
): AdminCountryItem[] {
|
||||
return normalizeAdminCountries(data).items;
|
||||
}
|
||||
|
||||
/** Resolves ISO 3166-1 alpha-2 codes to country names (admin catalog). */
|
||||
export function useCountryNames() {
|
||||
const q = useQuery({
|
||||
queryKey: ['admin-countries'],
|
||||
queryFn: async () => {
|
||||
const res = await api.get<{ items: Array<{ code: string; name: string }> }>(
|
||||
'/api/v1/admin/countries'
|
||||
);
|
||||
return res.data.items ?? [];
|
||||
},
|
||||
queryFn: fetchAdminCountries,
|
||||
staleTime: 5 * 60_000,
|
||||
});
|
||||
|
||||
const items = adminCountryItems(q.data);
|
||||
|
||||
const nameByCode = useMemo(() => {
|
||||
const map = new Map<string, string>();
|
||||
for (const c of q.data ?? []) {
|
||||
for (const c of items) {
|
||||
map.set(c.code, c.name);
|
||||
}
|
||||
return map;
|
||||
}, [q.data]);
|
||||
}, [items]);
|
||||
|
||||
const label = useCallback(
|
||||
(code: string | null | undefined) => {
|
||||
|
||||
@ -52,7 +52,7 @@ export function DashboardFiltersBar({
|
||||
<Box
|
||||
sx={{
|
||||
p: 2,
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
border: '1px solid rgba(255,255,255,0.08)',
|
||||
bgcolor: 'rgba(255,255,255,0.02)',
|
||||
mb: 3,
|
||||
|
||||
@ -147,7 +147,7 @@ export function HomePage() {
|
||||
sx={{
|
||||
p: { xs: 2, md: 2.5 },
|
||||
mb: 2.5,
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
border: '1px solid rgba(255,255,255,0.06)',
|
||||
background:
|
||||
'linear-gradient(90deg, rgba(214,178,94,0.06) 0%, rgba(124,92,255,0.04) 100%)',
|
||||
@ -197,7 +197,7 @@ export function HomePage() {
|
||||
}}
|
||||
>
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} variant="rounded" sx={{ height: 280, borderRadius: 3 }} />
|
||||
<Skeleton key={i} variant="rounded" sx={{ height: 280, borderRadius: 2 }} />
|
||||
))}
|
||||
</Box>
|
||||
) : filtered.length === 0 ? (
|
||||
|
||||
@ -50,7 +50,7 @@ export function GameCard({ game, onPlay }: Props) {
|
||||
<Card
|
||||
sx={{
|
||||
height: '100%',
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
overflow: 'hidden',
|
||||
border: `1px solid ${alpha(accent, 0.22)}`,
|
||||
transition: 'transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease',
|
||||
|
||||
@ -44,7 +44,7 @@ export function PromoCarousel({ ads, loading }: Props) {
|
||||
return (
|
||||
<Skeleton
|
||||
variant="rounded"
|
||||
sx={{ height: { xs: 220, sm: 280, md: 320 }, borderRadius: 4 }}
|
||||
sx={{ height: { xs: 220, sm: 280, md: 320 }, borderRadius: 2 }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@ -54,7 +54,7 @@ export function PromoCarousel({ ads, loading }: Props) {
|
||||
<Paper
|
||||
sx={{
|
||||
p: { xs: 3, md: 4 },
|
||||
borderRadius: 4,
|
||||
borderRadius: 2,
|
||||
minHeight: { xs: 200, md: 280 },
|
||||
display: 'grid',
|
||||
placeItems: 'center',
|
||||
@ -81,7 +81,7 @@ export function PromoCarousel({ ads, loading }: Props) {
|
||||
sx={{
|
||||
position: 'relative',
|
||||
overflow: 'hidden',
|
||||
borderRadius: 4,
|
||||
borderRadius: 2,
|
||||
minHeight: { xs: 220, sm: 280, md: 320 },
|
||||
border: `1px solid ${alpha(accent, 0.35)}`,
|
||||
background: bg,
|
||||
|
||||
@ -25,7 +25,7 @@ export function PromoStrip({ ads }: Props) {
|
||||
<Paper
|
||||
sx={{
|
||||
p: 2,
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
height: '100%',
|
||||
border: `1px solid ${alpha(accent, 0.25)}`,
|
||||
background: ad.backgroundGradient || `linear-gradient(135deg, ${alpha(accent, 0.15)}, rgba(18,23,36,0.9))`,
|
||||
|
||||
@ -19,6 +19,7 @@ import ShieldRoundedIcon from '@mui/icons-material/ShieldRounded';
|
||||
import HeadsetMicRoundedIcon from '@mui/icons-material/HeadsetMicRounded';
|
||||
import HelpOutlineRoundedIcon from '@mui/icons-material/HelpOutlineRounded';
|
||||
import AdminPanelSettingsRoundedIcon from '@mui/icons-material/AdminPanelSettingsRounded';
|
||||
import ManageAccountsRoundedIcon from '@mui/icons-material/ManageAccountsRounded';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useAuth } from '../../shared/auth/AuthContext';
|
||||
@ -39,7 +40,8 @@ type OptionCardKey =
|
||||
| 'faq'
|
||||
| 'support'
|
||||
| 'countries'
|
||||
| 'rbac';
|
||||
| 'rbac'
|
||||
| 'adminUsers';
|
||||
|
||||
type OptionCardConfig = {
|
||||
key: OptionCardKey;
|
||||
@ -188,6 +190,15 @@ const OPTION_CARDS: OptionCardConfig[] = [
|
||||
bg: 'rgba(124,92,255,0.16)',
|
||||
border: 'rgba(124,92,255,0.22)',
|
||||
},
|
||||
{
|
||||
key: 'adminUsers',
|
||||
path: '/admin/admin-users',
|
||||
icon: ManageAccountsRoundedIcon,
|
||||
badgeKey: 'accessControl',
|
||||
badgeColor: 'secondary',
|
||||
bg: 'rgba(214,178,94,0.16)',
|
||||
border: 'rgba(214,178,94,0.22)',
|
||||
},
|
||||
];
|
||||
|
||||
/** Landing page for administrative tools and configuration shortcuts. */
|
||||
@ -221,7 +232,7 @@ export function OptionsPage() {
|
||||
{visibleCards.map((card) => {
|
||||
const Icon = card.icon;
|
||||
return (
|
||||
<Card key={card.key} sx={{ gridColumn: { xs: '1 / -1', md: 'span 6' }, borderRadius: 3 }}>
|
||||
<Card key={card.key} sx={{ gridColumn: { xs: '1 / -1', md: 'span 6' } }}>
|
||||
<CardActionArea onClick={() => nav(card.path)} sx={{ height: '100%' }}>
|
||||
<CardContent sx={{ p: 2.5 }}>
|
||||
<Stack direction="row" spacing={1.5} sx={{ alignItems: 'flex-start' }}>
|
||||
|
||||
@ -80,7 +80,7 @@ export function ProfilePage() {
|
||||
sx={{
|
||||
p: { xs: 2.5, md: 3 },
|
||||
mb: 2.5,
|
||||
borderRadius: 4,
|
||||
borderRadius: 2,
|
||||
border: '1px solid rgba(214,178,94,0.25)',
|
||||
background:
|
||||
'linear-gradient(135deg, rgba(214,178,94,0.16) 0%, rgba(124,92,255,0.1) 60%, rgba(18,23,36,0.92) 100%)',
|
||||
@ -160,7 +160,7 @@ export function ProfilePage() {
|
||||
gridTemplateColumns: { xs: '1fr', lg: '1.4fr 1fr' },
|
||||
}}
|
||||
>
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent sx={{ p: 2.5 }}>
|
||||
<PageSectionHeader
|
||||
title={t('profile.personalInfo')}
|
||||
@ -199,7 +199,7 @@ export function ProfilePage() {
|
||||
</Card>
|
||||
|
||||
<Stack spacing={2.5}>
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent sx={{ p: 2.5 }}>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 2 }}>
|
||||
{t('profile.emailVerification')}
|
||||
@ -216,7 +216,7 @@ export function ProfilePage() {
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent sx={{ p: 2.5 }}>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 2 }}>
|
||||
{t('profile.referralProgram')}
|
||||
@ -225,7 +225,7 @@ export function ProfilePage() {
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent sx={{ p: 2.5 }}>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 2 }}>
|
||||
{t('profile.accountDetails')}
|
||||
@ -270,7 +270,7 @@ export function ProfilePage() {
|
||||
gridTemplateColumns: { xs: '1fr', md: 'repeat(2, 1fr)' },
|
||||
}}
|
||||
>
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent sx={{ p: 2.5 }}>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 0.5 }}>
|
||||
{t('profile.changePassword')}
|
||||
@ -282,7 +282,7 @@ export function ProfilePage() {
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent sx={{ p: 2.5 }}>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 0.5 }}>
|
||||
{t('profile.twoFactorAuth')}
|
||||
@ -305,7 +305,7 @@ export function ProfilePage() {
|
||||
)}
|
||||
|
||||
{tab === 1 && (
|
||||
<Card sx={{ borderRadius: 3, mt: 2.5 }}>
|
||||
<Card sx={{ borderRadius: 2, mt: 2.5 }}>
|
||||
<CardContent sx={{ p: 2.5 }}>
|
||||
<SecurityNotificationsPanel />
|
||||
</CardContent>
|
||||
|
||||
290
prediqo_web/src/features/rbac/AdminUserPermissionsPage.tsx
Normal file
290
prediqo_web/src/features/rbac/AdminUserPermissionsPage.tsx
Normal file
@ -0,0 +1,290 @@
|
||||
/**
|
||||
* Per-user permission exceptions: inherited, direct allow, direct deny, effective.
|
||||
*/
|
||||
import {
|
||||
Alert,
|
||||
Box,
|
||||
Button,
|
||||
Chip,
|
||||
IconButton,
|
||||
Paper,
|
||||
Stack,
|
||||
TextField,
|
||||
ToggleButton,
|
||||
ToggleButtonGroup,
|
||||
Tooltip,
|
||||
Typography,
|
||||
} from '@mui/material';
|
||||
import ArrowBackRoundedIcon from '@mui/icons-material/ArrowBackRounded';
|
||||
import AddRoundedIcon from '@mui/icons-material/AddRounded';
|
||||
import BlockRoundedIcon from '@mui/icons-material/BlockRounded';
|
||||
import RestartAltRoundedIcon from '@mui/icons-material/RestartAltRounded';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Link as RouterLink, useParams } from 'react-router-dom';
|
||||
import { api } from '../../shared/services/api';
|
||||
import { PageHeader, RefreshIconButton } from '../../shared/components/PageHeader';
|
||||
import { useAuth } from '../../shared/auth/AuthContext';
|
||||
import type { AdminStaffUser } from './AdminUsersPage';
|
||||
|
||||
type PermissionItem = {
|
||||
key: string;
|
||||
description: string | null;
|
||||
category: string | null;
|
||||
inherited: boolean;
|
||||
directAllow: boolean;
|
||||
directDeny: boolean;
|
||||
effective: boolean;
|
||||
sources: string[];
|
||||
};
|
||||
|
||||
type DetailResponse = {
|
||||
user: AdminStaffUser;
|
||||
permissions: PermissionItem[];
|
||||
categories: Record<string, PermissionItem[]>;
|
||||
};
|
||||
|
||||
type OriginFilter = 'all' | 'inherited' | 'allow' | 'deny' | 'effective' | 'inactive';
|
||||
|
||||
export function AdminUserPermissionsPage() {
|
||||
const { t } = useTranslation();
|
||||
const { userId = '' } = useParams();
|
||||
const { can } = useAuth();
|
||||
const canManage = can('admin.rbac.manage');
|
||||
const qc = useQueryClient();
|
||||
const [search, setSearch] = useState('');
|
||||
const [origin, setOrigin] = useState<OriginFilter>('all');
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const detailQ = useQuery({
|
||||
queryKey: ['rbac-admin-user', userId],
|
||||
enabled: !!userId,
|
||||
queryFn: async () => {
|
||||
const res = await api.get<DetailResponse>(`/api/v1/admin/rbac/admin-users/${userId}/permissions`);
|
||||
return res.data;
|
||||
},
|
||||
});
|
||||
|
||||
const mut = useMutation({
|
||||
mutationFn: async (body: { permissionKey: string; action: 'allow' | 'deny' | 'reset' }) => {
|
||||
const res = await api.patch<DetailResponse>(
|
||||
`/api/v1/admin/rbac/admin-users/${userId}/permissions`,
|
||||
body
|
||||
);
|
||||
return res.data;
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
setError(null);
|
||||
qc.setQueryData(['rbac-admin-user', userId], data);
|
||||
void qc.invalidateQueries({ queryKey: ['rbac-admin-users'] });
|
||||
},
|
||||
onError: (e: unknown) => {
|
||||
setError(
|
||||
(e as { response?: { data?: { error?: string } } })?.response?.data?.error ??
|
||||
t('admin.rbac.userPermissions.saveFailed')
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
const user = detailQ.data?.user;
|
||||
const categories = useMemo(() => {
|
||||
const q = search.trim().toLowerCase();
|
||||
const raw = detailQ.data?.categories;
|
||||
const grouped = raw && !Array.isArray(raw) ? raw : {};
|
||||
return Object.entries(grouped)
|
||||
.map(([cat, items]) => ({
|
||||
cat,
|
||||
items: (Array.isArray(items) ? items : []).filter((p) => {
|
||||
if (q && !p.key.toLowerCase().includes(q) && !(p.description ?? '').toLowerCase().includes(q)) {
|
||||
return false;
|
||||
}
|
||||
if (origin === 'inherited') return p.inherited;
|
||||
if (origin === 'allow') return p.directAllow;
|
||||
if (origin === 'deny') return p.directDeny;
|
||||
if (origin === 'effective') return p.effective;
|
||||
if (origin === 'inactive') return !p.effective;
|
||||
return true;
|
||||
}),
|
||||
}))
|
||||
.filter((g) => g.items.length > 0);
|
||||
}, [detailQ.data?.categories, search, origin]);
|
||||
|
||||
return (
|
||||
<Box sx={{ minWidth: 0 }}>
|
||||
<PageHeader
|
||||
leading={
|
||||
<IconButton component={RouterLink} to="/admin/admin-users" aria-label={t('common.back')}>
|
||||
<ArrowBackRoundedIcon />
|
||||
</IconButton>
|
||||
}
|
||||
title={user?.fullName || user?.email || t('admin.rbac.userPermissions.title')}
|
||||
subtitle={t('admin.rbac.userPermissions.subtitle')}
|
||||
actions={<RefreshIconButton onClick={() => void detailQ.refetch()} disabled={detailQ.isFetching} />}
|
||||
/>
|
||||
|
||||
{detailQ.isError && (
|
||||
<Alert severity="error" sx={{ mb: 2 }}>
|
||||
{t('admin.rbac.userPermissions.loadFailed')}
|
||||
</Alert>
|
||||
)}
|
||||
{error && (
|
||||
<Alert severity="error" sx={{ mb: 2 }} onClose={() => setError(null)}>
|
||||
{error}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{user && (
|
||||
<Paper sx={{ p: 2, mb: 2 }}>
|
||||
<Stack spacing={1.25}>
|
||||
<Typography variant="body2" sx={{ opacity: 0.75 }}>
|
||||
{user.email}
|
||||
</Typography>
|
||||
<Stack direction="row" spacing={0.75} useFlexGap sx={{ flexWrap: 'wrap' }}>
|
||||
{(Array.isArray(user.roles) ? user.roles : []).map((r) => (
|
||||
<Chip key={r} size="small" label={r} color={r === 'admin' || r === 'super_admin' ? 'primary' : 'default'} />
|
||||
))}
|
||||
</Stack>
|
||||
<Stack direction="row" spacing={1} useFlexGap sx={{ flexWrap: 'wrap' }}>
|
||||
<Chip label={t('admin.rbac.adminUsers.inherited', { count: user.inheritedCount })} variant="outlined" />
|
||||
<Chip color="success" label={t('admin.rbac.userPermissions.added', { count: user.allowCount })} />
|
||||
<Chip color="error" label={t('admin.rbac.userPermissions.removed', { count: user.denyCount })} />
|
||||
<Chip color="info" label={t('admin.rbac.adminUsers.effective', { count: user.effectiveCount })} />
|
||||
</Stack>
|
||||
</Stack>
|
||||
</Paper>
|
||||
)}
|
||||
|
||||
<Stack direction={{ xs: 'column', md: 'row' }} spacing={1.5} sx={{ mb: 2 }}>
|
||||
<TextField
|
||||
size="small"
|
||||
fullWidth
|
||||
label={t('admin.rbac.userPermissions.search')}
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
/>
|
||||
<ToggleButtonGroup
|
||||
exclusive
|
||||
size="small"
|
||||
value={origin}
|
||||
onChange={(_, v: OriginFilter | null) => v && setOrigin(v)}
|
||||
sx={{ flexWrap: 'wrap' }}
|
||||
>
|
||||
<ToggleButton value="all">{t('common.all')}</ToggleButton>
|
||||
<ToggleButton value="inherited">{t('admin.rbac.userPermissions.filterInherited')}</ToggleButton>
|
||||
<ToggleButton value="allow">{t('admin.rbac.userPermissions.filterAllow')}</ToggleButton>
|
||||
<ToggleButton value="deny">{t('admin.rbac.userPermissions.filterDeny')}</ToggleButton>
|
||||
<ToggleButton value="effective">{t('admin.rbac.userPermissions.filterEffective')}</ToggleButton>
|
||||
<ToggleButton value="inactive">{t('admin.rbac.userPermissions.filterInactive')}</ToggleButton>
|
||||
</ToggleButtonGroup>
|
||||
</Stack>
|
||||
|
||||
<Stack spacing={1.5}>
|
||||
{categories.map(({ cat, items }) => (
|
||||
<Paper key={cat} sx={{ p: 2 }}>
|
||||
<Typography sx={{ fontWeight: 800, textTransform: 'capitalize', mb: 1.5 }}>
|
||||
{t(`admin.rbac.categories.${cat}`, { defaultValue: cat.replace(/_/g, ' ') })}
|
||||
</Typography>
|
||||
<Stack spacing={1}>
|
||||
{items.map((p) => (
|
||||
<Box
|
||||
key={p.key}
|
||||
sx={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: { xs: '1fr', md: 'minmax(0, 1fr) auto' },
|
||||
gap: 1,
|
||||
alignItems: 'center',
|
||||
py: 0.75,
|
||||
borderBottom: '1px solid rgba(255,255,255,0.06)',
|
||||
}}
|
||||
>
|
||||
<Box sx={{ minWidth: 0 }}>
|
||||
<Typography variant="body2" sx={{ fontFamily: 'monospace', fontSize: 12 }}>
|
||||
{p.key}
|
||||
</Typography>
|
||||
{p.description && (
|
||||
<Typography variant="caption" sx={{ opacity: 0.7 }}>
|
||||
{p.description}
|
||||
</Typography>
|
||||
)}
|
||||
<Stack direction="row" spacing={0.5} useFlexGap sx={{ mt: 0.5, flexWrap: 'wrap' }}>
|
||||
{p.inherited && (
|
||||
<Chip size="small" variant="outlined" label={t('admin.rbac.userPermissions.originRole')} />
|
||||
)}
|
||||
{p.directAllow && (
|
||||
<Chip size="small" color="success" label={t('admin.rbac.userPermissions.originAllow')} />
|
||||
)}
|
||||
{p.directDeny && (
|
||||
<Chip size="small" color="error" label={t('admin.rbac.userPermissions.originDeny')} />
|
||||
)}
|
||||
<Chip
|
||||
size="small"
|
||||
color={p.effective ? 'info' : 'default'}
|
||||
label={
|
||||
p.effective
|
||||
? t('admin.rbac.userPermissions.effectiveOn')
|
||||
: t('admin.rbac.userPermissions.effectiveOff')
|
||||
}
|
||||
/>
|
||||
{p.sources.map((s) => (
|
||||
<Chip key={s} size="small" variant="outlined" label={s} />
|
||||
))}
|
||||
</Stack>
|
||||
</Box>
|
||||
{canManage && (
|
||||
<Stack direction="row" spacing={0.5}>
|
||||
<Tooltip title={t('admin.rbac.userPermissions.allow')}>
|
||||
<span>
|
||||
<Button
|
||||
size="small"
|
||||
color="success"
|
||||
variant={p.directAllow ? 'contained' : 'outlined'}
|
||||
startIcon={<AddRoundedIcon />}
|
||||
disabled={mut.isPending || p.directAllow}
|
||||
onClick={() => mut.mutate({ permissionKey: p.key, action: 'allow' })}
|
||||
>
|
||||
{t('admin.rbac.userPermissions.allow')}
|
||||
</Button>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Tooltip title={t('admin.rbac.userPermissions.deny')}>
|
||||
<span>
|
||||
<Button
|
||||
size="small"
|
||||
color="error"
|
||||
variant={p.directDeny ? 'contained' : 'outlined'}
|
||||
startIcon={<BlockRoundedIcon />}
|
||||
disabled={mut.isPending || p.directDeny}
|
||||
onClick={() => mut.mutate({ permissionKey: p.key, action: 'deny' })}
|
||||
>
|
||||
{t('admin.rbac.userPermissions.deny')}
|
||||
</Button>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Tooltip title={t('admin.rbac.userPermissions.reset')}>
|
||||
<span>
|
||||
<Button
|
||||
size="small"
|
||||
variant="outlined"
|
||||
startIcon={<RestartAltRoundedIcon />}
|
||||
disabled={mut.isPending || (!p.directAllow && !p.directDeny)}
|
||||
onClick={() => mut.mutate({ permissionKey: p.key, action: 'reset' })}
|
||||
>
|
||||
{t('admin.rbac.userPermissions.reset')}
|
||||
</Button>
|
||||
</span>
|
||||
</Tooltip>
|
||||
</Stack>
|
||||
)}
|
||||
</Box>
|
||||
))}
|
||||
</Stack>
|
||||
</Paper>
|
||||
))}
|
||||
{detailQ.isSuccess && categories.length === 0 && (
|
||||
<Alert severity="info">{t('admin.rbac.userPermissions.empty')}</Alert>
|
||||
)}
|
||||
</Stack>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
230
prediqo_web/src/features/rbac/AdminUsersPage.tsx
Normal file
230
prediqo_web/src/features/rbac/AdminUsersPage.tsx
Normal file
@ -0,0 +1,230 @@
|
||||
/**
|
||||
* Dedicated list of administrative users (staff roles and permission exceptions).
|
||||
*/
|
||||
import {
|
||||
Alert,
|
||||
Box,
|
||||
Button,
|
||||
Chip,
|
||||
FormControl,
|
||||
InputLabel,
|
||||
MenuItem,
|
||||
Pagination,
|
||||
Paper,
|
||||
Select,
|
||||
Stack,
|
||||
TextField,
|
||||
Typography,
|
||||
} from '@mui/material';
|
||||
import ManageAccountsRoundedIcon from '@mui/icons-material/ManageAccountsRounded';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Link as RouterLink, useSearchParams } from 'react-router-dom';
|
||||
import { api } from '../../shared/services/api';
|
||||
import { PageHeader, RefreshIconButton } from '../../shared/components/PageHeader';
|
||||
import { PermissionGate } from '../../shared/auth/PermissionGate';
|
||||
|
||||
export type AdminStaffUser = {
|
||||
id: string;
|
||||
email: string | null;
|
||||
fullName: string | null;
|
||||
isEnabled: boolean;
|
||||
roles: string[];
|
||||
inheritedCount: number;
|
||||
allowCount: number;
|
||||
denyCount: number;
|
||||
effectiveCount: number;
|
||||
};
|
||||
|
||||
type ExceptionFilter = 'all' | 'any' | 'allow' | 'deny' | 'none';
|
||||
|
||||
const PAGE_SIZE = 25;
|
||||
|
||||
function asArray<T>(value: T[] | undefined | null): T[] {
|
||||
return Array.isArray(value) ? value : [];
|
||||
}
|
||||
|
||||
export function AdminUsersPage() {
|
||||
const { t } = useTranslation();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const [search, setSearch] = useState(searchParams.get('search') ?? '');
|
||||
const [debounced, setDebounced] = useState(search);
|
||||
const role = searchParams.get('role') ?? '';
|
||||
const exception = (searchParams.get('exception') as ExceptionFilter | null) ?? 'all';
|
||||
const permission = searchParams.get('permission') ?? '';
|
||||
const page = Math.max(1, parseInt(searchParams.get('page') ?? '1', 10) || 1);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = window.setTimeout(() => setDebounced(search.trim()), 350);
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [search]);
|
||||
|
||||
const rolesQ = useQuery({
|
||||
queryKey: ['rbac-roles'],
|
||||
queryFn: async () => {
|
||||
const res = await api.get<{ roles?: Array<{ name: string }> } | Array<{ name: string }>>(
|
||||
'/api/v1/admin/rbac/roles'
|
||||
);
|
||||
const payload = res.data;
|
||||
return Array.isArray(payload) ? payload : asArray(payload?.roles);
|
||||
},
|
||||
staleTime: 60_000,
|
||||
});
|
||||
|
||||
const staffQ = useQuery({
|
||||
queryKey: ['rbac-admin-users', debounced, role, exception, permission, page],
|
||||
queryFn: async () => {
|
||||
const res = await api.get<{ users: AdminStaffUser[]; total: number }>('/api/v1/admin/rbac/admin-users', {
|
||||
params: {
|
||||
search: debounced || undefined,
|
||||
role: role || undefined,
|
||||
exception: exception !== 'all' ? exception : undefined,
|
||||
permission: permission || undefined,
|
||||
limit: PAGE_SIZE,
|
||||
offset: (page - 1) * PAGE_SIZE,
|
||||
},
|
||||
});
|
||||
return res.data;
|
||||
},
|
||||
});
|
||||
|
||||
const roleOptions = useMemo(
|
||||
() => asArray(rolesQ.data).filter((r) => r.name !== 'user').map((r) => r.name),
|
||||
[rolesQ.data]
|
||||
);
|
||||
|
||||
const totalPages = Math.max(1, Math.ceil((staffQ.data?.total ?? 0) / PAGE_SIZE));
|
||||
|
||||
function updateParam(key: string, value: string) {
|
||||
const next = new URLSearchParams(searchParams);
|
||||
if (value) next.set(key, value);
|
||||
else next.delete(key);
|
||||
if (key !== 'page') next.delete('page');
|
||||
setSearchParams(next);
|
||||
}
|
||||
|
||||
return (
|
||||
<Box sx={{ minWidth: 0 }}>
|
||||
<PageHeader
|
||||
title={t('admin.rbac.adminUsers.title')}
|
||||
subtitle={t('admin.rbac.adminUsers.subtitle')}
|
||||
actions={<RefreshIconButton onClick={() => void staffQ.refetch()} disabled={staffQ.isFetching} />}
|
||||
/>
|
||||
|
||||
{staffQ.isError && (
|
||||
<Alert severity="error" sx={{ mb: 2 }}>
|
||||
{t('admin.rbac.adminUsers.loadFailed')}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<Paper sx={{ p: 2, mb: 2 }}>
|
||||
<Stack direction={{ xs: 'column', md: 'row' }} spacing={1.5} useFlexGap sx={{ flexWrap: 'wrap' }}>
|
||||
<TextField
|
||||
size="small"
|
||||
label={t('admin.rbac.adminUsers.search')}
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
onBlur={() => setDebounced(search.trim())}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') setDebounced(search.trim());
|
||||
}}
|
||||
sx={{ minWidth: 240, flex: 1 }}
|
||||
/>
|
||||
<FormControl size="small" sx={{ minWidth: 180 }}>
|
||||
<InputLabel>{t('admin.rbac.adminUsers.roleFilter')}</InputLabel>
|
||||
<Select
|
||||
label={t('admin.rbac.adminUsers.roleFilter')}
|
||||
value={role}
|
||||
onChange={(e) => updateParam('role', e.target.value)}
|
||||
>
|
||||
<MenuItem value="">{t('common.all')}</MenuItem>
|
||||
{roleOptions.map((name) => (
|
||||
<MenuItem key={name} value={name}>
|
||||
{name}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
</FormControl>
|
||||
<FormControl size="small" sx={{ minWidth: 180 }}>
|
||||
<InputLabel>{t('admin.rbac.adminUsers.exceptionFilter')}</InputLabel>
|
||||
<Select
|
||||
label={t('admin.rbac.adminUsers.exceptionFilter')}
|
||||
value={exception}
|
||||
onChange={(e) => updateParam('exception', e.target.value === 'all' ? '' : e.target.value)}
|
||||
>
|
||||
<MenuItem value="all">{t('common.all')}</MenuItem>
|
||||
<MenuItem value="any">{t('admin.rbac.adminUsers.exceptionAny')}</MenuItem>
|
||||
<MenuItem value="allow">{t('admin.rbac.adminUsers.exceptionAllow')}</MenuItem>
|
||||
<MenuItem value="deny">{t('admin.rbac.adminUsers.exceptionDeny')}</MenuItem>
|
||||
<MenuItem value="none">{t('admin.rbac.adminUsers.exceptionNone')}</MenuItem>
|
||||
</Select>
|
||||
</FormControl>
|
||||
<TextField
|
||||
size="small"
|
||||
label={t('admin.rbac.adminUsers.permissionFilter')}
|
||||
value={permission}
|
||||
onChange={(e) => updateParam('permission', e.target.value.trim())}
|
||||
sx={{ minWidth: 220 }}
|
||||
/>
|
||||
</Stack>
|
||||
</Paper>
|
||||
|
||||
<Stack spacing={1.5}>
|
||||
{asArray(staffQ.data?.users).map((user) => (
|
||||
<Paper key={user.id} sx={{ p: 2 }}>
|
||||
<Stack
|
||||
direction={{ xs: 'column', sm: 'row' }}
|
||||
spacing={1.5}
|
||||
sx={{ alignItems: { sm: 'center' }, justifyContent: 'space-between' }}
|
||||
>
|
||||
<Box sx={{ minWidth: 0, flex: 1 }}>
|
||||
<Typography sx={{ fontWeight: 800 }}>{user.fullName || user.email || user.id.slice(0, 8)}</Typography>
|
||||
{user.email && user.fullName && (
|
||||
<Typography variant="body2" sx={{ opacity: 0.7 }}>
|
||||
{user.email}
|
||||
</Typography>
|
||||
)}
|
||||
<Stack direction="row" spacing={0.75} useFlexGap sx={{ mt: 1, flexWrap: 'wrap' }}>
|
||||
{asArray(user.roles).map((r) => (
|
||||
<Chip key={r} size="small" label={r} color={r === 'super_admin' || r === 'admin' ? 'primary' : 'default'} />
|
||||
))}
|
||||
{!user.isEnabled && <Chip size="small" color="warning" label={t('admin.rbac.adminUsers.disabled')} />}
|
||||
</Stack>
|
||||
</Box>
|
||||
<Stack direction="row" spacing={1} useFlexGap sx={{ flexWrap: 'wrap' }}>
|
||||
<Chip size="small" variant="outlined" label={t('admin.rbac.adminUsers.inherited', { count: user.inheritedCount })} />
|
||||
<Chip size="small" color="success" variant="outlined" label={`+${user.allowCount}`} />
|
||||
<Chip size="small" color="error" variant="outlined" label={`-${user.denyCount}`} />
|
||||
<Chip size="small" color="info" label={t('admin.rbac.adminUsers.effective', { count: user.effectiveCount })} />
|
||||
</Stack>
|
||||
<PermissionGate permission="admin.rbac.view">
|
||||
<Button
|
||||
component={RouterLink}
|
||||
to={`/admin/admin-users/${user.id}/permissions`}
|
||||
variant="contained"
|
||||
startIcon={<ManageAccountsRoundedIcon />}
|
||||
sx={{ whiteSpace: 'nowrap' }}
|
||||
>
|
||||
{t('admin.rbac.adminUsers.managePermissions')}
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
</Stack>
|
||||
</Paper>
|
||||
))}
|
||||
{!staffQ.isLoading && asArray(staffQ.data?.users).length === 0 && (
|
||||
<Alert severity="info">{t('admin.rbac.adminUsers.empty')}</Alert>
|
||||
)}
|
||||
</Stack>
|
||||
|
||||
{totalPages > 1 && (
|
||||
<Pagination
|
||||
sx={{ mt: 2 }}
|
||||
count={totalPages}
|
||||
page={page}
|
||||
onChange={(_, p) => updateParam('page', p === 1 ? '' : String(p))}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@ -25,6 +25,7 @@ import LockRoundedIcon from '@mui/icons-material/LockRounded';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Link as RouterLink } from 'react-router-dom';
|
||||
import { api } from '../../shared/services/api';
|
||||
import { PageHeader, RefreshIconButton } from '../../shared/components/PageHeader';
|
||||
import { PermissionGate } from '../../shared/auth/PermissionGate';
|
||||
@ -63,8 +64,9 @@ export function RoleManagementPage() {
|
||||
const rolesQ = useQuery({
|
||||
queryKey: ['rbac-roles'],
|
||||
queryFn: async () => {
|
||||
const res = await api.get<{ roles: RoleDto[] }>('/api/v1/admin/rbac/roles');
|
||||
return res.data.roles;
|
||||
const res = await api.get<{ roles?: RoleDto[] } | RoleDto[]>('/api/v1/admin/rbac/roles');
|
||||
const payload = res.data;
|
||||
return Array.isArray(payload) ? payload : payload?.roles ?? [];
|
||||
},
|
||||
});
|
||||
|
||||
@ -76,19 +78,33 @@ export function RoleManagementPage() {
|
||||
},
|
||||
});
|
||||
|
||||
const categories = useMemo(() => permsQ.data ?? {}, [permsQ.data]);
|
||||
const categories = useMemo(() => {
|
||||
const raw = permsQ.data as unknown;
|
||||
if (!raw || Array.isArray(raw) || typeof raw !== 'object') return {};
|
||||
const maybeWrapped = raw as { categories?: Record<string, PermissionDto[]> };
|
||||
if (maybeWrapped.categories && typeof maybeWrapped.categories === 'object' && !Array.isArray(maybeWrapped.categories)) {
|
||||
return maybeWrapped.categories;
|
||||
}
|
||||
return raw as Record<string, PermissionDto[]>;
|
||||
}, [permsQ.data]);
|
||||
|
||||
const saveMut = useMutation({
|
||||
mutationFn: async () => {
|
||||
const body = {
|
||||
name: name.trim(),
|
||||
const body: {
|
||||
name?: string;
|
||||
description?: string;
|
||||
permissionKeys: string[];
|
||||
} = {
|
||||
description: description.trim() || undefined,
|
||||
permissionKeys: [...selected],
|
||||
};
|
||||
if (!editing?.isSystem) {
|
||||
body.name = name.trim();
|
||||
}
|
||||
if (editing) {
|
||||
await api.patch(`/api/v1/admin/rbac/roles/${editing.id}`, body);
|
||||
} else {
|
||||
await api.post('/api/v1/admin/rbac/roles', body);
|
||||
await api.post('/api/v1/admin/rbac/roles', { ...body, name: name.trim() });
|
||||
}
|
||||
},
|
||||
onSuccess: async () => {
|
||||
@ -160,6 +176,9 @@ export function RoleManagementPage() {
|
||||
actions={
|
||||
<>
|
||||
<RefreshIconButton onClick={() => rolesQ.refetch()} disabled={rolesQ.isFetching} />
|
||||
<Button component={RouterLink} to="/admin/admin-users" variant="outlined">
|
||||
{t('admin.rbac.adminUsers.title')}
|
||||
</Button>
|
||||
<PermissionGate permission="admin.rbac.manage">
|
||||
<Button variant="contained" startIcon={<AddRoundedIcon />} onClick={openCreate}>
|
||||
{t('admin.rbac.createRole')}
|
||||
@ -176,8 +195,8 @@ export function RoleManagementPage() {
|
||||
)}
|
||||
|
||||
<Stack spacing={2}>
|
||||
{(rolesQ.data ?? []).map((role) => (
|
||||
<Paper key={role.id} sx={{ p: 2.5, borderRadius: 3 }}>
|
||||
{(Array.isArray(rolesQ.data) ? rolesQ.data : []).map((role) => (
|
||||
<Paper key={role.id} sx={{ p: 2.5 }}>
|
||||
<Stack direction="row" spacing={2} sx={{ alignItems: 'flex-start' }}>
|
||||
<Box sx={{ flex: 1, minWidth: 0 }}>
|
||||
<Stack
|
||||
@ -200,6 +219,9 @@ export function RoleManagementPage() {
|
||||
)}
|
||||
<Chip
|
||||
size="small"
|
||||
component={RouterLink}
|
||||
to={`/admin/admin-users?role=${encodeURIComponent(role.name)}`}
|
||||
clickable
|
||||
label={t('admin.rbac.userCount', { count: role.userCount })}
|
||||
variant="outlined"
|
||||
/>
|
||||
@ -274,7 +296,8 @@ export function RoleManagementPage() {
|
||||
{t('admin.rbac.permissions')}
|
||||
</Typography>
|
||||
{Object.entries(categories).map(([cat, perms]) => {
|
||||
const keys = perms.map((p) => p.key);
|
||||
const list = Array.isArray(perms) ? perms : [];
|
||||
const keys = list.map((p) => p.key);
|
||||
const allSelected = keys.length > 0 && keys.every((k) => selected.has(k));
|
||||
const someSelected = keys.some((k) => selected.has(k));
|
||||
return (
|
||||
@ -294,7 +317,7 @@ export function RoleManagementPage() {
|
||||
}
|
||||
/>
|
||||
<Box sx={{ pl: 3, display: 'grid', gap: 0.5 }}>
|
||||
{perms.map((p) => (
|
||||
{list.map((p) => (
|
||||
<FormControlLabel
|
||||
key={p.key}
|
||||
control={
|
||||
|
||||
@ -306,7 +306,7 @@ export function ReferralAdminPage() {
|
||||
{configQ.isError && <Alert severity="error">{t('admin.referralAdmin.loadError')}</Alert>}
|
||||
|
||||
{s && (
|
||||
<Card sx={{ borderRadius: 3, mb: 2 }}>
|
||||
<Card sx={{ borderRadius: 2, mb: 2 }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 2 }}>
|
||||
{t('admin.referralAdmin.programSettings')}
|
||||
@ -781,7 +781,7 @@ export function ReferralAdminPage() {
|
||||
)}
|
||||
|
||||
{showModeConfig && (
|
||||
<Card sx={{ borderRadius: 3, mb: 2 }}>
|
||||
<Card sx={{ borderRadius: 2, mb: 2 }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 2 }}>
|
||||
{t('admin.referralAdmin.levelsTitle')}
|
||||
@ -895,7 +895,7 @@ export function ReferralAdminPage() {
|
||||
)}
|
||||
|
||||
{showModeConfig && (
|
||||
<Card sx={{ borderRadius: 3, mb: 2 }}>
|
||||
<Card sx={{ borderRadius: 2, mb: 2 }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 2 }}>
|
||||
{t('admin.referralAdmin.bonusPoolTitle')}
|
||||
@ -956,7 +956,7 @@ export function ReferralAdminPage() {
|
||||
)}
|
||||
|
||||
{showReviewUi && (
|
||||
<Card sx={{ borderRadius: 3, mb: 2 }}>
|
||||
<Card sx={{ borderRadius: 2, mb: 2 }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 2 }}>
|
||||
{t('admin.referralAdmin.reviewTitle')}
|
||||
@ -1050,7 +1050,7 @@ export function ReferralAdminPage() {
|
||||
)}
|
||||
|
||||
{stats && (
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent>
|
||||
<Stack
|
||||
direction={{ xs: 'column', sm: 'row' }}
|
||||
|
||||
@ -90,7 +90,7 @@ type FraudDashboard = {
|
||||
|
||||
function StatCard({ label, value, sub }: { label: string; value: string | number; sub?: string }) {
|
||||
return (
|
||||
<Card sx={{ borderRadius: 3, height: '100%' }}>
|
||||
<Card sx={{ borderRadius: 2, height: '100%' }}>
|
||||
<CardContent>
|
||||
<Typography variant="caption" color="text.secondary">
|
||||
{label}
|
||||
@ -246,7 +246,7 @@ export function ReferralFraudDashboardPage() {
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<Card sx={{ borderRadius: 3, mb: 2 }}>
|
||||
<Card sx={{ borderRadius: 2, mb: 2 }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 2 }}>
|
||||
{t('admin.referralFraud.reviewQueue.title')}
|
||||
@ -316,7 +316,7 @@ export function ReferralFraudDashboardPage() {
|
||||
|
||||
<Grid container spacing={2} sx={{ mb: 2 }}>
|
||||
<Grid size={{ xs: 12, md: 6 }}>
|
||||
<Card sx={{ borderRadius: 3, height: '100%' }}>
|
||||
<Card sx={{ borderRadius: 2, height: '100%' }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 2 }}>
|
||||
{t('admin.referralFraud.highRisk.title')}
|
||||
@ -349,7 +349,7 @@ export function ReferralFraudDashboardPage() {
|
||||
</Card>
|
||||
</Grid>
|
||||
<Grid size={{ xs: 12, md: 6 }}>
|
||||
<Card sx={{ borderRadius: 3, height: '100%' }}>
|
||||
<Card sx={{ borderRadius: 2, height: '100%' }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 2 }}>
|
||||
{t('admin.referralFraud.sybilSignals.title')}
|
||||
@ -373,7 +373,7 @@ export function ReferralFraudDashboardPage() {
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<Card sx={{ borderRadius: 3, mb: 2 }}>
|
||||
<Card sx={{ borderRadius: 2, mb: 2 }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 2 }}>
|
||||
{t('admin.referralFraud.clawback.title')}
|
||||
@ -435,7 +435,7 @@ export function ReferralFraudDashboardPage() {
|
||||
|
||||
<Grid container spacing={2}>
|
||||
<Grid size={{ xs: 12, md: 6 }}>
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 2 }}>
|
||||
{t('admin.referralFraud.recentClawbacks.title')}
|
||||
@ -500,7 +500,7 @@ export function ReferralFraudDashboardPage() {
|
||||
</Card>
|
||||
</Grid>
|
||||
<Grid size={{ xs: 12, md: 6 }}>
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 2 }}>
|
||||
{t('admin.referralFraud.recentBlocks.title')}
|
||||
|
||||
@ -39,7 +39,7 @@ const COMMISSIONS_PAGE_SIZE = 25;
|
||||
|
||||
function StatCard({ label, value, sub }: { label: string; value: string | number; sub?: string }) {
|
||||
return (
|
||||
<Card sx={{ borderRadius: 3, height: '100%' }}>
|
||||
<Card sx={{ borderRadius: 2, height: '100%' }}>
|
||||
<CardContent>
|
||||
<Typography variant="caption" color="text.secondary">
|
||||
{label}
|
||||
@ -119,8 +119,8 @@ export function ReferralPage() {
|
||||
|
||||
{dashQ.isLoading && (
|
||||
<Stack spacing={2}>
|
||||
<Skeleton height={120} sx={{ borderRadius: 3 }} />
|
||||
<Skeleton height={280} sx={{ borderRadius: 3 }} />
|
||||
<Skeleton height={120} sx={{ borderRadius: 2 }} />
|
||||
<Skeleton height={280} sx={{ borderRadius: 2 }} />
|
||||
</Stack>
|
||||
)}
|
||||
|
||||
@ -168,7 +168,7 @@ export function ReferralPage() {
|
||||
|
||||
<Stack direction={{ xs: 'column', md: 'row' }} spacing={2} sx={{ mb: 2 }}>
|
||||
<Box sx={{ flex: 1 }}>
|
||||
<Card sx={{ borderRadius: 3, height: '100%' }}>
|
||||
<Card sx={{ borderRadius: 2, height: '100%' }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 1.5 }}>
|
||||
{t('referralPage.invite.title')}
|
||||
@ -252,7 +252,7 @@ export function ReferralPage() {
|
||||
</Box>
|
||||
|
||||
<Box sx={{ flex: 1 }}>
|
||||
<Card sx={{ borderRadius: 3, height: '100%' }}>
|
||||
<Card sx={{ borderRadius: 2, height: '100%' }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 1.5 }}>
|
||||
{t('referralPage.referrer.title')}
|
||||
@ -305,7 +305,7 @@ export function ReferralPage() {
|
||||
</Box>
|
||||
</Stack>
|
||||
|
||||
<Card sx={{ borderRadius: 3, mb: 2 }}>
|
||||
<Card sx={{ borderRadius: 2, mb: 2 }}>
|
||||
<CardContent>
|
||||
<Stack
|
||||
direction={{ xs: 'column', sm: 'row' }}
|
||||
@ -342,7 +342,7 @@ export function ReferralPage() {
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent sx={{ pb: 1 }}>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 2 }}>
|
||||
{t('referralPage.network.commissionHistory')}
|
||||
|
||||
@ -50,10 +50,16 @@ import { PermissionGate } from '../../shared/auth/PermissionGate';
|
||||
const USDT_WALLET_CODE = 'USDT_TRC20';
|
||||
const USDT_DECIMALS = 6;
|
||||
|
||||
const AUDIT_FILTER_ACTIONS: Record<'predictions' | 'admin_changes', string> = {
|
||||
const ENGINE_AUDIT_ACTIONS = 'prediction_round_settled';
|
||||
const AUDIT_FILTER_ACTIONS: Record<
|
||||
'security' | 'failed' | 'predictions' | 'admin_changes',
|
||||
string
|
||||
> = {
|
||||
security: '',
|
||||
failed: 'login_failed',
|
||||
predictions: 'prediction_settled,prediction_round_settled,prediction_placed',
|
||||
admin_changes:
|
||||
'admin_user_deleted,admin_user_roles_changed,admin_user_permissions_changed,admin_user_flags_updated,admin_user_security_updated,settings_updated,admin_email_verified',
|
||||
'admin_user_deleted,admin_user_roles_changed,admin_user_permissions_changed,admin_user_flags_updated,admin_user_security_updated,settings_updated,admin_email_verified,admin_user_permission_override_added,admin_user_permission_override_removed,admin_user_permission_override_reset,rbac_role_created,rbac_role_updated,rbac_role_deleted',
|
||||
};
|
||||
const TABLE_PAGE_SIZE = 10;
|
||||
|
||||
@ -216,8 +222,8 @@ export function SecurityAdminPage() {
|
||||
const [tamperEventsPage, setTamperEventsPage] = useState(0);
|
||||
const [auditLogPage, setAuditLogPage] = useState(0);
|
||||
const [auditLogFilter, setAuditLogFilter] = useState<
|
||||
'all' | 'failed' | 'predictions' | 'admin_changes'
|
||||
>('all');
|
||||
'security' | 'failed' | 'predictions' | 'admin_changes'
|
||||
>('security');
|
||||
|
||||
const [auditExporting, setAuditExporting] = useState(false);
|
||||
const [auditUserIdFilter, setAuditUserIdFilter] = useState('');
|
||||
@ -229,7 +235,11 @@ export function SecurityAdminPage() {
|
||||
limit: String(TABLE_PAGE_SIZE),
|
||||
offset: String(auditLogPage * TABLE_PAGE_SIZE),
|
||||
};
|
||||
if (auditLogFilter !== 'all' && auditLogFilter !== 'failed') {
|
||||
if (auditLogFilter === 'security') {
|
||||
params.excludeActions = ENGINE_AUDIT_ACTIONS;
|
||||
} else if (auditLogFilter === 'failed') {
|
||||
params.actions = AUDIT_FILTER_ACTIONS.failed;
|
||||
} else {
|
||||
params.actions = AUDIT_FILTER_ACTIONS[auditLogFilter];
|
||||
}
|
||||
const userId = auditUserIdFilter.trim();
|
||||
@ -359,10 +369,7 @@ export function SecurityAdminPage() {
|
||||
auditToDate,
|
||||
],
|
||||
queryFn: async () => {
|
||||
const endpoint =
|
||||
auditLogFilter === 'failed'
|
||||
? '/api/v1/admin/security/failed-logins'
|
||||
: '/api/v1/admin/security/audit-logs';
|
||||
const endpoint = '/api/v1/admin/security/audit-logs';
|
||||
const res = await api.get<{ items: AuditLogEntry[]; total: number }>(endpoint, {
|
||||
params: buildAuditQueryParams(),
|
||||
});
|
||||
@ -509,8 +516,8 @@ export function SecurityAdminPage() {
|
||||
setAuditExporting(true);
|
||||
try {
|
||||
const params: Record<string, string> = {};
|
||||
if (auditLogFilter === 'failed') params.actions = 'login_failed';
|
||||
else if (auditLogFilter !== 'all') params.actions = AUDIT_FILTER_ACTIONS[auditLogFilter];
|
||||
if (auditLogFilter === 'security') params.excludeActions = ENGINE_AUDIT_ACTIONS;
|
||||
else params.actions = AUDIT_FILTER_ACTIONS[auditLogFilter];
|
||||
const userId = auditUserIdFilter.trim();
|
||||
if (userId) params.userId = userId;
|
||||
if (auditFromDate) params.from = new Date(`${auditFromDate}T00:00:00`).toISOString();
|
||||
@ -701,7 +708,7 @@ export function SecurityAdminPage() {
|
||||
</Tabs>
|
||||
|
||||
{tab === 0 && (
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent>
|
||||
<Stack direction="row" spacing={1} sx={{ mb: 2 }}>
|
||||
<Chip
|
||||
@ -782,7 +789,7 @@ export function SecurityAdminPage() {
|
||||
)}
|
||||
|
||||
{tab === 1 && (
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent>
|
||||
<Stack
|
||||
direction={{ xs: 'column', sm: 'row' }}
|
||||
@ -849,7 +856,7 @@ export function SecurityAdminPage() {
|
||||
)}
|
||||
|
||||
{tab === 2 && (
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent>
|
||||
<Stack
|
||||
direction={{ xs: 'column', sm: 'row' }}
|
||||
@ -916,7 +923,7 @@ export function SecurityAdminPage() {
|
||||
)}
|
||||
|
||||
{tab === 3 && (
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 1 }}>
|
||||
{t('admin.security.dbAudit.title')}
|
||||
@ -990,7 +997,7 @@ export function SecurityAdminPage() {
|
||||
)}
|
||||
|
||||
{tab === 4 && (
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 1 }}>
|
||||
{t('admin.security.auditLog.title')}
|
||||
@ -1000,9 +1007,9 @@ export function SecurityAdminPage() {
|
||||
</Typography>
|
||||
<Stack direction="row" spacing={1} sx={{ mb: 2, flexWrap: 'wrap' }}>
|
||||
<Chip
|
||||
label={t('admin.security.auditLog.allEvents')}
|
||||
color={auditLogFilter === 'all' ? 'primary' : 'default'}
|
||||
onClick={() => setAuditLogFilter('all')}
|
||||
label={t('admin.security.auditLog.securityEvents')}
|
||||
color={auditLogFilter === 'security' ? 'primary' : 'default'}
|
||||
onClick={() => setAuditLogFilter('security')}
|
||||
/>
|
||||
<Chip
|
||||
label={t('admin.security.auditLog.failedLogins')}
|
||||
@ -1123,7 +1130,7 @@ export function SecurityAdminPage() {
|
||||
)}
|
||||
|
||||
{tab === 5 && (
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent>
|
||||
<Stack
|
||||
direction={{ xs: 'column', sm: 'row' }}
|
||||
@ -1238,7 +1245,7 @@ export function SecurityAdminPage() {
|
||||
)}
|
||||
|
||||
{tab === 6 && (
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 1 }}>
|
||||
{t('admin.security.alertEmails.title')}
|
||||
|
||||
@ -55,6 +55,7 @@ export function SettingsPage() {
|
||||
candle_predict_backfill_max_per_tick: number;
|
||||
candle_predict_backfill_interval_ms: number;
|
||||
candle_predict_backfill_seed_max: number;
|
||||
engine_audit_log_retention_days: number;
|
||||
withdrawal_network_fee_usdt_micro: number;
|
||||
};
|
||||
|
||||
@ -113,7 +114,7 @@ export function SettingsPage() {
|
||||
<Typography sx={{ opacity: 0.7 }}>{t('admin.settings.subtitle')}</Typography>
|
||||
</Stack>
|
||||
|
||||
<Card sx={{ mt: 2.5, borderRadius: 3 }}>
|
||||
<Card sx={{ mt: 2.5, borderRadius: 2 }}>
|
||||
<CardContent sx={{ p: 2.5 }}>
|
||||
{q.isLoading ? (
|
||||
<Alert severity="info" sx={{ borderRadius: 2 }}>
|
||||
@ -531,6 +532,19 @@ export function SettingsPage() {
|
||||
fullWidth
|
||||
/>
|
||||
</Box>
|
||||
<Box sx={{ gridColumn: { xs: '1 / -1', md: 'span 6' } }}>
|
||||
<TextField
|
||||
label={t('admin.settings.sections.candlePredict.engineAuditRetention')}
|
||||
helperText={t('admin.settings.sections.candlePredict.engineAuditRetentionHelper')}
|
||||
type="number"
|
||||
value={effective.engine_audit_log_retention_days}
|
||||
onChange={(e) =>
|
||||
set('engine_audit_log_retention_days', parseNum(e.target.value))
|
||||
}
|
||||
fullWidth
|
||||
slotProps={{ htmlInput: { min: 0, max: 365 } }}
|
||||
/>
|
||||
</Box>
|
||||
</Box>
|
||||
</AccordionDetails>
|
||||
</Accordion>
|
||||
|
||||
@ -103,7 +103,7 @@ export function ShareCardsAdminPage() {
|
||||
{saveMut.isError && <Alert severity="error" sx={{ mb: 2 }}>{t('admin.shareCards.saveFailed')}</Alert>}
|
||||
{saveMut.isSuccess && <Alert severity="success" sx={{ mb: 2 }}>{t('admin.shareCards.saved')}</Alert>}
|
||||
|
||||
<Card sx={{ borderRadius: 3, mb: 2 }}>
|
||||
<Card sx={{ borderRadius: 2, mb: 2 }}>
|
||||
<CardContent component="fieldset" disabled={!canEditShareCards} sx={{ border: 0, m: 0, p: 0, minWidth: 0 }}>
|
||||
<FormControlLabel
|
||||
control={
|
||||
|
||||
@ -161,7 +161,7 @@ function CardShell({
|
||||
sx={{
|
||||
width: 420,
|
||||
maxWidth: '100%',
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
overflow: 'hidden',
|
||||
background: 'linear-gradient(155deg, #0B1220 0%, #142033 45%, #0E1A2B 100%)',
|
||||
border: '1px solid rgba(255,255,255,0.12)',
|
||||
|
||||
@ -55,7 +55,7 @@ export function ShareResultVerifyPage() {
|
||||
background: 'linear-gradient(160deg, #0B1220 0%, #16253A 100%)',
|
||||
}}
|
||||
>
|
||||
<Paper sx={{ width: '100%', maxWidth: 480, borderRadius: 3, p: 3 }}>
|
||||
<Paper sx={{ width: '100%', maxWidth: 480, borderRadius: 2, p: 3 }}>
|
||||
<Stack spacing={2} sx={{ alignItems: 'flex-start' }}>
|
||||
<PrediqoLogo variant="wordmark" size={40} />
|
||||
<Typography variant="h5" sx={{ fontWeight: 900 }}>
|
||||
|
||||
@ -260,7 +260,7 @@ export function SoloEncouragementAdminPage() {
|
||||
<Typography sx={{ opacity: 0.7 }}>{t('admin.soloEncouragement.subtitle')}</Typography>
|
||||
</Stack>
|
||||
|
||||
<Card sx={{ borderRadius: 3, mb: 3 }}>
|
||||
<Card sx={{ borderRadius: 2, mb: 3 }}>
|
||||
<CardContent>
|
||||
<Stack spacing={2}>
|
||||
<FormControlLabel
|
||||
@ -336,7 +336,7 @@ export function SoloEncouragementAdminPage() {
|
||||
<Typography variant="h6" sx={{ fontWeight: 900, mb: 1.5 }}>
|
||||
{t('admin.soloEncouragement.activeStreaks')}
|
||||
</Typography>
|
||||
<Card sx={{ borderRadius: 3, mb: 3 }}>
|
||||
<Card sx={{ borderRadius: 2, mb: 3 }}>
|
||||
<CardContent sx={{ p: 0, '&:last-child': { pb: 0 } }}>
|
||||
<ScrollableTable>
|
||||
<Table size="small">
|
||||
@ -434,7 +434,7 @@ export function SoloEncouragementAdminPage() {
|
||||
{exportError}
|
||||
</Alert>
|
||||
)}
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent sx={{ p: 0, '&:last-child': { pb: 0 } }}>
|
||||
<ScrollableTable>
|
||||
<Table size="small">
|
||||
|
||||
@ -264,7 +264,7 @@ export function SupportAdminPage() {
|
||||
}}
|
||||
>
|
||||
{/* Conversation list */}
|
||||
<Paper sx={{ p: 2, borderRadius: 3, display: 'flex', flexDirection: 'column', minHeight: 400 }}>
|
||||
<Paper sx={{ p: 2, borderRadius: 2, display: 'flex', flexDirection: 'column', minHeight: 400 }}>
|
||||
<TextField
|
||||
size="small"
|
||||
placeholder={t('admin.supportAdmin.searchPlaceholder')}
|
||||
@ -351,7 +351,7 @@ export function SupportAdminPage() {
|
||||
</Paper>
|
||||
|
||||
{/* Chat */}
|
||||
<Paper sx={{ borderRadius: 3, display: 'flex', flexDirection: 'column', minHeight: 400 }}>
|
||||
<Paper sx={{ borderRadius: 2, display: 'flex', flexDirection: 'column', minHeight: 400 }}>
|
||||
{!selectedId ? (
|
||||
<Typography sx={{ p: 3, opacity: 0.6 }}>{t('admin.supportAdmin.selectConversation')}</Typography>
|
||||
) : (
|
||||
@ -458,7 +458,7 @@ export function SupportAdminPage() {
|
||||
</Paper>
|
||||
|
||||
{/* User context */}
|
||||
<Paper sx={{ p: 2, borderRadius: 3, display: { xs: 'none', lg: 'block' } }}>
|
||||
<Paper sx={{ p: 2, borderRadius: 2, display: { xs: 'none', lg: 'block' } }}>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 1 }}>
|
||||
{t('admin.supportAdmin.contextTitle')}
|
||||
</Typography>
|
||||
|
||||
@ -75,7 +75,7 @@ export function SupportWidget() {
|
||||
display: open ? 'flex' : 'none',
|
||||
flexDirection: 'column',
|
||||
overflow: 'hidden',
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
border: '1px solid',
|
||||
borderColor: 'divider',
|
||||
}}
|
||||
|
||||
@ -134,7 +134,7 @@ export function TestWalletAdminPage() {
|
||||
<Typography sx={{ opacity: 0.7 }}>{t('admin.testWallet.subtitle')}</Typography>
|
||||
</Stack>
|
||||
|
||||
<Card sx={{ borderRadius: 3, mb: 3 }}>
|
||||
<Card sx={{ borderRadius: 2, mb: 3 }}>
|
||||
<CardContent>
|
||||
<Stack spacing={2} component="fieldset" disabled={!canManageTestWallet} sx={{ border: 0, m: 0, p: 0, minWidth: 0 }}>
|
||||
<FormControlLabel
|
||||
@ -248,7 +248,7 @@ export function TestWalletAdminPage() {
|
||||
<Typography variant="h6" sx={{ fontWeight: 900, mb: 1.5 }}>
|
||||
{t('admin.testWallet.history')}
|
||||
</Typography>
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent sx={{ p: 0, '&:last-child': { pb: 0 } }}>
|
||||
<ScrollableTable>
|
||||
<Table size="small">
|
||||
|
||||
@ -204,7 +204,7 @@ export function TreasuryAdminPage() {
|
||||
label: asset.coldWallet?.label ?? '',
|
||||
};
|
||||
return (
|
||||
<Card key={wt.id} sx={{ borderRadius: 3 }}>
|
||||
<Card key={wt.id} sx={{ borderRadius: 2 }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 900, mb: 1 }}>
|
||||
{wt.name} ({wt.network})
|
||||
@ -270,7 +270,7 @@ export function TreasuryAdminPage() {
|
||||
</Stack>
|
||||
)}
|
||||
|
||||
<Card sx={{ borderRadius: 3, mb: 3 }}>
|
||||
<Card sx={{ borderRadius: 2, mb: 3 }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 900, mb: 1 }}>
|
||||
{t('admin.treasury.fundingTitle')}
|
||||
@ -352,7 +352,7 @@ export function TreasuryAdminPage() {
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<Card sx={{ borderRadius: 2 }}>
|
||||
<CardContent>
|
||||
<Stack
|
||||
direction={{ xs: 'column', sm: 'row' }}
|
||||
|
||||
@ -62,6 +62,7 @@ import { humanToRaw, rawToHuman } from '../wallet/utils/walletFormat';
|
||||
import { CountryAutocomplete } from '../../shared/components/CountryAutocomplete';
|
||||
import { useAuth } from '../../shared/auth/AuthContext';
|
||||
import { PermissionGate } from '../../shared/auth/PermissionGate';
|
||||
import { fetchAdminCountries, adminCountryItems } from '../countries/useCountryNames';
|
||||
import {
|
||||
type AdminUser,
|
||||
type AdminUserFilters,
|
||||
@ -395,26 +396,23 @@ export function UserManagementPage() {
|
||||
|
||||
const countriesQ = useQuery({
|
||||
queryKey: ['admin-countries'],
|
||||
queryFn: async () => {
|
||||
const res = await api.get<{ items: Array<{ code: string; name: string }> }>(
|
||||
'/api/v1/admin/countries'
|
||||
);
|
||||
return res.data.items ?? [];
|
||||
},
|
||||
queryFn: fetchAdminCountries,
|
||||
});
|
||||
|
||||
const countryItems = adminCountryItems(countriesQ.data);
|
||||
|
||||
const countryOptions = useMemo(
|
||||
() => (countriesQ.data ?? []).map((c) => ({ code: c.code, name: c.name })),
|
||||
[countriesQ.data]
|
||||
() => countryItems.map((c) => ({ code: c.code, name: c.name })),
|
||||
[countryItems]
|
||||
);
|
||||
|
||||
const countryNameByCode = useMemo(() => {
|
||||
const map = new Map<string, string>();
|
||||
for (const c of countriesQ.data ?? []) {
|
||||
for (const c of countryItems) {
|
||||
map.set(c.code, c.name);
|
||||
}
|
||||
return map;
|
||||
}, [countriesQ.data]);
|
||||
}, [countryItems]);
|
||||
|
||||
const countryLabel = useCallback(
|
||||
(code: string | null | undefined) => {
|
||||
@ -1221,7 +1219,7 @@ export function UserManagementPage() {
|
||||
<Paper
|
||||
sx={{
|
||||
p: 1.5,
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
border: '1px solid rgba(255,255,255,0.12)',
|
||||
backgroundImage: 'none',
|
||||
}}
|
||||
@ -1267,7 +1265,7 @@ export function UserManagementPage() {
|
||||
)}
|
||||
|
||||
<Grid size={{ xs: 12 }}>
|
||||
<Paper sx={{ p: 2, borderRadius: 3, border: '1px solid rgba(255,255,255,0.08)', backgroundImage: 'none' }}>
|
||||
<Paper sx={{ p: 2, borderRadius: 2, border: '1px solid rgba(255,255,255,0.08)', backgroundImage: 'none' }}>
|
||||
<Stack direction="row" spacing={1} sx={{ alignItems: 'center', mb: filtersOpen ? 1.5 : 0 }}>
|
||||
<TextField
|
||||
fullWidth
|
||||
@ -1594,7 +1592,7 @@ export function UserManagementPage() {
|
||||
))}
|
||||
</Stack>
|
||||
) : (
|
||||
<Paper sx={{ borderRadius: 3, border: '1px solid rgba(255,255,255,0.08)', overflow: 'visible', backgroundImage: 'none', width: '100%', minWidth: 0 }}>
|
||||
<Paper sx={{ borderRadius: 2, border: '1px solid rgba(255,255,255,0.08)', overflow: 'visible', backgroundImage: 'none', width: '100%', minWidth: 0 }}>
|
||||
<Box ref={gridScrollRef} sx={{ width: '100%', maxWidth: '100%', overflowX: 'auto', overflowY: 'hidden', scrollbarGutter: 'stable' }}>
|
||||
<DataGrid
|
||||
apiRef={apiRef}
|
||||
|
||||
@ -107,7 +107,7 @@ export function WalletPage() {
|
||||
sx={{
|
||||
p: { xs: 2.5, md: 3 },
|
||||
mb: 2.5,
|
||||
borderRadius: 4,
|
||||
borderRadius: 2,
|
||||
border: '1px solid rgba(214,178,94,0.25)',
|
||||
background:
|
||||
'linear-gradient(135deg, rgba(214,178,94,0.18) 0%, rgba(124,92,255,0.12) 55%, rgba(18,23,36,0.9) 100%)',
|
||||
@ -184,9 +184,9 @@ export function WalletPage() {
|
||||
>
|
||||
{loading ? (
|
||||
<>
|
||||
<Skeleton variant="rounded" height={220} sx={{ borderRadius: 3 }} />
|
||||
<Skeleton variant="rounded" height={220} sx={{ borderRadius: 3 }} />
|
||||
<Skeleton variant="rounded" height={220} sx={{ borderRadius: 3 }} />
|
||||
<Skeleton variant="rounded" height={220} sx={{ borderRadius: 2 }} />
|
||||
<Skeleton variant="rounded" height={220} sx={{ borderRadius: 2 }} />
|
||||
<Skeleton variant="rounded" height={220} sx={{ borderRadius: 2 }} />
|
||||
</>
|
||||
) : usdtBalance ? (
|
||||
<>
|
||||
|
||||
@ -72,7 +72,7 @@ export function BonusWalletCard({ balance, onSuccess, onError }: BonusWalletCard
|
||||
return (
|
||||
<Card
|
||||
sx={{
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
height: '100%',
|
||||
border: '1px solid rgba(124,92,255,0.35)',
|
||||
background:
|
||||
|
||||
@ -30,7 +30,7 @@ export function MainAssetCard({ balance, onReceive, onSend }: MainAssetCardProps
|
||||
const hasLocked = BigInt(balance.locked || '0') > 0n;
|
||||
|
||||
return (
|
||||
<Card sx={{ borderRadius: 3, height: '100%' }}>
|
||||
<Card sx={{ borderRadius: 2, height: '100%' }}>
|
||||
<CardContent sx={{ p: 2.5 }}>
|
||||
<Stack direction="row" spacing={1.5} sx={{ alignItems: 'center' }}>
|
||||
<Box
|
||||
|
||||
@ -73,7 +73,7 @@ export function ReceiveDialog({ open, onClose, onCopied }: ReceiveDialogProps) {
|
||||
<Box
|
||||
sx={{
|
||||
p: 2,
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
bgcolor: '#fff',
|
||||
border: '1px solid rgba(255,255,255,0.12)',
|
||||
}}
|
||||
|
||||
@ -108,7 +108,7 @@ export function TestWalletCard({ balance, onSuccess, onError }: TestWalletCardPr
|
||||
return (
|
||||
<Card
|
||||
sx={{
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
height: '100%',
|
||||
border: '1px solid rgba(76,175,80,0.35)',
|
||||
background:
|
||||
|
||||
@ -122,7 +122,7 @@ export function TransactionList({
|
||||
sx={{
|
||||
p: 4,
|
||||
textAlign: 'center',
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
border: '1px solid rgba(255,255,255,0.08)',
|
||||
}}
|
||||
>
|
||||
@ -138,7 +138,7 @@ export function TransactionList({
|
||||
<Stack spacing={2}>
|
||||
<Paper
|
||||
sx={{
|
||||
borderRadius: 3,
|
||||
borderRadius: 2,
|
||||
border: '1px solid rgba(255,255,255,0.08)',
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
|
||||
@ -5,6 +5,15 @@ import { Navigate, Outlet, useLocation } from 'react-router-dom';
|
||||
import { useAuth } from './AuthContext';
|
||||
import { ADMIN_PAGE_PERMISSIONS } from './permissions';
|
||||
|
||||
function requiredPermissionForPath(pathname: string, explicit?: string): string | undefined {
|
||||
if (explicit) return explicit;
|
||||
if (ADMIN_PAGE_PERMISSIONS[pathname]) return ADMIN_PAGE_PERMISSIONS[pathname];
|
||||
const match = Object.keys(ADMIN_PAGE_PERMISSIONS)
|
||||
.sort((a, b) => b.length - a.length)
|
||||
.find((p) => pathname.startsWith(`${p}/`));
|
||||
return match ? ADMIN_PAGE_PERMISSIONS[match] : undefined;
|
||||
}
|
||||
|
||||
export function RequireAuth({
|
||||
adminOnly = false,
|
||||
staffOnly = false,
|
||||
@ -25,7 +34,7 @@ export function RequireAuth({
|
||||
return <Navigate to="/home" replace />;
|
||||
}
|
||||
|
||||
const requiredPerm = permission ?? ADMIN_PAGE_PERMISSIONS[location.pathname];
|
||||
const requiredPerm = requiredPermissionForPath(location.pathname, permission);
|
||||
|
||||
if (adminOnly || requiredPerm) {
|
||||
if (!hasAdminPanel && !isAdmin) {
|
||||
|
||||
@ -67,6 +67,7 @@ export const ADMIN_PAGE_PERMISSIONS: Record<string, string> = {
|
||||
'/admin/countries': 'admin.countries.view',
|
||||
'/admin/network': 'admin.network.view',
|
||||
'/admin/rbac': 'admin.rbac.view',
|
||||
'/admin/admin-users': 'admin.rbac.view',
|
||||
'/admin/support': 'admin.support.view',
|
||||
'/admin/faq': 'admin.faq.view',
|
||||
};
|
||||
@ -87,4 +88,5 @@ export const OPTIONS_CARD_PERMISSIONS: Record<string, string> = {
|
||||
support: 'admin.support.view',
|
||||
countries: 'admin.countries.view',
|
||||
rbac: 'admin.rbac.view',
|
||||
adminUsers: 'admin.rbac.view',
|
||||
};
|
||||
|
||||
@ -992,6 +992,10 @@ export const en = {
|
||||
title: 'Roles & permissions',
|
||||
description: 'Create custom admin roles, assign granular permissions, and manage access profiles.',
|
||||
},
|
||||
adminUsers: {
|
||||
title: 'Admin users',
|
||||
description: 'Manage staff accounts and individual permission exceptions on top of roles.',
|
||||
},
|
||||
},
|
||||
},
|
||||
rbac: {
|
||||
@ -1031,6 +1035,47 @@ export const en = {
|
||||
share_cards: 'Share cards',
|
||||
solo_encouragement: 'Solo encouragement',
|
||||
},
|
||||
adminUsers: {
|
||||
title: 'Admin users',
|
||||
subtitle: 'Staff accounts, custom admin roles, and individual permission exceptions.',
|
||||
search: 'Search by name or email',
|
||||
roleFilter: 'Role',
|
||||
exceptionFilter: 'Exceptions',
|
||||
exceptionAny: 'Any exception',
|
||||
exceptionAllow: 'Direct allow',
|
||||
exceptionDeny: 'Direct deny',
|
||||
exceptionNone: 'No exceptions',
|
||||
permissionFilter: 'Effective permission key',
|
||||
inherited: '{{count}} inherited',
|
||||
effective: '{{count}} effective',
|
||||
managePermissions: 'Manage permissions',
|
||||
empty: 'No administrative users match these filters.',
|
||||
loadFailed: 'Failed to load admin users.',
|
||||
disabled: 'Disabled',
|
||||
},
|
||||
userPermissions: {
|
||||
title: 'User permissions',
|
||||
subtitle: 'Inherited from roles, plus individual allow and deny exceptions.',
|
||||
loadFailed: 'Failed to load user permissions.',
|
||||
saveFailed: 'Failed to update permission exception.',
|
||||
search: 'Search permissions',
|
||||
added: '+{{count}} added',
|
||||
removed: '−{{count}} removed',
|
||||
filterInherited: 'Inherited',
|
||||
filterAllow: 'Added',
|
||||
filterDeny: 'Removed',
|
||||
filterEffective: 'Effective',
|
||||
filterInactive: 'Not effective',
|
||||
originRole: 'Role',
|
||||
originAllow: 'Direct allow',
|
||||
originDeny: 'Direct deny',
|
||||
effectiveOn: 'Effective',
|
||||
effectiveOff: 'Not effective',
|
||||
allow: 'Allow',
|
||||
deny: 'Deny',
|
||||
reset: 'Reset',
|
||||
empty: 'No permissions match these filters.',
|
||||
},
|
||||
},
|
||||
approvals: {
|
||||
title: 'Approvals',
|
||||
@ -1565,8 +1610,8 @@ export const en = {
|
||||
},
|
||||
auditLog: {
|
||||
title: 'Security audit log',
|
||||
subtitle: 'Application-level security events (logins, password changes, 2FA, access denials). Auto-refreshes every 30s.',
|
||||
allEvents: 'All events',
|
||||
subtitle: 'Security and admin events by default. Engine round settlements are excluded unless you open Predictions.',
|
||||
securityEvents: 'Security events',
|
||||
failedLogins: 'Failed logins',
|
||||
predictions: 'Predictions',
|
||||
adminChanges: 'Admin changes',
|
||||
@ -1702,6 +1747,9 @@ export const en = {
|
||||
backfillMaxHelper: 'Candles filled per interval per run',
|
||||
backfillSeed: 'Backfill seed max',
|
||||
backfillSeedHelper: 'Historical candles on first run',
|
||||
engineAuditRetention: 'Engine audit retention (days)',
|
||||
engineAuditRetentionHelper:
|
||||
'Automatically delete prediction_round_settled logs older than this. 0 = never purge.',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@ -1008,6 +1008,10 @@ export const fr = {
|
||||
title: 'Rôles & permissions',
|
||||
description: 'Créer des rôles admin personnalisés, attribuer des permissions granulaires et gérer les profils d’accès.',
|
||||
},
|
||||
adminUsers: {
|
||||
title: 'Utilisateurs admin',
|
||||
description: 'Gérer les comptes staff et les exceptions de permissions individuelles en plus des rôles.',
|
||||
},
|
||||
},
|
||||
},
|
||||
rbac: {
|
||||
@ -1047,6 +1051,47 @@ export const fr = {
|
||||
share_cards: 'Cartes de partage',
|
||||
solo_encouragement: 'Encouragement solo',
|
||||
},
|
||||
adminUsers: {
|
||||
title: 'Utilisateurs admin',
|
||||
subtitle: 'Comptes staff, rôles admin personnalisés et exceptions de permissions individuelles.',
|
||||
search: 'Rechercher par nom ou e-mail',
|
||||
roleFilter: 'Rôle',
|
||||
exceptionFilter: 'Exceptions',
|
||||
exceptionAny: 'Toute exception',
|
||||
exceptionAllow: 'Ajout direct',
|
||||
exceptionDeny: 'Retrait direct',
|
||||
exceptionNone: 'Aucune exception',
|
||||
permissionFilter: 'Clé de permission effective',
|
||||
inherited: '{{count}} héritée(s)',
|
||||
effective: '{{count}} effective(s)',
|
||||
managePermissions: 'Gérer les permissions',
|
||||
empty: 'Aucun utilisateur administratif ne correspond à ces filtres.',
|
||||
loadFailed: 'Impossible de charger les utilisateurs admin.',
|
||||
disabled: 'Désactivé',
|
||||
},
|
||||
userPermissions: {
|
||||
title: 'Permissions utilisateur',
|
||||
subtitle: 'Héritées des rôles, plus les exceptions individuelles d’ajout et de retrait.',
|
||||
loadFailed: 'Impossible de charger les permissions utilisateur.',
|
||||
saveFailed: 'Impossible de mettre à jour l’exception de permission.',
|
||||
search: 'Rechercher une permission',
|
||||
added: '+{{count}} ajoutée(s)',
|
||||
removed: '−{{count}} retirée(s)',
|
||||
filterInherited: 'Héritées',
|
||||
filterAllow: 'Ajoutées',
|
||||
filterDeny: 'Retirées',
|
||||
filterEffective: 'Effectives',
|
||||
filterInactive: 'Non effectives',
|
||||
originRole: 'Rôle',
|
||||
originAllow: 'Ajout direct',
|
||||
originDeny: 'Retrait direct',
|
||||
effectiveOn: 'Effective',
|
||||
effectiveOff: 'Non effective',
|
||||
allow: 'Autoriser',
|
||||
deny: 'Retirer',
|
||||
reset: 'Réinitialiser',
|
||||
empty: 'Aucune permission ne correspond à ces filtres.',
|
||||
},
|
||||
},
|
||||
approvals: {
|
||||
title: 'Approbations',
|
||||
@ -1582,8 +1627,8 @@ export const fr = {
|
||||
auditLog: {
|
||||
title: 'Journal d’audit sécurité',
|
||||
subtitle:
|
||||
'Événements de sécurité applicatifs (connexions, mots de passe, 2FA, refus d’accès). Actualisation automatique toutes les 30 s.',
|
||||
allEvents: 'Tous les événements',
|
||||
'Événements de sécurité et d’administration par défaut. Les clôtures de rounds moteur sont exclues, sauf dans Prédictions.',
|
||||
securityEvents: 'Événements de sécurité',
|
||||
failedLogins: 'Échecs de connexion',
|
||||
predictions: 'Prédictions',
|
||||
adminChanges: 'Modifications admin',
|
||||
@ -1719,6 +1764,9 @@ export const fr = {
|
||||
backfillMaxHelper: 'Bougies remplies par intervalle et par exécution',
|
||||
backfillSeed: 'Backfill seed max',
|
||||
backfillSeedHelper: 'Bougies historiques au premier lancement',
|
||||
engineAuditRetention: 'Rétention des logs moteur (jours)',
|
||||
engineAuditRetentionHelper:
|
||||
'Supprime automatiquement les logs prediction_round_settled plus anciens. 0 = ne jamais purger.',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user