]> BookStack Code Mirror - bookstack/commitdiff
Standardised admin role check
authorDan Brown <redacted>
Fri, 29 Dec 2017 16:14:20 +0000 (16:14 +0000)
committerDan Brown <redacted>
Fri, 29 Dec 2017 16:14:20 +0000 (16:14 +0000)
app/Console/Commands/DeleteUsers.php
app/Repos/UserRepo.php

index c287dd55eaf32ab458ba4af1c8b9a3f926bb108f..8829d39923a58b4911de1fde0d57ccfd65adabc7 100644 (file)
@@ -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;
index c3546a442cc27dc8fecfc54d04ec66f0b16ceac9..52ad2e47e9a3390dd5ed3665a714fe2d361bcee2 100644 (file)
@@ -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;
     }