Refactor Admin Panel with more features (#384)

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Chirag Chhatrala
2024-04-22 19:41:21 +05:30
committed by GitHub
parent eeb3ec3b77
commit 053a4a4976
12 changed files with 586 additions and 111 deletions

View File

@@ -3,7 +3,6 @@
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Forms\Form;
use App\Models\User;
class ImpersonationController extends Controller
@@ -13,22 +12,10 @@ class ImpersonationController extends Controller
$this->middleware('moderator');
}
public function impersonate($identifier)
public function impersonate($userId)
{
$user = null;
if (is_numeric($identifier)) {
$user = User::find($identifier);
} elseif (filter_var($identifier, FILTER_VALIDATE_EMAIL)) {
$user = User::whereEmail($identifier)->first();
} else {
// Find by form slug
$form = Form::whereSlug($identifier)->first();
if ($form) {
$user = $form->creator;
}
}
if (! $user) {
$user = User::find($userId);
if (!$user) {
return $this->error([
'message' => 'User not found.',
]);
@@ -38,7 +25,7 @@ class ImpersonationController extends Controller
]);
}
\Log::warning('Impersonation started', [
\Log::warning(AdminController::ADMIN_LOG_PREFIX . 'Impersonation started', [
'from_id' => auth()->id(),
'from_email' => auth()->user()->email,
'target_id' => $user->id,