Fix impersonation for moderator

This commit is contained in:
Julien Nahum 2024-01-24 17:45:29 +01:00
parent 2babb5c637
commit 3a25178697
2 changed files with 6 additions and 11 deletions

View File

@ -39,7 +39,6 @@ class ImpersonationController extends Controller
]);
}
\Log::warning('Impersonation started',[
'from_id' => auth()->id(),
'from_email' => auth()->user()->email,
@ -47,15 +46,11 @@ class ImpersonationController extends Controller
'target_email' => $user->id,
]);
// Be this user
if (auth()->user()->moderator) {
$token = auth()->claims([
$token = auth()->claims(auth()->user()->admin ? [] : [
'impersonating' => true,
'impersonator_id' => auth()->id(),
])->login($user);
} else {
$token = auth()->login($user);
}
return $this->success([
'token' => $token
]);

View File

@ -116,7 +116,7 @@ Route::group(['middleware' => 'auth:api'], function () {
});
});
Route::group(['middleware' => 'admin', 'prefix' => 'admin'], function () {
Route::group(['middleware' => 'moderator', 'prefix' => 'admin'], function () {
Route::get('impersonate/{identifier}',
[\App\Http\Controllers\Admin\ImpersonationController::class, 'impersonate']);
});