Added permission visiblity control to image-delete button
Includes test to cover. For #3697
This commit is contained in:
parent
b698bb0e07
commit
fbef0d06f2
|
@ -14,12 +14,9 @@ use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class ImageController extends Controller
|
class ImageController extends Controller
|
||||||
{
|
{
|
||||||
protected $imageRepo;
|
protected ImageRepo $imageRepo;
|
||||||
protected $imageService;
|
protected ImageService $imageService;
|
||||||
|
|
||||||
/**
|
|
||||||
* ImageController constructor.
|
|
||||||
*/
|
|
||||||
public function __construct(ImageRepo $imageRepo, ImageService $imageService)
|
public function __construct(ImageRepo $imageRepo, ImageService $imageService)
|
||||||
{
|
{
|
||||||
$this->imageRepo = $imageRepo;
|
$this->imageRepo = $imageRepo;
|
||||||
|
|
|
@ -20,10 +20,12 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="grid half">
|
<div class="grid half">
|
||||||
<div>
|
<div>
|
||||||
|
@if(userCan('image-delete', $image))
|
||||||
<button type="button"
|
<button type="button"
|
||||||
id="image-manager-delete"
|
id="image-manager-delete"
|
||||||
title="{{ trans('common.delete') }}"
|
title="{{ trans('common.delete') }}"
|
||||||
class="button icon outline">@icon('delete')</button>
|
class="button icon outline">@icon('delete')</button>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="text-right">
|
<div class="text-right">
|
||||||
<button type="submit"
|
<button type="submit"
|
||||||
|
|
|
@ -457,6 +457,32 @@ class ImageTest extends TestCase
|
||||||
$this->assertFalse(file_exists(public_path($relPath)), 'Uploaded image has not been deleted as expected');
|
$this->assertFalse(file_exists(public_path($relPath)), 'Uploaded image has not been deleted as expected');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_image_manager_delete_button_only_shows_with_permission()
|
||||||
|
{
|
||||||
|
$page = Page::query()->first();
|
||||||
|
$this->asAdmin();
|
||||||
|
$imageName = 'first-image.png';
|
||||||
|
$relPath = $this->getTestImagePath('gallery', $imageName);
|
||||||
|
$this->deleteImage($relPath);
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
|
$this->uploadImage($imageName, $page->id);
|
||||||
|
$image = Image::first();
|
||||||
|
|
||||||
|
$resp = $this->get("/images/edit/{$image->id}");
|
||||||
|
$this->withHtml($resp)->assertElementExists('button#image-manager-delete[title="Delete"]');
|
||||||
|
|
||||||
|
$resp = $this->actingAs($viewer)->get("/images/edit/{$image->id}");
|
||||||
|
$this->withHtml($resp)->assertElementNotExists('button#image-manager-delete[title="Delete"]');
|
||||||
|
|
||||||
|
$this->giveUserPermissions($viewer, ['image-delete-all']);
|
||||||
|
|
||||||
|
$resp = $this->actingAs($viewer)->get("/images/edit/{$image->id}");
|
||||||
|
$this->withHtml($resp)->assertElementExists('button#image-manager-delete[title="Delete"]');
|
||||||
|
|
||||||
|
$this->deleteImage($relPath);
|
||||||
|
}
|
||||||
|
|
||||||
protected function getTestProfileImage()
|
protected function getTestProfileImage()
|
||||||
{
|
{
|
||||||
$imageName = 'profile.png';
|
$imageName = 'profile.png';
|
||||||
|
|
Loading…
Reference in New Issue