- Add `$selectedActions = []` parameter to delete/remove methods in multiple Livewire components to support optional deletion actions - Return error message string when password verification fails instead of silent return - Return `true` on successful deletion to indicate completion - Handle selectedActions to set component properties for cascading deletions (delete_volumes, delete_networks, delete_configurations, docker_cleanup) - Add test coverage for Danger component delete functionality with password validation and selected actions handling
85 lines
2.1 KiB
PHP
85 lines
2.1 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, $selectedActions = [])
|
|
{
|
|
if (! isInstanceAdmin()) {
|
|
return redirect()->route('dashboard');
|
|
}
|
|
|
|
if (! verifyPasswordConfirmation($password, $this)) {
|
|
return 'The provided password is incorrect.';
|
|
}
|
|
|
|
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();
|
|
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
return $this->dispatch('error', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.team.admin-view');
|
|
}
|
|
}
|