Permission generation fails in certain cases #2154

Closed
opened 2026-02-05 03:07:37 +03:00 by OVERLORD · 0 comments
Owner

Originally created by @ssddanbrown on GitHub (Mar 12, 2021).

Originally assigned to: @ssddanbrown on GitHub.

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.

Originally created by @ssddanbrown on GitHub (Mar 12, 2021). Originally assigned to: @ssddanbrown on GitHub. ### 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.
OVERLORD added the 🐛 Bug🚀 Priority🏭 Back-End labels 2026-02-05 03:07:37 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#2154