coolify/app/Livewire/Team/AdminView.php
Andras Bacsai b0d50669b1 fix: skip password confirmation for OAuth users
OAuth users don't have passwords set, so they should not be prompted for password confirmation when performing destructive actions. This fix:
- Detects OAuth users via the hasPassword() method
- Skips password confirmation in modal for OAuth users
- Keeps text name confirmation as the final step
- Centralizes logic in helper functions for maintainability
- Changes button text to "Confirm" when password step is skipped

Fixes #4457

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-12 14:12:02 +01:00

83 lines
2 KiB
PHP

<?php
namespace App\Livewire\Team;
use App\Models\User;
use Livewire\Component;
class AdminView extends Component
{
public $users;
public ?string $search = '';
public bool $lots_of_users = false;
private $number_of_users_to_show = 20;
public function mount()
{
if (! isInstanceAdmin()) {
return redirect()->route('dashboard');
}
$this->getUsers();
}
public function submitSearch()
{
if ($this->search !== '') {
$this->users = User::where(function ($query) {
$query->where('name', 'like', "%{$this->search}%")
->orWhere('email', 'like', "%{$this->search}%");
})->get()->filter(function ($user) {
return $user->id !== auth()->id();
});
} else {
$this->getUsers();
}
}
public function getUsers()
{
$users = User::where('id', '!=', auth()->id())->get();
if ($users->count() > $this->number_of_users_to_show) {
$this->lots_of_users = true;
$this->users = $users->take($this->number_of_users_to_show);
} else {
$this->lots_of_users = false;
$this->users = $users;
}
}
public function delete($id, $password)
{
if (! isInstanceAdmin()) {
return redirect()->route('dashboard');
}
if (! verifyPasswordConfirmation($password, $this)) {
return;
}
if (! auth()->user()->isInstanceAdmin()) {
return $this->dispatch('error', 'You are not authorized to delete users');
}
$user = User::find($id);
if (! $user) {
return $this->dispatch('error', 'User not found');
}
try {
$user->delete();
$this->getUsers();
} catch (\Exception $e) {
return $this->dispatch('error', $e->getMessage());
}
}
public function render()
{
return view('livewire.team.admin-view');
}
}