Add cross-organisation admin API endpoints behind role:super_admin middleware: - AdminOrganisationController: CRUD with search, filter, billing_status management - AdminUserController: user management with role assignment across orgs - AdminStatsController: platform-wide aggregate statistics - AdminActivityLogController: filterable activity log viewer - AdminImpersonationController + ImpersonationService: user impersonation with token-based session management and activity logging - BillingStatus enum, form requests, API resources, 23 feature tests Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Resources\Admin\AdminUserResource;
|
|
use App\Models\User;
|
|
use App\Services\ImpersonationService;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
final class AdminImpersonationController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly ImpersonationService $impersonationService,
|
|
) {}
|
|
|
|
public function start(User $user): JsonResponse
|
|
{
|
|
/** @var User $admin */
|
|
$admin = auth()->user();
|
|
$result = $this->impersonationService->start($admin, $user);
|
|
|
|
return $this->success([
|
|
'token' => $result['token'],
|
|
'user' => new AdminUserResource($result['user']->load('organisations')),
|
|
'admin_id' => $result['admin_id'],
|
|
]);
|
|
}
|
|
|
|
public function stop(): JsonResponse
|
|
{
|
|
/** @var User $currentUser */
|
|
$currentUser = auth()->user();
|
|
$admin = $this->impersonationService->stop($currentUser);
|
|
|
|
return $this->success([
|
|
'user' => new AdminUserResource($admin->load('organisations')),
|
|
]);
|
|
}
|
|
}
|