From 89978409cfaae51d5c9405c8186f43405cf27b5b Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Mon, 28 Sep 2026 14:31:20 +0100 Subject: [PATCH] Chapter Conversion: Fixed page cached permissions not being rebuilt Fixes scenario where page access permissions are changed due to a change of applied permission scope (where a parent book permissions were active, but would no longer be post-promotion), but the page visibility permissions were not being rebuilt. Added test to cover. Fixes #6226 --- app/Entities/Tools/HierarchyTransformer.php | 1 + tests/Entity/ConvertTest.php | 26 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/app/Entities/Tools/HierarchyTransformer.php b/app/Entities/Tools/HierarchyTransformer.php index c58d29bd0..59edb5d1f 100644 --- a/app/Entities/Tools/HierarchyTransformer.php +++ b/app/Entities/Tools/HierarchyTransformer.php @@ -42,6 +42,7 @@ class HierarchyTransformer $this->trashCan->destroyEntity($chapter); Activity::add(ActivityType::BOOK_CREATE_FROM_CHAPTER, $book); + $book->rebuildPermissions(); return $book; } diff --git a/tests/Entity/ConvertTest.php b/tests/Entity/ConvertTest.php index 8658e7699..e3ba78dfe 100644 --- a/tests/Entity/ConvertTest.php +++ b/tests/Entity/ConvertTest.php @@ -67,6 +67,32 @@ class ConvertTest extends TestCase $resp->assertRedirect(); } + public function test_convert_chapter_to_book_rebuilds_page_permissions() + { + $editor = $this->users->editor(); + $chapter = $this->entities->chapterHasPages(); + /** @var Page $childPage */ + $childPage = $chapter->pages()->first(); + $oldBookId = $childPage->book_id; + + // Make chapter non-accessible via parent book, so the permissions should not + // be restricting the child page after conversion + $this->permissions->disableEntityInheritedPermissions($chapter->book); + $this->actingAs($editor)->get($childPage->getUrl())->assertNotFound(); + + $resp = $this->asAdmin()->post($chapter->getUrl('/convert-to-book')); + $resp->assertRedirectContains('/books/'); + + /** @var Book $newBook */ + $newBook = Book::query()->orderBy('id', 'desc')->first(); + $childPage->refresh(); + $this->assertNotEquals($oldBookId, $childPage->book_id); + $this->assertEquals($newBook->id, $childPage->book_id); + + $resp = $this->actingAs($editor)->get($childPage->getUrl()); + $resp->assertOk(); + } + public function test_book_edit_view_shows_convert_option() { $book = $this->entities->book();