fix: record real admin identity in Users/Transactions audit trail
audit entries hardcoded actor: 'admin' regardless of who performed the
action. Both local gateways now pull the signed-in admin's displayName
from AdminAuthService, falling back to 'admin' only when unavailable.
Moderation's actor field is a role classifier ('admin' | 'customer'),
not an identity string, and is left unchanged.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { delay } from 'rxjs/operators';
|
||||
import { AdminInvitation, AdminRole, AdminSession, AdminUser, AdminUserAuditEntry, AdminUserScope, AdminUserStatus } from '../models/admin-user.model';
|
||||
import { AdminUsersGateway } from './admin-users-gateway.interface';
|
||||
import { AdminAuthService } from '../../../../core/admin-auth/admin-auth.service';
|
||||
|
||||
const BUILT_IN_ROLES: AdminRole[] = [
|
||||
{ id: 'owner', name: 'Owner', permissions: ['*'], builtIn: true },
|
||||
@@ -13,6 +14,7 @@ const BUILT_IN_ROLES: AdminRole[] = [
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AdminUsersLocalGateway implements AdminUsersGateway {
|
||||
private readonly adminAuth = inject(AdminAuthService);
|
||||
private users: AdminUser[] | null = null;
|
||||
private roles: AdminRole[] = [...BUILT_IN_ROLES];
|
||||
private invitations: AdminInvitation[] = [];
|
||||
@@ -90,12 +92,16 @@ export class AdminUsersLocalGateway implements AdminUsersGateway {
|
||||
this.audit[userId] = [
|
||||
...(this.audit[userId] ?? []),
|
||||
roleId
|
||||
? { eventKey: 'roleChanged', roleId, actor: 'admin', timestamp: new Date().toISOString() }
|
||||
: { eventKey: 'statusChanged', status, actor: 'admin', timestamp: new Date().toISOString() },
|
||||
? { eventKey: 'roleChanged', roleId, actor: this.currentActor, timestamp: new Date().toISOString() }
|
||||
: { eventKey: 'statusChanged', status, actor: this.currentActor, timestamp: new Date().toISOString() },
|
||||
];
|
||||
return of(updated).pipe(delay(50));
|
||||
}
|
||||
|
||||
private get currentActor(): string {
|
||||
return this.adminAuth.displayName() ?? 'admin';
|
||||
}
|
||||
|
||||
private ensureUsers(): AdminUser[] {
|
||||
if (!this.users) {
|
||||
this.users = [
|
||||
|
||||
Reference in New Issue
Block a user