-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve buttons visibility per user permission
- Loading branch information
Showing
5 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
app/code/Magento/MediaGalleryUi/Ui/Component/Listing/Massactions/Massaction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\MediaGalleryUi\Ui\Component\Listing\Massactions; | ||
|
||
use Magento\Ui\Component\Container; | ||
use Magento\Framework\View\Element\UiComponent\ContextInterface; | ||
use Magento\Framework\AuthorizationInterface; | ||
|
||
/** | ||
* Massaction comntainer | ||
*/ | ||
class Massaction extends Container | ||
{ | ||
private const ACL_IMAGE_ACTIONS = [ | ||
'delete_assets' => 'Magento_MediaGallery::delete_assets' | ||
]; | ||
|
||
/** | ||
* @var AuthorizationInterface | ||
*/ | ||
private $authorization; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param ContextInterface $context | ||
* @param AuthorizationInterface $authorization | ||
* @param array $components | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
ContextInterface $context, | ||
AuthorizationInterface $authorization, | ||
array $components = [], | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $components, $data); | ||
$this->authorization = $authorization; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function prepare(): void | ||
{ | ||
parent::prepare(); | ||
$this->setData( | ||
'config', | ||
array_replace_recursive( | ||
(array)$this->getData('config'), | ||
[ | ||
'allowedActions' => $this->getAllowedActions() | ||
] | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Return allowed actions for media gallery | ||
*/ | ||
private function getAllowedActions(): array | ||
{ | ||
$allowedActions = []; | ||
foreach (self::ACL_IMAGE_ACTIONS as $key => $action) { | ||
if ($this->authorization->isAllowed($action)) { | ||
$allowedActions[] = $key; | ||
} | ||
} | ||
|
||
return $allowedActions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters