mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 05:36:00 +00:00
Merge branch 'v0.31.x'
This commit is contained in:
commit
a644f64c6b
@ -3,8 +3,10 @@
|
|||||||
use BookStack\Auth\Permissions;
|
use BookStack\Auth\Permissions;
|
||||||
use BookStack\Auth\Role;
|
use BookStack\Auth\Role;
|
||||||
use BookStack\Entities\Models\Book;
|
use BookStack\Entities\Models\Book;
|
||||||
|
use BookStack\Entities\Models\Chapter;
|
||||||
use BookStack\Entities\Models\Entity;
|
use BookStack\Entities\Models\Entity;
|
||||||
use BookStack\Entities\EntityProvider;
|
use BookStack\Entities\EntityProvider;
|
||||||
|
use BookStack\Entities\Models\Page;
|
||||||
use BookStack\Model;
|
use BookStack\Model;
|
||||||
use BookStack\Traits\HasCreatorAndUpdater;
|
use BookStack\Traits\HasCreatorAndUpdater;
|
||||||
use BookStack\Traits\HasOwner;
|
use BookStack\Traits\HasOwner;
|
||||||
@ -112,21 +114,16 @@ class PermissionService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a chapter via ID, Checks local cache
|
* Get a chapter via ID, Checks local cache
|
||||||
* @param $chapterId
|
|
||||||
* @return \BookStack\Entities\Models\Book
|
|
||||||
*/
|
*/
|
||||||
protected function getChapter($chapterId)
|
protected function getChapter(int $chapterId): ?Chapter
|
||||||
{
|
{
|
||||||
if (isset($this->entityCache['chapter']) && $this->entityCache['chapter']->has($chapterId)) {
|
if (isset($this->entityCache['chapter']) && $this->entityCache['chapter']->has($chapterId)) {
|
||||||
return $this->entityCache['chapter']->get($chapterId);
|
return $this->entityCache['chapter']->get($chapterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$chapter = $this->entityProvider->chapter->find($chapterId);
|
return $this->entityProvider->chapter->newQuery()
|
||||||
if ($chapter === null) {
|
->withTrashed()
|
||||||
$chapter = false;
|
->find($chapterId);
|
||||||
}
|
|
||||||
|
|
||||||
return $chapter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -460,7 +457,7 @@ class PermissionService
|
|||||||
$hasPermissiveAccessToParents = !$book->restricted;
|
$hasPermissiveAccessToParents = !$book->restricted;
|
||||||
|
|
||||||
// For pages with a chapter, Check if explicit permissions are set on the Chapter
|
// For pages with a chapter, Check if explicit permissions are set on the Chapter
|
||||||
if ($entity->isA('page') && $entity->chapter_id !== 0 && $entity->chapter_id !== '0') {
|
if ($entity instanceof Page && intval($entity->chapter_id) !== 0) {
|
||||||
$chapter = $this->getChapter($entity->chapter_id);
|
$chapter = $this->getChapter($entity->chapter_id);
|
||||||
$hasPermissiveAccessToParents = $hasPermissiveAccessToParents && !$chapter->restricted;
|
$hasPermissiveAccessToParents = $hasPermissiveAccessToParents && !$chapter->restricted;
|
||||||
if ($chapter->restricted) {
|
if ($chapter->restricted) {
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
<?php namespace BookStack\Entities\Models;
|
<?php namespace BookStack\Entities\Models;
|
||||||
|
|
||||||
use BookStack\Entities\Models\Chapter;
|
|
||||||
use BookStack\Entities\Models\Entity;
|
|
||||||
use BookStack\Entities\Models\Book;
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
@ -49,7 +46,7 @@ abstract class BookChild extends Entity
|
|||||||
|
|
||||||
// Update all child pages if a chapter
|
// Update all child pages if a chapter
|
||||||
if ($this instanceof Chapter) {
|
if ($this instanceof Chapter) {
|
||||||
foreach ($this->pages as $page) {
|
foreach ($this->pages()->withTrashed()->get() as $page) {
|
||||||
$page->changeBook($newBookId);
|
$page->changeBook($newBookId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,6 +196,24 @@ class SortTest extends TestCase
|
|||||||
$this->assertTrue($chapter->book->id == $newBook->id, 'Page book is now the new book');
|
$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 */
|
||||||
|
$chapter = Chapter::query()->whereHas('pages')->first();
|
||||||
|
$currentBook = $chapter->book;
|
||||||
|
$pageToCheck = $chapter->pages->first();
|
||||||
|
$newBook = Book::query()->where('id', '!=', $currentBook->id)->first();
|
||||||
|
|
||||||
|
$pageToCheck->delete();
|
||||||
|
|
||||||
|
$this->asEditor()->put($chapter->getUrl('/move'), [
|
||||||
|
'entity_selection' => 'book:' . $newBook->id
|
||||||
|
]);
|
||||||
|
|
||||||
|
$pageToCheck->refresh();
|
||||||
|
$this->assertEquals($newBook->id, $pageToCheck->book_id);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_book_sort()
|
public function test_book_sort()
|
||||||
{
|
{
|
||||||
$oldBook = Book::query()->first();
|
$oldBook = Book::query()->first();
|
||||||
|
Loading…
Reference in New Issue
Block a user