Skip to content

Commit dd9bdda

Browse files
committed
Improve acl resources for new media gallery
1 parent 771dc31 commit dd9bdda

File tree

17 files changed

+240
-104
lines changed

17 files changed

+240
-104
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
*/
1414
class DeleteFiles extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images implements HttpPostActionInterface
1515
{
16-
/**
17-
* @see _isAllowed()
18-
*/
19-
public const ADMIN_RESOURCE = 'Magento_Cms::delete_assets';
20-
2116
/**
2217
* @var \Magento\Framework\Controller\Result\JsonFactory
2318
*/

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,12 @@
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.
1716
*/
1817
class DeleteFolder extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images implements HttpPostActionInterface
1918
{
20-
/**
21-
* @see _isAllowed()
22-
*/
23-
public const ADMIN_RESOURCE = 'Magento_Cms::delete_folder';
24-
2519
/**
2620
* @var \Magento\Framework\Controller\Result\JsonFactory
2721
*/

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
*/
1515
class NewFolder extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images implements HttpPostActionInterface
1616
{
17-
/**
18-
* @see _isAllowed()
19-
*/
20-
public const ADMIN_RESOURCE = 'Magento_Cms::create_folder';
21-
2217
/**
2318
* @var \Magento\Framework\Controller\Result\JsonFactory
2419
*/

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88

99
class OnInsert extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images
1010
{
11-
/**
12-
* @see _isAllowed()
13-
*/
14-
public const ADMIN_RESOURCE = 'Magento_Cms::insert_assets';
1511

1612
/**
1713
* @var \Magento\Framework\Controller\Result\RawFactory

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
*/
1818
class Upload extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images implements HttpPostActionInterface
1919
{
20-
/**
21-
* @see _isAllowed()
22-
*/
23-
public const ADMIN_RESOURCE = 'Magento_Cms::upload_assets';
24-
2520
/**
2621
* @var \Magento\Framework\Controller\Result\JsonFactory
2722
*/
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
9+
<acl>
10+
<resources>
11+
<resource id="Magento_Backend::admin">
12+
<resource id="Magento_Backend::content">
13+
<resource id="Magento_Backend::content_elements">
14+
<resource id="Magento_Cms::media_gallery" title="Media Gallery" translate="title">
15+
<resource id="Magento_MediaGallery::upload_assets" title="Upload Assets" translate="title" sortOrder="80"/>
16+
<resource id="Magento_MediaGallery::delete_assets" title="Delete Assets" translate="title" sortOrder="70"/>
17+
<resource id="Magento_MediaGallery::insert_assets" title="Insert Assets into the content" translate="title" sortOrder="60"/>
18+
<resource id="Magento_MediaGallery::create_folder" title="Create Folder" translate="title" sortOrder="50"/>
19+
<resource id="Magento_MediaGallery::delete_folder" title="Delete Folder" translate="title" sortOrder="40"/>
20+
</resource>
21+
</resource>
22+
</resource>
23+
</resource>
24+
</resources>
25+
</acl>
26+
</config>

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::create_folder';
32+
public const ADMIN_RESOURCE = 'Magento_MediaGallery::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::delete_folder';
33+
public const ADMIN_RESOURCE = 'Magento_MediaGallery::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::delete_assets';
34+
public const ADMIN_RESOURCE = 'Magento_MediaGallery::delete_assets';
3535

3636
/**
3737
* @var DeleteImage

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::upload_assets';
31+
public const ADMIN_RESOURCE = 'Magento_MediaGallery::upload_assets';
3232

3333
/**
3434
* @var UploadImage
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\MediaGalleryUi\Ui\Component\Control;
7+
8+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
9+
use Magento\Framework\AuthorizationInterface;
10+
11+
/**
12+
* Create Folder button
13+
*/
14+
class CreateFolder implements ButtonProviderInterface
15+
{
16+
private const ACL_CREATE_FOLDER = 'Magento_MediaGallery::create_folder';
17+
18+
/**
19+
* @var AuthorizationInterface
20+
*/
21+
private $authorization;
22+
23+
/**
24+
* Constructor.
25+
*
26+
* @param AuthorizationInterface $authorization
27+
*/
28+
public function __construct(
29+
AuthorizationInterface $authorization
30+
) {
31+
$this->authorization = $authorization;
32+
}
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
public function getButtonData()
38+
{
39+
if (!$this->authorization->isAllowed(self::ACL_CREATE_FOLDER)) {
40+
return [];
41+
}
42+
43+
return [
44+
'label' => __('Create Folder'),
45+
'on_click' => 'jQuery("#create_folder").trigger("create_folder");',
46+
'class' => 'action-default scalable add media-gallery-actions-buttons',
47+
'sort_order' => 10,
48+
];
49+
}
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\MediaGalleryUi\Ui\Component\Control;
7+
8+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
9+
use Magento\Framework\AuthorizationInterface;
10+
11+
/**
12+
* Delete images button
13+
*/
14+
class DeleteAssets implements ButtonProviderInterface
15+
{
16+
private const ACL_DELETE_ASSETS= 'Magento_MediaGallery::delete_assets';
17+
18+
/**
19+
* @var AuthorizationInterface
20+
*/
21+
private $authorization;
22+
23+
/**
24+
* Constructor.
25+
*
26+
* @param AuthorizationInterface $authorization
27+
*/
28+
public function __construct(
29+
AuthorizationInterface $authorization
30+
) {
31+
$this->authorization = $authorization;
32+
}
33+
34+
/**
35+
* @return array
36+
*/
37+
public function getButtonData()
38+
{
39+
if (!$this->authorization->isAllowed(self::ACL_DELETE_ASSETS)) {
40+
return [];
41+
}
42+
43+
return [
44+
'label' => __('Delete Images...'),
45+
'on_click' => 'jQuery(window).trigger("massAction.MediaGallery")',
46+
'class' => 'action-default scalable add media-gallery-actions-buttons',
47+
'sort_order' => 50,
48+
];
49+
}
50+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\MediaGalleryUi\Ui\Component\Control;
7+
8+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
9+
use Magento\Framework\AuthorizationInterface;
10+
11+
/**
12+
* Delete Folder button
13+
*/
14+
class DeleteFolder implements ButtonProviderInterface
15+
{
16+
private const ACL_DELETE_FOLDER = 'Magento_MediaGallery::delete_folder';
17+
18+
/**
19+
* @var AuthorizationInterface
20+
*/
21+
private $authorization;
22+
23+
/**
24+
* Constructor.
25+
*
26+
* @param AuthorizationInterface $authorization
27+
*/
28+
public function __construct(
29+
AuthorizationInterface $authorization
30+
) {
31+
$this->authorization = $authorization;
32+
}
33+
34+
/**
35+
* @return array
36+
*/
37+
public function getButtonData()
38+
{
39+
if (!$this->authorization->isAllowed(self::ACL_DELETE_FOLDER)) {
40+
return [];
41+
}
42+
43+
return [
44+
'label' => __('Delete Folder'),
45+
'disabled' => 'disabled',
46+
'on_click' => 'jQuery("#delete_folder").trigger("delete_folder");',
47+
'class' => 'action-default scalable add media-gallery-actions-buttons',
48+
'sort_order' => 30,
49+
];
50+
}
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\MediaGalleryUi\Ui\Component\Control;
7+
8+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
9+
use Magento\Framework\AuthorizationInterface;
10+
11+
/**
12+
* Upload Image button
13+
*/
14+
class UploadAssets implements ButtonProviderInterface
15+
{
16+
private const ACL_UPLOAD_ASSETS= 'Magento_MediaGallery::upload_assets';
17+
18+
/**
19+
* @var AuthorizationInterface
20+
*/
21+
private $authorization;
22+
23+
/**
24+
* Constructor.
25+
*
26+
* @param AuthorizationInterface $authorization
27+
*/
28+
public function __construct(
29+
AuthorizationInterface $authorization
30+
) {
31+
$this->authorization = $authorization;
32+
}
33+
34+
/**
35+
* @return array
36+
*/
37+
public function getButtonData()
38+
{
39+
if (!$this->authorization->isAllowed(self::ACL_UPLOAD_ASSETS)) {
40+
return [];
41+
}
42+
43+
return [
44+
'label' => __('Upload Image'),
45+
'disabled' => 'disabled',
46+
'on_click' => 'jQuery("#image-uploader-input").click();',
47+
'class' => 'action-default scalable add media-gallery-actions-buttons',
48+
'sort_order' => 20,
49+
];
50+
}
51+
}

app/code/Magento/MediaGalleryUi/etc/acl.xml

Lines changed: 0 additions & 26 deletions
This file was deleted.

app/code/Magento/MediaGalleryUi/view/adminhtml/ui_component/media_gallery_listing.xml

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,10 @@
2828
<class>cancel action-quaternary</class>
2929
<label translate="true">Cancel</label>
3030
</button>
31-
<button name="upload_image">
32-
<param name="on_click" xsi:type="string">jQuery('#image-uploader-input').click();</param>
33-
<class>action-add scalable media-gallery-actions-buttons</class>
34-
<param name="sort_order" xsi:type="number">20</param>
35-
<label translate="true">Upload Image</label>
36-
</button>
37-
<button name="delete_folder">
38-
<param name="on_click" xsi:type="string">jQuery('#delete_folder').trigger('delete_folder');</param>
39-
<param name="disabled" xsi:type="string">disabled</param>
40-
<param name="sort_order" xsi:type="number">30</param>
41-
<class>action-default scalable media-gallery-actions-buttons</class>
42-
<label translate="true">Delete Folder</label>
43-
</button>
44-
<button name="create_folder">
45-
<param name="on_click" xsi:type="string">jQuery('#create_folder').trigger('create_folder');</param>
46-
<param name="sort_order" xsi:type="number">10</param>
47-
<class>action-default scalable add media-gallery-actions-buttons</class>
48-
<label translate="true">Create Folder</label>
49-
</button>
50-
<button name="delete_massaction">
51-
<param name="on_click" xsi:type="string">jQuery(window).trigger('massAction.MediaGallery')</param>
52-
<param name="sort_order" xsi:type="number">50</param>
53-
<class>action-default scalable add media-gallery-actions-buttons</class>
54-
<label translate="true">Delete Images...</label>
55-
</button>
31+
<button name="upload_image" class="Magento\MediaGalleryUi\Ui\Component\Control\UploadAssets"/>
32+
<button name="delete_folder" class="Magento\MediaGalleryUi\Ui\Component\Control\DeleteFolder"/>
33+
<button name="create_folder" class="Magento\MediaGalleryUi\Ui\Component\Control\CreateFolder"/>
34+
<button name="delete_massaction" class="Magento\MediaGalleryUi\Ui\Component\Control\DeleteAssets"/>
5635
</buttons>
5736
<spinner>media_gallery_columns</spinner>
5837
<deps>

0 commit comments

Comments
 (0)