Both caught in tests:
Fixed loss of permissions for admin users when entity restrictions were
active, since there are no entity-restrictions for the admin role but
we'd force generate them in joint permissions, which would be queried.
Fixed new role permission checks when permissions given with only the
action (eg. 'view'), since the type prefix would be required for role
permission checks. Was previously not needed as only the simpler form
was used in the jointpermissions after merge & calculation.
{
$explodedPermission = explode('-', $permission);
$action = $explodedPermission[1] ?? $explodedPermission[0];
{
$explodedPermission = explode('-', $permission);
$action = $explodedPermission[1] ?? $explodedPermission[0];
+ $fullPermission = count($explodedPermission) > 1 ? $permission : $ownable->getMorphClass() . '-' . $permission;
+
$user = $this->currentUser();
$userRoleIds = $this->getCurrentUserRoleIds();
$user = $this->currentUser();
$userRoleIds = $this->getCurrentUserRoleIds();
- $allRolePermission = $user->can($permission . '-all');
- $ownRolePermission = $user->can($permission . '-own');
+ $allRolePermission = $user->can($fullPermission . '-all');
+ $ownRolePermission = $user->can($fullPermission . '-own');
$nonJointPermissions = ['restrictions', 'image', 'attachment', 'comment'];
$ownerField = ($ownable instanceof Entity) ? 'owned_by' : 'created_by';
$isOwner = $user->id === $ownable->getAttribute($ownerField);
$nonJointPermissions = ['restrictions', 'image', 'attachment', 'comment'];
$ownerField = ($ownable instanceof Entity) ? 'owned_by' : 'created_by';
$isOwner = $user->id === $ownable->getAttribute($ownerField);
return $hasRolePermission;
}
return $hasRolePermission;
}
- $entityPermissions = $this->getApplicableEntityPermissions($ownable, $userRoleIds, $action);
- if (is_null($entityPermissions)) {
- return $hasRolePermission;
- }
+ $hasApplicableEntityPermissions = $this->hasEntityPermission($ownable, $userRoleIds, $action);
- return count($entityPermissions) > 0;
+ return is_null($hasApplicableEntityPermissions) ? $hasRolePermission : $hasApplicableEntityPermissions;
- * Get the permissions that are applicable for the given entity item.
- * Returns null when no entity permissions apply otherwise entity permissions
- * are active, even if the returned array is empty.
- *
- * @returns EntityPermission[]
+ * Check if there are permissions that are applicable for the given entity item, action and roles.
+ * Returns null when no entity permissions are in force.
- protected function getApplicableEntityPermissions(Entity $entity, array $userRoleIds, string $action): ?array
+ protected function hasEntityPermission(Entity $entity, array $userRoleIds, string $action): ?bool
+ $adminRoleId = Role::getSystemRole('admin')->id;
+ if (in_array($adminRoleId, $userRoleIds)) {
+ return true;
+ }
+
$chain = [$entity];
if ($entity instanceof Page && $entity->chapter_id) {
$chain[] = $entity->chapter;
$chain = [$entity];
if ($entity instanceof Page && $entity->chapter_id) {
$chain[] = $entity->chapter;
return $currentEntity->permissions()
->whereIn('role_id', $userRoleIds)
->where('action', '=', $action)
return $currentEntity->permissions()
->whereIn('role_id', $userRoleIds)
->where('action', '=', $action)
/**
* Check if this shelf contains the given book.
/**
* Check if this shelf contains the given book.
- *
- * @param Book $book
- *
- * @return bool
*/
public function contains(Book $book): bool
{
*/
public function contains(Book $book): bool
{
/**
* Add a book to the end of this shelf.
/**
* Add a book to the end of this shelf.
- *
- * @param Book $book
*/
public function appendBook(Book $book)
{
*/
public function appendBook(Book $book)
{
+ /** @var Bookshelf $shelf */
$shelf = Bookshelf::visible()->find($contextBookshelfId);
$shelfContainsBook = $shelf && $shelf->contains($book);
$shelf = Bookshelf::visible()->find($contextBookshelfId);
$shelfContainsBook = $shelf && $shelf->contains($book);
public function show(ActivityQueries $activities, string $slug)
{
$shelf = $this->bookshelfRepo->getBySlug($slug);
public function show(ActivityQueries $activities, string $slug)
{
$shelf = $this->bookshelfRepo->getBySlug($slug);
- $this->checkOwnablePermission('book-view', $shelf);
+ $this->checkOwnablePermission('bookshelf-view', $shelf);
$sort = setting()->getForCurrentUser('shelf_books_sort', 'default');
$order = setting()->getForCurrentUser('shelf_books_sort_order', 'asc');
$sort = setting()->getForCurrentUser('shelf_books_sort', 'default');
$order = setting()->getForCurrentUser('shelf_books_sort_order', 'asc');