Aligned chapter move permissions with page move permissions

This commit is contained in:
Dan Brown
2022-01-05 16:11:11 +00:00
parent d3ca23b195
commit fbd388ba4c
5 changed files with 36 additions and 9 deletions

View File

@ -198,6 +198,31 @@ class SortTest extends TestCase
$this->assertTrue($chapter->book->id == $newBook->id, 'Page book is now the new book');
}
public function test_chapter_move_requires_create_permissions_in_new_book()
{
$chapter = Chapter::query()->first();
$currentBook = $chapter->book;
$newBook = Book::query()->where('id', '!=', $currentBook->id)->first();
$editor = $this->getEditor();
$this->setEntityRestrictions($newBook, ['view', 'update', 'delete'], [$editor->roles->first()]);
$this->setEntityRestrictions($chapter, ['view', 'update', 'create', 'delete'], [$editor->roles->first()]);
$moveChapterResp = $this->actingAs($editor)->put($chapter->getUrl('/move'), [
'entity_selection' => 'book:' . $newBook->id,
]);
$this->assertPermissionError($moveChapterResp);
$this->setEntityRestrictions($newBook, ['view', 'update', 'create', 'delete'], [$editor->roles->first()]);
$moveChapterResp = $this->put($chapter->getUrl('/move'), [
'entity_selection' => 'book:' . $newBook->id,
]);
$chapter = Chapter::query()->find($chapter->id);
$moveChapterResp->assertRedirect($chapter->getUrl());
$this->assertTrue($chapter->book->id == $newBook->id, 'Page book is now the new book');
}
public function test_chapter_move_changes_book_for_deleted_pages_within()
{
/** @var Chapter $chapter */