X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/5f1ee5fb0e8f9422650b380f8bdd7299618a99fa..refs/pull/3113/head:/app/Auth/Role.php diff --git a/app/Auth/Role.php b/app/Auth/Role.php index 13ec6df16..71da88e19 100644 --- a/app/Auth/Role.php +++ b/app/Auth/Role.php @@ -1,28 +1,37 @@ -belongsToMany(User::class)->orderBy('name', 'asc'); } @@ -38,7 +47,7 @@ class Role extends Model /** * The RolePermissions that belong to the role. */ - public function permissions() + public function permissions(): BelongsToMany { return $this->belongsToMany(RolePermission::class, 'permission_role', 'role_id', 'permission_id'); } @@ -54,6 +63,7 @@ class Role extends Model return true; } } + return false; } @@ -76,7 +86,7 @@ class Role extends Model /** * Get the role of the specified display name. */ - public static function getRole(string $displayName): ?Role + public static function getRole(string $displayName): ?self { return static::query()->where('display_name', '=', $displayName)->first(); } @@ -84,13 +94,13 @@ class Role extends Model /** * Get the role object for the specified system role. */ - public static function getSystemRole(string $systemName): ?Role + public static function getSystemRole(string $systemName): ?self { return static::query()->where('system_name', '=', $systemName)->first(); } /** - * Get all visible roles + * Get all visible roles. */ public static function visible(): Collection { @@ -102,6 +112,17 @@ class Role extends Model */ public static function restrictable(): Collection { - return static::query()->where('system_name', '!=', 'admin')->get(); + return static::query() + ->where('system_name', '!=', 'admin') + ->orderBy('display_name', 'asc') + ->get(); + } + + /** + * {@inheritdoc} + */ + public function logDescriptor(): string + { + return "({$this->id}) {$this->display_name}"; } }