X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/21f2a7087c7ef1af1e30e1997bce77cc64ede76e..refs/pull/3179/head:/app/Entities/Repos/ChapterRepo.php diff --git a/app/Entities/Repos/ChapterRepo.php b/app/Entities/Repos/ChapterRepo.php index 87f9e9e40..2b81891af 100644 --- a/app/Entities/Repos/ChapterRepo.php +++ b/app/Entities/Repos/ChapterRepo.php @@ -10,6 +10,7 @@ use BookStack\Entities\Tools\BookContents; use BookStack\Entities\Tools\TrashCan; use BookStack\Exceptions\MoveOperationException; use BookStack\Exceptions\NotFoundException; +use BookStack\Exceptions\PermissionsException; use BookStack\Facades\Activity; use Exception; @@ -85,15 +86,19 @@ class ChapterRepo * 'book:' (book:5). * * @throws MoveOperationException + * @throws PermissionsException */ public function move(Chapter $chapter, string $parentIdentifier): Book { - /** @var Book $parent */ $parent = $this->findParentByIdentifier($parentIdentifier); if (is_null($parent)) { throw new MoveOperationException('Book to move chapter into not found'); } + if (!userCan('chapter-create', $parent)) { + throw new PermissionsException('User does not have permission to create a chapter within the chosen book'); + } + $chapter->changeBook($parent->id); $chapter->rebuildPermissions(); Activity::add(ActivityType::CHAPTER_MOVE, $chapter);