fix: show first 20 users only in admin view

This commit is contained in:
Andras Bacsai 2024-05-22 14:23:55 +02:00
parent 4d08147647
commit b6d129a5c1
2 changed files with 16 additions and 2 deletions

View File

@ -10,6 +10,8 @@ class AdminView extends Component
{ {
public $users; public $users;
public ?string $search = ""; public ?string $search = "";
public bool $lots_of_users = false;
private $number_of_users_to_show = 20;
public function mount() public function mount()
{ {
if (!isInstanceAdmin()) { if (!isInstanceAdmin()) {
@ -32,8 +34,14 @@ public function submitSearch()
} }
public function getUsers() public function getUsers()
{ {
$this->users = User::where('id', '!=', auth()->id())->get(); $users = User::where('id', '!=', auth()->id())->get();
// $this->users = User::all(); 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;
}
} }
private function finalizeDeletion(User $user, Team $team) private function finalizeDeletion(User $user, Team $team)
{ {
@ -59,6 +67,9 @@ private function finalizeDeletion(User $user, Team $team)
} }
public function delete($id) public function delete($id)
{ {
if (!auth()->user()->isInstanceAdmin()) {
return $this->dispatch('error', 'You are not authorized to delete users');
}
$user = User::find($id); $user = User::find($id);
$teams = $user->teams; $teams = $user->teams;
foreach ($teams as $team) { foreach ($teams as $team) {

View File

@ -25,5 +25,8 @@ class="font-bold text-red-500 dark:text-warning">from the server (if it's reacha
@empty @empty
<div>No users found other than the root.</div> <div>No users found other than the root.</div>
@endforelse @endforelse
@if ($lots_of_users)
<div>There are more users than shown. Please use the search bar to find the user you are looking for.</div>
@endif
</div> </div>
</div> </div>