feat: add user impersonation service

This commit is contained in:
idevakk
2025-11-17 10:44:19 -08:00
parent f60c986e07
commit a7029b5f57
21 changed files with 1343 additions and 6 deletions

View File

@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('impersonation_logs', function (Blueprint $table) {
$table->id();
$table->foreignId('admin_id')->constrained('users')->onDelete('cascade');
$table->foreignId('target_user_id')->constrained('users')->onDelete('cascade');
$table->timestamp('start_time');
$table->timestamp('end_time')->nullable();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->enum('status', ['active', 'completed', 'force_terminated', 'expired'])->default('active');
$table->json('pages_visited')->nullable();
$table->json('actions_taken')->nullable();
$table->timestamps();
// Indexes for performance
$table->index(['admin_id', 'start_time']);
$table->index(['target_user_id', 'start_time']);
$table->index(['status', 'start_time']);
$table->index(['ip_address']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('impersonation_logs');
}
};