feat: implement system-wide activity logging with database persistence, repository patterns, and admin controller access.

This commit is contained in:
pbao9
2026-05-16 20:01:52 +07:00
parent 8a115c5175
commit 551c90d60b
44 changed files with 845 additions and 33 deletions
@@ -10,6 +10,7 @@ use App\Jobs\VirtualMachine\Snapshot\RevertSnapshot;
use App\Jobs\VirtualMachine\Snapshot\RemoveSnapshot;
use App\Models\ModuleSnapshot;
use App\Models\ModuleVmware;
use App\Services\ActivityLogger;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -17,6 +18,8 @@ class SnapshotController extends Controller
{
use ResolvesVm;
public function __construct(protected ActivityLogger $activityLogger) {}
public function store(Request $request): JsonResponse
{
$customer = $request->user();
@@ -47,6 +50,14 @@ class SnapshotController extends Controller
CreateSnapshot::dispatch($snapshot->id);
$this->activityLogger->log(
event: 'created',
logName: 'Snapshot',
description: "Customer {$customer->email} tạo snapshot: {$snapshot->name} cho VM #{$vm->id}",
subject: $snapshot,
newValues: ['name' => $snapshot->name, 'vm_id' => $vm->id],
);
return response()->json([
'error' => false,
'message' => 'Đã gửi yêu cầu tạo snapshot vào hàng đợi',
@@ -159,6 +170,13 @@ class SnapshotController extends Controller
RevertSnapshot::dispatch($vm->id, $snapshot->id);
$this->activityLogger->log(
event: 'revert',
logName: 'Snapshot',
description: "Customer {$customer->email} revert snapshot: {$snapshot->name} (ID: {$snapshot->id}) cho VM #{$vm->id}",
subject: $snapshot,
);
return response()->json([
'error' => false,
'message' => 'Đã gửi yêu cầu revert snapshot vào hàng đợi',
@@ -189,6 +207,13 @@ class SnapshotController extends Controller
RemoveSnapshot::dispatch($vm->id, $snapshot->id);
$this->activityLogger->log(
event: 'deleted',
logName: 'Snapshot',
description: "Customer {$customer->email} xóa snapshot: {$snapshot->name} (ID: {$snapshot->id}) của VM #{$vm->id}",
subject: $snapshot,
);
return response()->json([
'error' => false,
'message' => 'Đã gửi yêu cầu xóa snapshot vào hàng đợi',