BookStack\Services\PermissionService::createJointPermissionData PHP Метод

createJointPermissionData() защищенный Метод

Create entity permission data for an entity and role for a particular action.
protected createJointPermissionData ( Entity $entity, Role $role, $action ) : array
$entity BookStack\Entity
$role BookStack\Role
$action
Результат array
    protected function createJointPermissionData(Entity $entity, Role $role, $action)
    {
        $permissionPrefix = (strpos($action, '-') === false ? $entity->getType() . '-' : '') . $action;
        $roleHasPermission = $role->hasPermission($permissionPrefix . '-all');
        $roleHasPermissionOwn = $role->hasPermission($permissionPrefix . '-own');
        $explodedAction = explode('-', $action);
        $restrictionAction = end($explodedAction);
        if ($entity->isA('book')) {
            if (!$entity->restricted) {
                return $this->createJointPermissionDataArray($entity, $role, $action, $roleHasPermission, $roleHasPermissionOwn);
            } else {
                $hasAccess = $entity->hasActiveRestriction($role->id, $restrictionAction);
                return $this->createJointPermissionDataArray($entity, $role, $action, $hasAccess, $hasAccess);
            }
        } elseif ($entity->isA('chapter')) {
            if (!$entity->restricted) {
                $book = $this->getBook($entity->book_id);
                $hasExplicitAccessToBook = $book->hasActiveRestriction($role->id, $restrictionAction);
                $hasPermissiveAccessToBook = !$book->restricted;
                return $this->createJointPermissionDataArray($entity, $role, $action, $hasExplicitAccessToBook || $roleHasPermission && $hasPermissiveAccessToBook, $hasExplicitAccessToBook || $roleHasPermissionOwn && $hasPermissiveAccessToBook);
            } else {
                $hasAccess = $entity->hasActiveRestriction($role->id, $restrictionAction);
                return $this->createJointPermissionDataArray($entity, $role, $action, $hasAccess, $hasAccess);
            }
        } elseif ($entity->isA('page')) {
            if (!$entity->restricted) {
                $book = $this->getBook($entity->book_id);
                $hasExplicitAccessToBook = $book->hasActiveRestriction($role->id, $restrictionAction);
                $hasPermissiveAccessToBook = !$book->restricted;
                $chapter = $this->getChapter($entity->chapter_id);
                $hasExplicitAccessToChapter = $chapter && $chapter->hasActiveRestriction($role->id, $restrictionAction);
                $hasPermissiveAccessToChapter = $chapter && !$chapter->restricted;
                $acknowledgeChapter = $chapter && $chapter->restricted;
                $hasExplicitAccessToParents = $acknowledgeChapter ? $hasExplicitAccessToChapter : $hasExplicitAccessToBook;
                $hasPermissiveAccessToParents = $acknowledgeChapter ? $hasPermissiveAccessToChapter : $hasPermissiveAccessToBook;
                return $this->createJointPermissionDataArray($entity, $role, $action, $hasExplicitAccessToParents || $roleHasPermission && $hasPermissiveAccessToParents, $hasExplicitAccessToParents || $roleHasPermissionOwn && $hasPermissiveAccessToParents);
            } else {
                $hasAccess = $entity->hasRestriction($role->id, $action);
                return $this->createJointPermissionDataArray($entity, $role, $action, $hasAccess, $hasAccess);
            }
        }
    }