diff --git a/src/Cms/Language.php b/src/Cms/Language.php index c5053c359a..c7e5fb0808 100644 --- a/src/Cms/Language.php +++ b/src/Cms/Language.php @@ -300,6 +300,16 @@ public function exists(): bool return file_exists($this->root()); } + /** + * Checks if the language is accessible to the current user + */ + public function isAccessible(): bool + { + static $accessible = []; + $role = $this->kirby()->role()?->id() ?? '__none__'; + return $accessible[$role] ??= $this->permissions()->can('access'); + } + /** * Checks if this is the default language * for the site. diff --git a/src/Cms/Permissions.php b/src/Cms/Permissions.php index a89ff22a49..d584337d7d 100644 --- a/src/Cms/Permissions.php +++ b/src/Cms/Permissions.php @@ -41,8 +41,10 @@ class Permissions 'update' => true ], 'languages' => [ + 'access' => true, 'create' => true, 'delete' => true, + 'list' => true, 'update' => true ], 'pages' => [ @@ -62,10 +64,12 @@ class Permissions 'update' => true ], 'site' => [ + 'access' => true, 'changeTitle' => true, 'update' => true ], 'users' => [ + 'access' => true, 'changeEmail' => true, 'changeLanguage' => true, 'changeName' => true, @@ -73,15 +77,18 @@ class Permissions 'changeRole' => true, 'create' => true, 'delete' => true, + 'list' => true, 'update' => true ], 'user' => [ + 'access' => true, 'changeEmail' => true, 'changeLanguage' => true, 'changeName' => true, 'changePassword' => true, 'changeRole' => true, 'delete' => true, + 'list' => true, 'update' => true ] ]; diff --git a/src/Cms/Site.php b/src/Cms/Site.php index fa8a2a336a..089e3d19ff 100644 --- a/src/Cms/Site.php +++ b/src/Cms/Site.php @@ -266,6 +266,16 @@ public function is($site): bool return $this === $site; } + /** + * Checks if the site is accessible to the current user + */ + public function isAccessible(): bool + { + static $accessible = []; + $role = $this->kirby()->role()?->id() ?? '__none__'; + return $accessible[$role] ??= $this->permissions()->can('access'); + } + /** * Returns the root to the media folder for the site * @internal diff --git a/src/Cms/User.php b/src/Cms/User.php index 62b0398b65..a484d02ced 100644 --- a/src/Cms/User.php +++ b/src/Cms/User.php @@ -281,6 +281,16 @@ public function is(User|null $user = null): bool return $this->id() === $user->id(); } + /** + * Checks if the user is accessible to the current user + */ + public function isAccessible(): bool + { + static $accessible = []; + $role = $this->kirby()->role()?->id() ?? '__none__'; + return $accessible[$role] ??= $this->permissions()->can('access'); + } + /** * Checks if this user has the admin role */