X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/257a5a23ecaf7ce779969d575ff8a0b976181d13..refs/pull/2023/head:/app/Auth/Role.php diff --git a/app/Auth/Role.php b/app/Auth/Role.php index c8bb47e45..df9b1cea9 100644 --- a/app/Auth/Role.php +++ b/app/Auth/Role.php @@ -1,8 +1,16 @@ belongsToMany(User::class); + return $this->belongsToMany(User::class)->orderBy('name', 'asc'); } /** @@ -30,7 +38,7 @@ class Role extends Model */ public function permissions() { - return $this->belongsToMany(Permissions\RolePermission::class, 'permission_role', 'role_id', 'permission_id'); + return $this->belongsToMany(RolePermission::class, 'permission_role', 'role_id', 'permission_id'); } /** @@ -51,20 +59,20 @@ class Role extends Model /** * Add a permission to this role. - * @param \BookStack\Auth\Permissions\RolePermission $permission + * @param RolePermission $permission */ - public function attachPermission(Permissions\RolePermission $permission) + public function attachPermission(RolePermission $permission) { $this->permissions()->attach($permission->id); } /** * Detach a single permission from this role. - * @param \BookStack\Auth\Permissions\RolePermission $permission + * @param RolePermission $permission */ - public function detachPermission(Permissions\RolePermission $permission) + public function detachPermission(RolePermission $permission) { - $this->permissions()->detach($permission->id); + $this->permissions()->detach([$permission->id]); } /** @@ -74,7 +82,7 @@ class Role extends Model */ public static function getRole($roleName) { - return static::where('name', '=', $roleName)->first(); + return static::query()->where('name', '=', $roleName)->first(); } /** @@ -84,7 +92,7 @@ class Role extends Model */ public static function getSystemRole($roleName) { - return static::where('system_name', '=', $roleName)->first(); + return static::query()->where('system_name', '=', $roleName)->first(); } /** @@ -93,6 +101,15 @@ class Role extends Model */ public static function visible() { - return static::where('hidden', '=', false)->orderBy('name')->get(); + return static::query()->where('hidden', '=', false)->orderBy('name')->get(); + } + + /** + * Get the roles that can be restricted. + * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection + */ + public static function restrictable() + { + return static::query()->where('system_name', '!=', 'admin')->get(); } }