Skip to content

Commit eb09b10

Browse files
committed
ACP2E-1878: Website limited Administrator can't add Image to the product.
- fix - add test
1 parent 5676386 commit eb09b10

File tree

5 files changed

+50
-18
lines changed

5 files changed

+50
-18
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Gallery/Content.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
namespace Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery;
1515

16+
use Magento\Catalog\Helper\Image;
1617
use Magento\Framework\App\ObjectManager;
1718
use Magento\Backend\Block\Media\Uploader;
1819
use Magento\Framework\Json\Helper\Data as JsonHelper;
@@ -45,7 +46,7 @@ class Content extends \Magento\Backend\Block\Widget
4546
protected $_jsonEncoder;
4647

4748
/**
48-
* @var \Magento\Catalog\Helper\Image
49+
* @var Image
4950
*/
5051
private $imageHelper;
5152

@@ -67,6 +68,7 @@ class Content extends \Magento\Backend\Block\Widget
6768
* @param ImageUploadConfigDataProvider $imageUploadConfigDataProvider
6869
* @param Database $fileStorageDatabase
6970
* @param JsonHelper|null $jsonHelper
71+
* @param Image|null $imageHelper
7072
*/
7173
public function __construct(
7274
\Magento\Backend\Block\Template\Context $context,
@@ -75,7 +77,8 @@ public function __construct(
7577
array $data = [],
7678
ImageUploadConfigDataProvider $imageUploadConfigDataProvider = null,
7779
Database $fileStorageDatabase = null,
78-
?JsonHelper $jsonHelper = null
80+
?JsonHelper $jsonHelper = null,
81+
?Image $imageHelper = null
7982
) {
8083
$this->_jsonEncoder = $jsonEncoder;
8184
$this->_mediaConfig = $mediaConfig;
@@ -85,6 +88,7 @@ public function __construct(
8588
?: ObjectManager::getInstance()->get(ImageUploadConfigDataProvider::class);
8689
$this->fileStorageDatabase = $fileStorageDatabase
8790
?: ObjectManager::getInstance()->get(Database::class);
91+
$this->imageHelper = $imageHelper ?: ObjectManager::getInstance()->get(Image::class);
8892
}
8993

9094
/**
@@ -191,7 +195,7 @@ public function getImagesJson()
191195
$fileHandler = $mediaDir->stat($this->_mediaConfig->getMediaPath($image['file']));
192196
$image['size'] = $fileHandler['size'];
193197
} catch (FileSystemException $e) {
194-
$image['url'] = $this->getImageHelper()->getDefaultPlaceholderUrl('small_image');
198+
$image['url'] = $this->imageHelper->getDefaultPlaceholderUrl('small_image');
195199
$image['size'] = 0;
196200
$this->_logger->warning($e);
197201
}
@@ -304,17 +308,14 @@ public function getImageTypesJson()
304308
}
305309

306310
/**
307-
* Returns image helper object.
311+
* Flag if gallery content editing is enabled.
308312
*
309-
* @return \Magento\Catalog\Helper\Image
310-
* @deprecated 101.0.3
313+
* Is enabled by default, exposed to interceptors to add custom logic
314+
*
315+
* @return bool
311316
*/
312-
private function getImageHelper()
317+
public function isEditEnabled() : bool
313318
{
314-
if ($this->imageHelper === null) {
315-
$this->imageHelper = \Magento\Framework\App\ObjectManager::getInstance()
316-
->get(\Magento\Catalog\Helper\Image::class);
317-
}
318-
return $this->imageHelper;
319+
return true;
319320
}
320321
}

app/code/Magento/Catalog/i18n/en_US.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,4 +819,4 @@ Details,Details
819819
"Failed to retrieve product links for ""%1""","Failed to retrieve product links for ""%1"""
820820
"The linked product SKU is invalid. Verify the data and try again.","The linked product SKU is invalid. Verify the data and try again."
821821
"The linked products data is invalid. Verify the data and try again.","The linked products data is invalid. Verify the data and try again."
822-
822+
"Restricted admin is allowed to perform actions with images or videos, only when the admin has rights to all websites which the product is assigned to.","Restricted admin is allowed to perform actions with images or videos, only when the admin has rights to all websites which the product is assigned to."

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/helper/gallery.phtml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,29 @@
99
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
1010
$elementName = $block->getElement()->getName() . '[images]';
1111
$formName = $block->getFormName();
12+
$isEditEnabled = $block->isEditEnabled();
13+
1214
/** @var \Magento\Framework\Json\Helper\Data $jsonHelper */
1315
$jsonHelper = $block->getData('jsonHelper');
16+
17+
$message = 'Restricted admin is allowed to perform actions with images or videos, ' .
18+
'only when the admin has rights to all websites which the product is assigned to.';
1419
?>
20+
21+
<div class="row">
22+
<?php if (!$isEditEnabled): ?>
23+
<span> <?= /* @noEscape */ $message ?></span>
24+
<?php endif; ?>
25+
</div>
26+
1527
<div id="<?= $block->getHtmlId() ?>"
16-
class="gallery"
28+
class="gallery <?= $isEditEnabled ? '' : ' disabled' ?>"
1729
data-mage-init='{"productGallery":{"template":"#<?= $block->getHtmlId() ?>-template"}}'
1830
data-parent-component="<?= $block->escapeHtml($block->getData('config/parentComponent')) ?>"
1931
data-images="<?= $block->escapeHtml($block->getImagesJson()) ?>"
2032
data-types="<?= $block->escapeHtml($jsonHelper->jsonEncode($block->getImageTypes())) ?>"
2133
>
22-
<?php if (!$block->getElement()->getReadonly()) {?>
34+
<?php if (!$block->getElement()->getReadonly() && $isEditEnabled) {?>
2335
<div class="image image-placeholder">
2436
<?= $block->getUploaderHtml() ?>
2537
<div class="product-image-wrapper">

app/code/Magento/ProductVideo/view/adminhtml/templates/helper/gallery.phtml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,28 @@
1111
*/
1212
$elementNameEscaped = $block->escapeHtmlAttr($block->getElement()->getName()) . '[images]';
1313
$formNameEscaped = $block->escapeHtmlAttr($block->getFormName());
14+
$isEditEnabled = $block->isEditEnabled();
1415

1516
/** @var \Magento\Framework\Json\Helper\Data $jsonHelper */
1617
$jsonHelper = $block->getData('jsonHelper');
18+
19+
$message = 'Restricted admin is allowed to perform actions with images or videos, ' .
20+
'only when the admin has rights to all websites which the product is assigned to.';
1721
?>
1822

1923
<div class="row">
24+
<?php if (!$isEditEnabled): ?>
25+
<span> <?= /* @noEscape */ $message ?></span>
26+
<?php endif; ?>
2027
<div class="add-video-button-container">
2128
<button id="add_video_button"
2229
title="<?= $block->escapeHtmlAttr(__('Add Video')) ?>"
2330
data-role="add-video-button"
2431
type="button"
2532
class="action-secondary"
26-
data-ui-id="widget-button-1">
33+
data-ui-id="widget-button-1"
34+
<?= ($block->isEditEnabled()) ? '' : 'disabled="disabled"' ?>
35+
>
2736
<span><?= $block->escapeHtml(__('Add Video')) ?></span>
2837
</button>
2938
</div>
@@ -36,13 +45,13 @@ $elementToggleCode = $element->getToggleCode() ? $element->getToggleCode():
3645
'toggleValueElements(this, this.parentNode.parentNode.parentNode)';
3746
?>
3847
<div id="<?= $block->escapeHtmlAttr($block->getHtmlId()) ?>"
39-
class="gallery"
48+
class="gallery <?= $isEditEnabled ? '' : ' disabled' ?>"
4049
data-mage-init='{"openVideoModal":{}}'
4150
data-parent-component="<?= $block->escapeHtml($block->getData('config/parentComponent')) ?>"
4251
data-images="<?= $block->escapeHtmlAttr($block->getImagesJson()) ?>"
4352
data-types='<?= /* @noEscape */ $jsonHelper->jsonEncode($block->getImageTypes()) ?>'
4453
>
45-
<?php if (!$block->getElement()->getReadonly()): ?>
54+
<?php if (!$block->getElement()->getReadonly() && $isEditEnabled): ?>
4655
<div class="image image-placeholder">
4756
<?= $block->getUploaderHtml(); ?>
4857
<div class="product-image-wrapper">

app/design/adminhtml/Magento/backend/web/css/source/components/_media-gallery.less

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
.gallery {
3838
&:extend(.abs-clearfix all);
3939
overflow: hidden;
40+
41+
&.disabled {
42+
.tooltip {
43+
display: none;
44+
}
45+
}
4046
}
4147

4248
.image {
@@ -84,13 +90,17 @@
8490
height: @image-gallery-placeholder__height;
8591

8692
.product-image-wrapper {
93+
/**
94+
* @codingStandardsIgnoreStart
95+
*/
8796
.lib-icon-font(
8897
@icon-camera__content,
8998
@_icon-font: @icons-admin__font-name,
9099
@_icon-font-size: @image-gallery-placeholder-icon__size,
91100
@_icon-font-color: @image-gallery-placeholder-icon__color,
92101
@_icon-font-text-hide: true
93102
);
103+
//@codingStandardsIgnoreEnd
94104

95105
&:before {
96106
left: 0;

0 commit comments

Comments
 (0)