mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-28 13:12:05 +00:00
Merge branch 'v0.30.x'
This commit is contained in:
commit
cf04a0d818
@ -204,7 +204,7 @@ class ExportFormatter
|
|||||||
{
|
{
|
||||||
$text = $chapter->name . "\n\n";
|
$text = $chapter->name . "\n\n";
|
||||||
$text .= $chapter->description . "\n\n";
|
$text .= $chapter->description . "\n\n";
|
||||||
foreach ($chapter->pages as $page) {
|
foreach ($chapter->getVisiblePages() as $page) {
|
||||||
$text .= $this->pageToPlainText($page);
|
$text .= $this->pageToPlainText($page);
|
||||||
}
|
}
|
||||||
return $text;
|
return $text;
|
||||||
@ -215,7 +215,7 @@ class ExportFormatter
|
|||||||
*/
|
*/
|
||||||
public function bookToPlainText(Book $book): string
|
public function bookToPlainText(Book $book): string
|
||||||
{
|
{
|
||||||
$bookTree = (new BookContents($book))->getTree(false, true);
|
$bookTree = (new BookContents($book))->getTree(false, false);
|
||||||
$text = $book->name . "\n\n";
|
$text = $book->name . "\n\n";
|
||||||
foreach ($bookTree as $bookChild) {
|
foreach ($bookTree as $bookChild) {
|
||||||
if ($bookChild->isA('chapter')) {
|
if ($bookChild->isA('chapter')) {
|
||||||
|
@ -112,7 +112,7 @@ class ImageRepo
|
|||||||
if ($filterType === 'page') {
|
if ($filterType === 'page') {
|
||||||
$query->where('uploaded_to', '=', $contextPage->id);
|
$query->where('uploaded_to', '=', $contextPage->id);
|
||||||
} elseif ($filterType === 'book') {
|
} elseif ($filterType === 'book') {
|
||||||
$validPageIds = $contextPage->book->pages()->get(['id'])->pluck('id')->toArray();
|
$validPageIds = $contextPage->book->pages()->visible()->get(['id'])->pluck('id')->toArray();
|
||||||
$query->whereIn('uploaded_to', $validPageIds);
|
$query->whereIn('uploaded_to', $validPageIds);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
67
tests/Permissions/ExportPermissionsTest.php
Normal file
67
tests/Permissions/ExportPermissionsTest.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?php namespace Tests\Permissions;
|
||||||
|
|
||||||
|
use BookStack\Entities\Book;
|
||||||
|
use BookStack\Entities\Chapter;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class ExportPermissionsTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function test_page_content_without_view_access_hidden_on_chapter_export()
|
||||||
|
{
|
||||||
|
$chapter = Chapter::query()->first();
|
||||||
|
$page = $chapter->pages()->firstOrFail();
|
||||||
|
$pageContent = Str::random(48);
|
||||||
|
$page->html = '<p>' . $pageContent . '</p>';
|
||||||
|
$page->save();
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
$this->actingAs($viewer);
|
||||||
|
$formats = ['html', 'plaintext'];
|
||||||
|
|
||||||
|
foreach ($formats as $format) {
|
||||||
|
$resp = $this->get($chapter->getUrl("export/{$format}"));
|
||||||
|
$resp->assertStatus(200);
|
||||||
|
$resp->assertSee($page->name);
|
||||||
|
$resp->assertSee($pageContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setEntityRestrictions($page, []);
|
||||||
|
|
||||||
|
foreach ($formats as $format) {
|
||||||
|
$resp = $this->get($chapter->getUrl("export/{$format}"));
|
||||||
|
$resp->assertStatus(200);
|
||||||
|
$resp->assertDontSee($page->name);
|
||||||
|
$resp->assertDontSee($pageContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_page_content_without_view_access_hidden_on_book_export()
|
||||||
|
{
|
||||||
|
$book = Book::query()->first();
|
||||||
|
$page = $book->pages()->firstOrFail();
|
||||||
|
$pageContent = Str::random(48);
|
||||||
|
$page->html = '<p>' . $pageContent . '</p>';
|
||||||
|
$page->save();
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
$this->actingAs($viewer);
|
||||||
|
$formats = ['html', 'plaintext'];
|
||||||
|
|
||||||
|
foreach ($formats as $format) {
|
||||||
|
$resp = $this->get($book->getUrl("export/{$format}"));
|
||||||
|
$resp->assertStatus(200);
|
||||||
|
$resp->assertSee($page->name);
|
||||||
|
$resp->assertSee($pageContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setEntityRestrictions($page, []);
|
||||||
|
|
||||||
|
foreach ($formats as $format) {
|
||||||
|
$resp = $this->get($book->getUrl("export/{$format}"));
|
||||||
|
$resp->assertStatus(200);
|
||||||
|
$resp->assertDontSee($page->name);
|
||||||
|
$resp->assertDontSee($pageContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user