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,18 +1,24 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { delay } from 'rxjs/operators';
|
||||
import { AdminTransaction, AdminTransactionListFilters, AdminTransactionsListResult } from '../models/admin-transaction.model';
|
||||
import { AdminTransactionsGateway } from './admin-transactions-gateway.interface';
|
||||
import { AdminOrdersLocalGateway } from '../../orders/services/admin-orders-local.gateway';
|
||||
import { AdminAuthService } from '../../../../core/admin-auth/admin-auth.service';
|
||||
|
||||
const METHODS = ['card', 'qr', 'cash_on_delivery'];
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AdminTransactionsLocalGateway implements AdminTransactionsGateway {
|
||||
private readonly adminAuth = inject(AdminAuthService);
|
||||
private cache: AdminTransaction[] | null = null;
|
||||
|
||||
constructor(private readonly ordersGateway: AdminOrdersLocalGateway) {}
|
||||
|
||||
private get currentActor(): string {
|
||||
return this.adminAuth.displayName() ?? 'admin';
|
||||
}
|
||||
|
||||
loadTransactions(filters: AdminTransactionListFilters): Observable<AdminTransactionsListResult> {
|
||||
return new Observable<AdminTransactionsListResult>(subscriber => {
|
||||
this.ensureData().then(() => {
|
||||
@@ -38,7 +44,7 @@ export class AdminTransactionsLocalGateway implements AdminTransactionsGateway {
|
||||
...tx,
|
||||
status: 'retried',
|
||||
updatedAt: new Date().toISOString(),
|
||||
audit: [...tx.audit, { action: 'Retried failed transaction', actor: 'admin', timestamp: new Date().toISOString() }],
|
||||
audit: [...tx.audit, { action: 'Retried failed transaction', actor: this.currentActor, timestamp: new Date().toISOString() }],
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -47,7 +53,7 @@ export class AdminTransactionsLocalGateway implements AdminTransactionsGateway {
|
||||
...tx,
|
||||
fraudFlag: flagged,
|
||||
updatedAt: new Date().toISOString(),
|
||||
audit: [...tx.audit, { action: flagged ? 'Flagged as fraud' : 'Fraud flag cleared', actor: 'admin', timestamp: new Date().toISOString() }],
|
||||
audit: [...tx.audit, { action: flagged ? 'Flagged as fraud' : 'Fraud flag cleared', actor: this.currentActor, timestamp: new Date().toISOString() }],
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user