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',[ \Log::warning('Impersonation started',[
'from_id' => auth()->id(), 'from_id' => auth()->id(),
'from_email' => auth()->user()->email, 'from_email' => auth()->user()->email,
@ -47,15 +46,11 @@ class ImpersonationController extends Controller
'target_email' => $user->id, 'target_email' => $user->id,
]); ]);
// Be this user $token = auth()->claims(auth()->user()->admin ? [] : [
if (auth()->user()->moderator) {
$token = auth()->claims([
'impersonating' => true, 'impersonating' => true,
'impersonator_id' => auth()->id(), 'impersonator_id' => auth()->id(),
])->login($user); ])->login($user);
} else {
$token = auth()->login($user);
}
return $this->success([ return $this->success([
'token' => $token '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}', Route::get('impersonate/{identifier}',
[\App\Http\Controllers\Admin\ImpersonationController::class, 'impersonate']); [\App\Http\Controllers\Admin\ImpersonationController::class, 'impersonate']);
}); });