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
This commit is contained in:
Dan Brown
2026-09-28 14:38:27 +01:00
parent 9f2c10cb49
commit 89978409cf
2 changed files with 27 additions and 0 deletions
@@ -42,6 +42,7 @@ class HierarchyTransformer
$this->trashCan->destroyEntity($chapter);
Activity::add(ActivityType::BOOK_CREATE_FROM_CHAPTER, $book);
$book->rebuildPermissions();
return $book;
}
+26
View File
@@ -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();