From 0c1b1cd435b1b757fecbdd4122803b7fff58c1be Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Fri, 29 Dec 2017 16:14:20 +0000 Subject: [PATCH] Standardised admin role check --- app/Console/Commands/DeleteUsers.php | 4 ++-- app/Repos/UserRepo.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/DeleteUsers.php b/app/Console/Commands/DeleteUsers.php index c287dd55e..8829d3992 100644 --- a/app/Console/Commands/DeleteUsers.php +++ b/app/Console/Commands/DeleteUsers.php @@ -39,11 +39,11 @@ class DeleteUsers extends Command{ $numDeleted = 0; if (strtolower(trim($confirm)) === 'yes') { - $totalUsers = User::count(); + $totalUsers = $this->user->count(); $users = $this->user->where('system_name', '=', null)->with('roles')->get(); foreach ($users as $user) { - if ($user->hasRole('admin')) + if ($user->hasSystemRole('admin')) { // don't delete users with "admin" role continue; diff --git a/app/Repos/UserRepo.php b/app/Repos/UserRepo.php index c3546a442..52ad2e47e 100644 --- a/app/Repos/UserRepo.php +++ b/app/Repos/UserRepo.php @@ -115,9 +115,9 @@ class UserRepo */ public function isOnlyAdmin(User $user) { - if (!$user->roles->pluck('name')->contains('admin')) return false; + if (!$user->hasSystemRole('admin')) return false; - $adminRole = $this->role->getRole('admin'); + $adminRole = $this->role->getSystemRole('admin'); if ($adminRole->users->count() > 1) return false; return true; }