Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission generation fails in certain cases #2632

Closed
ssddanbrown opened this issue Mar 11, 2021 · 0 comments
Closed

Permission generation fails in certain cases #2632

ssddanbrown opened this issue Mar 11, 2021 · 0 comments

Comments

@ssddanbrown
Copy link
Member

ssddanbrown commented Mar 11, 2021

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.

@ssddanbrown ssddanbrown self-assigned this Mar 11, 2021
@ssddanbrown ssddanbrown added this to the v0.31.8 milestone Mar 13, 2021
ssddanbrown added a commit that referenced this issue Mar 13, 2021
Could occur when a chapter was moved with deleted pages.
Fixes #2632
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant