Skip to content

Commit

Permalink
New access and list permissions
Browse files Browse the repository at this point in the history
Co-authored-by: Ahmet Bora <[email protected]>
  • Loading branch information
lukasbestle and afbora committed Dec 19, 2024
1 parent 2be7d6d commit 2561fb1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Cms/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions src/Cms/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ class Permissions
'update' => true
],
'languages' => [
'access' => true,
'create' => true,
'delete' => true,
'list' => true,
'update' => true
],
'pages' => [
Expand All @@ -62,26 +64,31 @@ class Permissions
'update' => true
],
'site' => [
'access' => true,
'changeTitle' => true,
'update' => true
],
'users' => [
'access' => true,
'changeEmail' => true,
'changeLanguage' => true,
'changeName' => true,
'changePassword' => true,
'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
]
];
Expand Down
10 changes: 10 additions & 0 deletions src/Cms/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/Cms/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 2561fb1

Please sign in to comment.