mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-05 09:34:37 +08:00
Fixed book-tree-gen page visibility issue
When book trees were generated, pages in chapters where ALL pages within were not supposed to be visibile, would be visible due to the code falling back on the raw relation which would not account for permissions. This has now been changed so that a custom 'visible_pages' attribute is set and used by any book tree structures, to ensure it does not fall back to the raw relation. Added an extra test to cover. For #2414
This commit is contained in:
@ -5,7 +5,6 @@ use Illuminate\Support\Collection;
|
||||
/**
|
||||
* Class Chapter
|
||||
* @property Collection<Page> $pages
|
||||
* @package BookStack\Entities
|
||||
*/
|
||||
class Chapter extends BookChild
|
||||
{
|
||||
@ -52,15 +51,6 @@ class Chapter extends BookChild
|
||||
return mb_strlen($description) > $length ? mb_substr($description, 0, $length-3) . '...' : $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this chapter has any child pages.
|
||||
* @return bool
|
||||
*/
|
||||
public function hasChildren()
|
||||
{
|
||||
return count($this->pages) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the visible pages in this chapter.
|
||||
*/
|
||||
|
@ -53,12 +53,16 @@ class BookContents
|
||||
$pages->groupBy('chapter_id')->each(function ($pages, $chapter_id) use ($chapterMap, &$lonePages) {
|
||||
$chapter = $chapterMap->get($chapter_id);
|
||||
if ($chapter) {
|
||||
$chapter->setAttribute('pages', collect($pages)->sortBy($this->bookChildSortFunc()));
|
||||
$chapter->setAttribute('visible_pages', collect($pages)->sortBy($this->bookChildSortFunc()));
|
||||
} else {
|
||||
$lonePages = $lonePages->concat($pages);
|
||||
}
|
||||
});
|
||||
|
||||
$chapters->whereNull('visible_pages')->each(function (Chapter $chapter) {
|
||||
$chapter->setAttribute('visible_pages', collect([]));
|
||||
});
|
||||
|
||||
$all->each(function (Entity $entity) use ($renderPages) {
|
||||
$entity->setRelation('book', $this->book);
|
||||
|
||||
|
Reference in New Issue
Block a user