Standardised admin role check

This commit is contained in:
Dan Brown 2017-12-29 16:14:20 +00:00
parent 3eb2246291
commit 0c1b1cd435
No known key found for this signature in database
GPG key ID: 46D9F943C24A2EF9
2 changed files with 4 additions and 4 deletions

View 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;

View 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;
}