X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/4b36df08a80f467c037de3bbdf85e13cd4cef9bc..refs/pull/3918/head:/app/Auth/Role.php diff --git a/app/Auth/Role.php b/app/Auth/Role.php index 255158afb..b293d1af2 100644 --- a/app/Auth/Role.php +++ b/app/Auth/Role.php @@ -1,29 +1,40 @@ -belongsToMany(User::class)->orderBy('name', 'asc'); } @@ -39,11 +50,19 @@ class Role extends Model implements Loggable /** * 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'); } + /** + * Get the entity permissions assigned to this role. + */ + public function entityPermissions(): HasMany + { + return $this->hasMany(EntityPermission::class); + } + /** * Check if this role has a permission. */ @@ -55,6 +74,7 @@ class Role extends Model implements Loggable return true; } } + return false; } @@ -77,7 +97,7 @@ class Role extends Model implements Loggable /** * 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(); } @@ -85,29 +105,13 @@ class Role extends Model implements Loggable /** * 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 - */ - public static function visible(): Collection - { - return static::query()->where('hidden', '=', false)->orderBy('name')->get(); - } - - /** - * Get the roles that can be restricted. - */ - public static function restrictable(): Collection - { - return static::query()->where('system_name', '!=', 'admin')->get(); - } - - /** - * @inheritdoc + * {@inheritdoc} */ public function logDescriptor(): string {