Skip to content

Commit e9e7bed

Browse files
ENGCOM-8057: [WIP] Introduce granulated Media Gallery ACL resources and enforce for old media gallery #29715
- Merge Pull Request #29715 from Nazar65/magento2:ASI-1487 - Merged commits: 1. 771dc31 2. dd9bdda 3. 989139f 4. 239314d 5. eaa20f2 6. 8cdcefd 7. 43fd057 8. dfa67b0 9. 8ef07f4 10. 3af8416 11. 7940f59 12. e690a8d 13. 4c085d7 14. 0e28c91 15. 80dae45 16. 67636e7 17. 739e6dc 18. 68bc010 19. 0ad0630 20. 9ccfdc9 21. 7b58d97 22. 90c9dac 23. 88a0150 24. 748eb4f 25. b3d5255 26. 0a6156f 27. 253bafb 28. 2448fd8 29. cf288e6 30. 7296cdf
2 parents 1dc62a7 + 7296cdf commit e9e7bed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1132
-138
lines changed

app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/DeleteFolder.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
1111

1212
use Magento\Framework\App\Action\HttpPostActionInterface;
13-
use Magento\Framework\App\Filesystem\DirectoryList;
1413

1514
/**
1615
* Delete image folder.

app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/NewFolder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function execute()
6565
}
6666
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
6767
$resultJson = $this->resultJsonFactory->create();
68-
68+
6969
return $resultJson->setData($result);
7070
}
7171
}

app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/Upload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function execute()
7474
}
7575
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
7676
$resultJson = $this->resultJsonFactory->create();
77-
77+
7878
return $resultJson->setData($response);
7979
}
8080
}

app/code/Magento/MediaGalleryCmsUi/Test/Mftf/Test/AdminMediaGalleryAssertUsedInLinkPagesGridTest.xml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
<before>
2222
<actionGroup ref="AdminLoginActionGroup" stepKey="login"/>
2323
</before>
24-
<after>
25-
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetAdminDataGridToDefaultView"/>
26-
</after>
27-
2824
<actionGroup ref="AdminOpenCreateNewCMSPageActionGroup" stepKey="navigateToCreateNewPage"/>
2925
<actionGroup ref="FillOutCustomCMSPageContentActionGroup" stepKey="fillBasicPageDataForPageWithDefaultStore">
3026
<argument name="title" value="Unique page title MediaGalleryUi"/>
@@ -37,9 +33,13 @@
3733
<actionGroup ref="AdminEnhancedMediaGalleryUploadImageActionGroup" stepKey="uploadImage">
3834
<argument name="image" value="ImageUpload3"/>
3935
</actionGroup>
40-
<actionGroup ref="AdminMediaGalleryClickImageInGridActionGroup" stepKey="selectContentImageInGrid">
41-
<argument name="imageName" value="{{ImageMetadata.title}}"/>
36+
<actionGroup ref="AdminEnhancedMediaGalleryViewImageDetails" stepKey="viewImageDetails"/>
37+
<actionGroup ref="AdminEnhancedMediaGalleryImageDetailsEditActionGroup" stepKey="editImage"/>
38+
<actionGroup ref="AdminEnhancedMediaGalleryImageDetailsSaveActionGroup" stepKey="saveImage">
39+
<argument name="image" value="UpdatedImageDetails"/>
4240
</actionGroup>
41+
<actionGroup ref="AdminEnhancedMediaGalleryCloseViewDetailsActionGroup" stepKey="closeViewDetails"/>
42+
4343
<actionGroup ref="AdminMediaGalleryClickAddSelectedActionGroup" stepKey="clickAddSelectedContentImage"/>
4444
<click selector="{{CmsNewPagePageActionsSection.saveAndContinueEdit}}" stepKey="savePage"/>
4545
<actionGroup ref="AdminOpenStandaloneMediaGalleryActionGroup" stepKey="openStandaloneMediaGallery"/>
@@ -48,21 +48,19 @@
4848
<argument name="entityName" value="Pages"/>
4949
</actionGroup>
5050
<actionGroup ref="AdminAssertMediaGalleryFilterPlaceHolderGridActionGroup" stepKey="assertFilterApplied">
51-
<argument name="filterPlaceholder" value="{{ImageMetadata.title}}"/>
51+
<argument name="filterPlaceholder" value="{{UpdatedImageDetails.title}}"/>
5252
</actionGroup>
53-
5453
<actionGroup ref="AdminDeleteCmsPageFromGridActionGroup" stepKey="deleteCmsPage">
5554
<argument name="urlKey" value="test-page-1"/>
5655
</actionGroup>
57-
5856
<actionGroup ref="AdminOpenStandaloneMediaGalleryActionGroup" stepKey="openMediaGallery"/>
5957
<actionGroup ref="AdminEnhancedMediaGalleryViewImageDetails" stepKey="openViewImageDetailsToVerfifyEmptyUsedIn"/>
6058
<actionGroup ref="AssertAdminEnhancedMediaGalleryUsedInSectionNotDisplayedActionGroup" stepKey="assertThereIsNoUsedInSection"/>
6159
<actionGroup ref="AdminEnhancedMediaGalleryCloseViewDetailsActionGroup" stepKey="closeDetails"/>
6260

6361
<actionGroup ref="AdminEnhancedMediaGalleryEnableMassActionModeActionGroup" stepKey="enableMassActionToDeleteImages"/>
6462
<actionGroup ref="AdminEnhancedMediaGallerySelectImageForMassActionActionGroup" stepKey="selectFirstImageToDelete">
65-
<argument name="imageName" value="{{ImageMetadata.title}}"/>
63+
<argument name="imageName" value="{{UpdatedImageDetails.title}}"/>
6664
</actionGroup>
6765
<actionGroup ref="AdminEnhancedMediaGalleryClickDeleteImagesButtonActionGroup" stepKey="clikDeleteSelectedButton"/>
6866
<actionGroup ref="AdminEnhancedMediaGalleryConfirmDeleteImagesActionGroup" stepKey="deleteImages"/>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MediaGalleryUi\Block\Adminhtml;
9+
10+
use Magento\Backend\Block\Template;
11+
use Magento\Directory\Helper\Data as DirectoryHelper;
12+
use Magento\Framework\AuthorizationInterface;
13+
use Magento\Framework\Json\Helper\Data as JsonHelper;
14+
use Magento\Framework\Serialize\Serializer\Json;
15+
16+
/**
17+
* Image details block
18+
*
19+
* @api
20+
*/
21+
class ImageDetails extends Template
22+
{
23+
/**
24+
* @var AuthorizationInterface
25+
*/
26+
private $authorization;
27+
28+
/**
29+
* @var Json
30+
*/
31+
private $json;
32+
33+
/**
34+
* @param Template\Context $context
35+
* @param AuthorizationInterface $authorization
36+
* @param Json $json
37+
* @param array $data
38+
* @param JsonHelper|null $jsonHelper
39+
* @param DirectoryHelper|null $directoryHelper
40+
*/
41+
public function __construct(
42+
Template\Context $context,
43+
AuthorizationInterface $authorization,
44+
Json $json,
45+
array $data = [],
46+
?JsonHelper $jsonHelper = null,
47+
?DirectoryHelper $directoryHelper = null
48+
) {
49+
$this->authorization = $authorization;
50+
$this->json = $json;
51+
parent::__construct($context, $data, $jsonHelper, $directoryHelper);
52+
}
53+
54+
/**
55+
* Retrieve actions json
56+
*
57+
* @return string
58+
*/
59+
public function getActionsJson(): string
60+
{
61+
$actions = [
62+
[
63+
'title' => __('Cancel'),
64+
'handler' => 'closeModal',
65+
'name' => 'cancel',
66+
'classes' => 'action-default scalable cancel action-quaternary'
67+
]
68+
];
69+
70+
if ($this->authorization->isAllowed('Magento_MediaGalleryUiApi::delete_assets')) {
71+
$actions[] = [
72+
'title' => __('Delete Image'),
73+
'handler' => 'deleteImageAction',
74+
'name' => 'delete',
75+
'classes' => 'action-default scalable delete action-quaternary'
76+
];
77+
}
78+
79+
if ($this->authorization->isAllowed('Magento_MediaGalleryUiApi::edit_assets')) {
80+
$actions[] = [
81+
'title' => __('Edit Details'),
82+
'handler' => 'editImageAction',
83+
'name' => 'edit',
84+
'classes' => 'action-default scalable edit action-quaternary'
85+
];
86+
}
87+
88+
if ($this->authorization->isAllowed('Magento_MediaGalleryUiApi::insert_assets')) {
89+
$actions[] = [
90+
'title' => __('Add Image'),
91+
'handler' => 'addImage',
92+
'name' => 'add-image',
93+
'classes' => 'scalable action-primary add-image-action'
94+
];
95+
}
96+
97+
return $this->json->serialize($actions);
98+
}
99+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MediaGalleryUi\Block\Adminhtml;
9+
10+
use Magento\Backend\Block\Template;
11+
use Magento\Directory\Helper\Data as DirectoryHelperData;
12+
use Magento\Framework\AuthorizationInterface;
13+
use Magento\Framework\Json\Helper\Data as JsonHelperData;
14+
use Magento\Framework\Serialize\Serializer\Json;
15+
16+
/**
17+
* Image details block
18+
*
19+
* @api
20+
*/
21+
class ImageDetailsStandalone extends Template
22+
{
23+
/**
24+
* @var AuthorizationInterface
25+
*/
26+
private $authorization;
27+
28+
/**
29+
* @var Json
30+
*/
31+
private $json;
32+
33+
/**
34+
* @param Template\Context $context
35+
* @param AuthorizationInterface $authorization
36+
* @param Json $json
37+
* @param array $data
38+
* @param JsonHelperData|null $jsonHelper
39+
* @param DirectoryHelperData|null $directoryHelper
40+
*/
41+
public function __construct(
42+
Template\Context $context,
43+
AuthorizationInterface $authorization,
44+
Json $json,
45+
array $data = [],
46+
?JsonHelperData $jsonHelper = null,
47+
?DirectoryHelperData $directoryHelper = null
48+
) {
49+
$this->authorization = $authorization;
50+
$this->json = $json;
51+
parent::__construct($context, $data, $jsonHelper, $directoryHelper);
52+
}
53+
54+
/**
55+
* Retrieve actions json
56+
*
57+
* @return string
58+
*/
59+
public function getActionsJson(): string
60+
{
61+
$standaloneActions = [
62+
[
63+
'title' => __('Cancel'),
64+
'handler' => 'closeModal',
65+
'name' => 'cancel',
66+
'classes' => 'action-default scalable cancel action-quaternary'
67+
]
68+
];
69+
70+
if ($this->authorization->isAllowed('Magento_MediaGalleryUiApi::delete_assets')) {
71+
$standaloneActions[] = [
72+
'title' => __('Delete Image'),
73+
'handler' => 'deleteImageAction',
74+
'name' => 'delete',
75+
'classes' => 'action-default scalable delete action-quaternary'
76+
];
77+
}
78+
79+
if ($this->authorization->isAllowed('Magento_MediaGalleryUiApi::edit_assets')) {
80+
$standaloneActions[] = [
81+
'title' => __('Edit Details'),
82+
'handler' => 'editImageAction',
83+
'name' => 'edit',
84+
'classes' => 'action-default scalable edit action-quaternary'
85+
];
86+
}
87+
88+
return $this->json->serialize($standaloneActions);
89+
}
90+
}

app/code/Magento/MediaGalleryUi/Controller/Adminhtml/Directories/Create.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Create extends Action implements HttpPostActionInterface
2929
/**
3030
* @see _isAllowed()
3131
*/
32-
public const ADMIN_RESOURCE = 'Magento_Cms::media_gallery';
32+
public const ADMIN_RESOURCE = 'Magento_MediaGalleryUiApi::create_folder';
3333

3434
/**
3535
* @var CreateDirectoriesByPathsInterface

app/code/Magento/MediaGalleryUi/Controller/Adminhtml/Directories/Delete.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Delete extends Action implements HttpPostActionInterface
3030
/**
3131
* @see _isAllowed()
3232
*/
33-
public const ADMIN_RESOURCE = 'Magento_Cms::media_gallery';
33+
public const ADMIN_RESOURCE = 'Magento_MediaGalleryUiApi::delete_folder';
3434

3535
/**
3636
* @var DeleteAssetsByPathsInterface

app/code/Magento/MediaGalleryUi/Controller/Adminhtml/Image/Delete.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Delete extends Action implements HttpPostActionInterface
3131
/**
3232
* @see _isAllowed()
3333
*/
34-
public const ADMIN_RESOURCE = 'Magento_Cms::media_gallery';
34+
public const ADMIN_RESOURCE = 'Magento_MediaGalleryUiApi::delete_assets';
3535

3636
/**
3737
* @var DeleteImage

app/code/Magento/MediaGalleryUi/Controller/Adminhtml/Image/SaveDetails.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class SaveDetails extends Action implements HttpPostActionInterface
3232
/**
3333
* @see _isAllowed()
3434
*/
35-
public const ADMIN_RESOURCE = 'Magento_Cms::media_gallery';
35+
public const ADMIN_RESOURCE = 'Magento_MediaGalleryUiApi::edit_assets';
3636

3737
/**
3838
* @var UpdateAsset

app/code/Magento/MediaGalleryUi/Controller/Adminhtml/Image/Upload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Upload extends Action implements HttpPostActionInterface
2828
/**
2929
* @see _isAllowed()
3030
*/
31-
public const ADMIN_RESOURCE = 'Magento_Cms::media_gallery';
31+
public const ADMIN_RESOURCE = 'Magento_MediaGalleryUiApi::upload_assets';
3232

3333
/**
3434
* @var UploadImage

0 commit comments

Comments
 (0)