]> BookStack Code Mirror - bookstack/commitdiff
ZIP Exports: Prevent book child page drafts from being included
authorDan Brown <redacted>
Sun, 22 Dec 2024 12:43:26 +0000 (12:43 +0000)
committerDan Brown <redacted>
Sun, 22 Dec 2024 12:43:26 +0000 (12:43 +0000)
Added test to cover

app/Exports/ZipExports/Models/ZipExportBook.php
tests/Exports/ZipExportTest.php

index 4f641d25bd71cd05025b4c95f5d90944ba3123b4..39176ded420dd0beb03041fdb4f1d29b76f038e5 100644 (file)
@@ -70,7 +70,7 @@ class ZipExportBook extends ZipExportModel
         foreach ($children as $child) {
             if ($child instanceof Chapter) {
                 $chapters[] = $child;
-            } else if ($child instanceof Page) {
+            } else if ($child instanceof Page && !$child->draft) {
                 $pages[] = $child;
             }
         }
index ebe07d052bcd94a619ee68f9d0ea0878efc97785..163828c1b6e9785cc74ca8364ffcabeb0300bdac 100644 (file)
@@ -198,7 +198,7 @@ class ZipExportTest extends TestCase
 
     public function test_book_export()
     {
-        $book = $this->entities->book();
+        $book = $this->entities->bookHasChaptersAndPages();
         $book->tags()->saveMany(Tag::factory()->count(2)->make());
 
         $zipResp = $this->asEditor()->get($book->getUrl("/export/zip"));
@@ -251,6 +251,35 @@ class ZipExportTest extends TestCase
         $this->assertCount($chapter->pages()->count(), $chapterData['pages']);
     }
 
+    public function test_draft_pages_are_not_included()
+    {
+        $editor = $this->users->editor();
+        $entities = $this->entities->createChainBelongingToUser($editor);
+        $book = $entities['book'];
+        $page = $entities['page'];
+        $chapter = $entities['chapter'];
+        $book->tags()->saveMany(Tag::factory()->count(2)->make());
+
+        $page->created_by = $editor->id;
+        $page->draft = true;
+        $page->save();
+
+        $zipResp = $this->actingAs($editor)->get($book->getUrl("/export/zip"));
+        $zip = $this->extractZipResponse($zipResp);
+        $this->assertCount(0, $zip->data['book']['chapters'][0]['pages'] ?? ['cat']);
+
+        $zipResp = $this->actingAs($editor)->get($chapter->getUrl("/export/zip"));
+        $zip = $this->extractZipResponse($zipResp);
+        $this->assertCount(0, $zip->data['chapter']['pages'] ?? ['cat']);
+
+        $page->chapter_id = 0;
+        $page->save();
+
+        $zipResp = $this->actingAs($editor)->get($book->getUrl("/export/zip"));
+        $zip = $this->extractZipResponse($zipResp);
+        $this->assertCount(0, $zip->data['book']['pages'] ?? ['cat']);
+    }
+
 
     public function test_cross_reference_links_are_converted()
     {
Morty Proxy This is a proxified and sanitized view of the page, visit original site.