Skip to content

Permission generation fails in certain cases #2632

Description

@ssddanbrown

Log

[2021-03-11 02:25:41] production.ERROR: Trying to get property 'restricted' of non-object {"userId":5,"exception":"[object] (ErrorException(code: 0): Trying to get property 'restricted' of non-object at /var/www/html/app/Auth/Permissions/PermissionService.php:466)

I also tried regenerating the permissions with the command, but that gave me another error message:
root@bookstack-57b6767f87-cfgnv:/var/www/html# php artisan bookstack:regenerate-permissions

   ErrorException  : Trying to get property 'restricted' of non-object

  at /var/www/html/app/Auth/Permissions/PermissionService.php:466
    462|         // For pages with a chapter, Check if explicit permissions are set on the Chapter
    463|         if ($entity->isA('page') && $entity->chapter_id !== 0 && $entity->chapter_id !== '0') {
    464|             $chapter = $this->getChapter($entity->chapter_id);
    465|             $hasPermissiveAccessToParents = $hasPermissiveAccessToParents && !$chapter->restricted;
466|             if ($chapter->restricted) {
    467|                 $hasExplicitAccessToParents = $this->mapHasActiveRestriction($permissionMap, $chapter, $role, $restrictionAction);
    468|             }
    469|         }
    470|

  Exception trace:

  1   Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Trying to get property 'restricted' of non-object", "/var/www/html/app/Auth/Permissions/PermissionService.php")
      /var/www/html/app/Auth/Permissions/PermissionService.php:466

Findings

Can replicate with the following:

  • You delete a page within a chapter.
  • Move the parent chapter of the deleted page to a different book. (Deleted page book_id and chapter book_id become mis-aligned at this point).
  • Delete that chapter.
  • Perform a book sort operation where the original deleted page is included and a change is made.

Primary issue is the mis-alignment of the chapter and page book_id, caused due to page book move actions not taking into account deleted pages.
The error point of the permission service could do with a little attention also, But any heavy refactoring should be done in #2633 so this can be safely part of a patch release.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions