X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/2d958e88bfc5a24e91223e328322b6d21d74215d..refs/pull/205/head:/app/Repos/ChapterRepo.php diff --git a/app/Repos/ChapterRepo.php b/app/Repos/ChapterRepo.php index 1a8cbdf0f..96f5b2d1e 100644 --- a/app/Repos/ChapterRepo.php +++ b/app/Repos/ChapterRepo.php @@ -98,8 +98,8 @@ class ChapterRepo extends EntityRepo { $chapter = $this->chapter->newInstance($input); $chapter->slug = $this->findSuitableSlug($chapter->name, $book->id); - $chapter->created_by = auth()->user()->id; - $chapter->updated_by = auth()->user()->id; + $chapter->created_by = user()->id; + $chapter->updated_by = user()->id; $chapter = $book->chapters()->save($chapter); $this->permissionService->buildJointPermissionsForEntity($chapter); return $chapter; @@ -195,11 +195,12 @@ class ChapterRepo extends EntityRepo /** * Changes the book relation of this chapter. - * @param $bookId + * @param $bookId * @param Chapter $chapter + * @param bool $rebuildPermissions * @return Chapter */ - public function changeBook($bookId, Chapter $chapter) + public function changeBook($bookId, Chapter $chapter, $rebuildPermissions = false) { $chapter->book_id = $bookId; // Update related activity @@ -213,9 +214,12 @@ class ChapterRepo extends EntityRepo foreach ($chapter->pages as $page) { $this->pageRepo->changeBook($bookId, $page); } - // Update permissions - $chapter->load('book'); - $this->permissionService->buildJointPermissionsForEntity($chapter->book); + + // Update permissions if applicable + if ($rebuildPermissions) { + $chapter->load('book'); + $this->permissionService->buildJointPermissionsForEntity($chapter->book); + } return $chapter; }