# Conflicts: # app/Http/Controllers/Api/SecurityController.php # app/Http/Controllers/Api/ServersController.php # app/Livewire/Admin/Index.php # app/Livewire/Destination/Show.php # app/Livewire/NavbarDeleteTeam.php # app/Livewire/Project/Application/Previews.php # app/Livewire/Project/DeleteProject.php # app/Livewire/Project/Shared/ResourceOperations.php # app/Livewire/Server/Resources.php # app/Livewire/Server/ValidateAndInstall.php # app/Livewire/Storage/Show.php # resources/views/livewire/dashboard.blade.php # resources/views/livewire/project/application/heading.blade.php # resources/views/livewire/project/database/heading.blade.php # resources/views/livewire/project/service/heading.blade.php # resources/views/livewire/project/shared/environment-variable/show.blade.php # resources/views/livewire/project/shared/scheduled-task/show.blade.php # tests/Feature/Security/TrustHostsMiddlewareTest.php
91 lines
2.2 KiB
PHP
91 lines
2.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 (! isInstanceAdmin()) {
|
|
return;
|
|
}
|
|
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()
|
|
{
|
|
if (! isInstanceAdmin()) {
|
|
return;
|
|
}
|
|
$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');
|
|
}
|
|
}
|