Fixed gallery images not visible until draft publish

For #4028
This commit is contained in:
Dan Brown 2023-02-16 17:57:34 +00:00
parent f9fcc9f3c7
commit 08b39500b3
No known key found for this signature in database
GPG key ID: 46D9F943C24A2EF9
3 changed files with 29 additions and 0 deletions

View 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);
});
});
}

View 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
*/

View 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();