Skip to content

Commit

Permalink
Fixed gallery images not visible until draft publish
Browse files Browse the repository at this point in the history
For #4028
  • Loading branch information
ssddanbrown committed Feb 16, 2023
1 parent f9fcc9f commit 08b3950
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/Auth/Permissions/PermissionApplicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ public function restrictPageRelationQuery(Builder $query, string $tableName, str
$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);
});
});
}
Expand Down
13 changes: 13 additions & 0 deletions tests/Helpers/EntityProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ public function newPage(array $input = ['name' => 'test page', 'html' => 'My new
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
*/
Expand Down
11 changes: 11 additions & 0 deletions tests/Uploads/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ public function test_gallery_get_list_format()
$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();
Expand Down

0 comments on commit 08b3950

Please sign in to comment.