]> BookStack Code Mirror - bookstack/commitdiff
Fixed gallery images not visible until draft publish
authorDan Brown <redacted>
Thu, 16 Feb 2023 17:57:34 +0000 (17:57 +0000)
committerDan Brown <redacted>
Thu, 16 Feb 2023 17:57:34 +0000 (17:57 +0000)
For #4028

app/Auth/Permissions/PermissionApplicator.php
tests/Helpers/EntityProvider.php
tests/Uploads/ImageTest.php

index 20cc87e48a65177d3d1eea9b48dc2eff60fd20f5..84ac27f875ce2c0a632a346592feb0340718c69d 100644 (file)
@@ -158,6 +158,11 @@ class PermissionApplicator
                     $query->select('id')->from('pages')
                         ->whereColumn('pages.id', '=', $fullPageIdColumn)
                         ->where('pages.draft', '=', false);
+                })->orWhereExists(function (QueryBuilder $query) use ($fullPageIdColumn) {
+                    $query->select('id')->from('pages')
+                        ->whereColumn('pages.id', '=', $fullPageIdColumn)
+                        ->where('pages.draft', '=', true)
+                        ->where('pages.created_by', '=', $this->currentUser()->id);
                 });
             });
     }
index d79015f75537deade2443f57a7018d6972139f46..8b045db54a2f13eaf312e01e8074788bc41dfae8 100644 (file)
@@ -184,6 +184,19 @@ class EntityProvider
         return $pageRepo->publishDraft($draftPage, $input);
     }
 
+    /**
+     * Create and return a new test draft page.
+     */
+    public function newDraftPage(array $input = ['name' => 'test page', 'html' => 'My new test page']): Page
+    {
+        $book = $this->book();
+        $pageRepo = app(PageRepo::class);
+        $draftPage = $pageRepo->getNewDraftPage($book);
+        $pageRepo->updatePageDraft($draftPage, $input);
+        $this->addToCache($draftPage);
+        return $draftPage;
+    }
+
     /**
      * @param Entity|Entity[] $entities
      */
index fb98565fc3d8a0774167703b097b5f26d2973f67..53040ea086b00edc218f3cbb072c27d321dfbc87 100644 (file)
@@ -120,6 +120,17 @@ class ImageTest extends TestCase
         $this->withHtml($searchFailRequest)->assertElementNotExists('div');
     }
 
+    public function test_image_gallery_lists_for_draft_page()
+    {
+        $this->actingAs($this->users->editor());
+        $draft = $this->entities->newDraftPage();
+        $this->files->uploadGalleryImageToPage($this, $draft);
+        $image = Image::query()->where('uploaded_to', '=', $draft->id)->firstOrFail();
+
+        $resp = $this->get("/images/gallery?page=1&uploaded_to={$draft->id}");
+        $resp->assertSee($image->getThumb(150, 150));
+    }
+
     public function test_image_usage()
     {
         $page = $this->entities->page();