Skip to content

Bulk ACL Admin Ui #30806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@
*/
namespace Magento\AsynchronousOperations\Controller\Adminhtml\Bulk;

use Magento\AsynchronousOperations\Model\AccessValidator;
use Magento\AsynchronousOperations\Model\IsAllowedForBulkUuid;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\View\Result\Page;
use Magento\Framework\View\Result\PageFactory;

/**
* Class View Operation Details Controller
*/
class Details extends \Magento\Backend\App\Action implements \Magento\Framework\App\Action\HttpGetActionInterface
class Details extends Action implements HttpGetActionInterface
{
/**
* @var \Magento\Framework\View\Result\PageFactory
* @var PageFactory
*/
private $resultPageFactory;

/**
* @var \Magento\AsynchronousOperations\Model\AccessValidator
* @var AccessValidator
* @deprecated
*/
private $accessValidator;

Expand All @@ -26,21 +36,29 @@ class Details extends \Magento\Backend\App\Action implements \Magento\Framework\
private $menuId;

/**
* Details constructor.
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Magento\AsynchronousOperations\Model\AccessValidator $accessValidator
* @var IsAllowedForBulkUuid
*/
private $isAllowedForBulkUuid;

/**
* @param Context $context
* @param PageFactory $resultPageFactory
* @param AccessValidator $accessValidator
* @param string $menuId
* @param IsAllowedForBulkUuid|null $isAllowedForBulkUuid
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\AsynchronousOperations\Model\AccessValidator $accessValidator,
$menuId = 'Magento_AsynchronousOperations::system_magento_logging_bulk_operations'
Context $context,
PageFactory $resultPageFactory,
AccessValidator $accessValidator,
$menuId = 'Magento_AsynchronousOperations::system_magento_logging_bulk_operations',
?IsAllowedForBulkUuid $isAllowedForBulkUuid = null
) {
$this->resultPageFactory = $resultPageFactory;
$this->accessValidator = $accessValidator;
$this->menuId = $menuId;
$this->isAllowedForBulkUuid = $isAllowedForBulkUuid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense to change target branch to 2.5 and get rid of Object manager?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, this PR targeting is 2.4-develop.

?: ObjectManager::getInstance()->get(IsAllowedForBulkUuid::class);
parent::__construct($context);
}

Expand All @@ -49,14 +67,13 @@ public function __construct(
*/
protected function _isAllowed()
{
return $this->_authorization->isAllowed('Magento_Logging::system_magento_logging_bulk_operations')
&& $this->accessValidator->isAllowed($this->getRequest()->getParam('uuid'));
return $this->isAllowedForBulkUuid->execute($this->getRequest()->getParam('uuid'));
}

/**
* Bulk details action
*
* @return \Magento\Framework\View\Result\Page
* @return Page
*/
public function execute()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@

use Magento\AsynchronousOperations\Model\BulkManagement;
use Magento\AsynchronousOperations\Model\BulkNotificationManagement;
use Magento\AsynchronousOperations\Model\IsAllowedForBulkUuid;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\View\Result\Redirect;
use Magento\Backend\App\Action;
use Magento\AsynchronousOperations\Model\AccessValidator;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Controller\ResultFactory;

/**
* Class Bulk Retry Controller
*/
class Retry extends Action
class Retry extends Action implements HttpPostActionInterface
{
/**
* @var BulkManagement
Expand All @@ -29,40 +32,47 @@ class Retry extends Action
private $notificationManagement;

/**
* @var \Magento\AsynchronousOperations\Model\AccessValidator
* @var AccessValidator
*/
private $accessValidator;

/**
* Retry constructor.
* @var IsAllowedForBulkUuid
*/
private $isAllowedForBulkUuid;

/**
* @param Context $context
* @param BulkManagement $bulkManagement
* @param BulkNotificationManagement $notificationManagement
* @param AccessValidator $accessValidator
* @param IsAllowedForBulkUuid|null $isAllowedForBulkUuid
*/
public function __construct(
Context $context,
BulkManagement $bulkManagement,
BulkNotificationManagement $notificationManagement,
AccessValidator $accessValidator
AccessValidator $accessValidator,
?IsAllowedForBulkUuid $isAllowedForBulkUuid = null
) {
parent::__construct($context);
$this->bulkManagement = $bulkManagement;
$this->notificationManagement = $notificationManagement;
$this->accessValidator = $accessValidator;
$this->isAllowedForBulkUuid = $isAllowedForBulkUuid
?: ObjectManager::getInstance()->get(IsAllowedForBulkUuid::class);
}

/**
* @inheritDoc
*/
protected function _isAllowed()
{
return $this->_authorization->isAllowed('Magento_Logging::system_magento_logging_bulk_operations')
&& $this->accessValidator->isAllowed($this->getRequest()->getParam('uuid'));
return $this->isAllowedForBulkUuid->execute($this->getRequest()->getParam('uuid'));
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function execute()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@

namespace Magento\AsynchronousOperations\Controller\Adminhtml\Index;

class Index extends \Magento\Backend\App\Action
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Result\Page;
use \Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\View\Result\PageFactory;

class Index extends Action implements HttpGetActionInterface
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Logging::system_magento_logging_bulk_operations';
public const ADMIN_RESOURCE = 'Magento_AsynchronousOperations::system_magento_logging_bulk_operations';

/**
* @var \Magento\Framework\View\Result\PageFactory
* @var PageFactory
*/
private $resultPageFactory;

Expand All @@ -26,33 +27,24 @@ class Index extends \Magento\Backend\App\Action
private $menuId;

/**
* Details constructor.
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param Context $context
* @param PageFactory $resultPageFactory
* @param string $menuId
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
Context $context,
PageFactory $resultPageFactory,
$menuId = 'Magento_AsynchronousOperations::system_magento_logging_bulk_operations'
) {
$this->resultPageFactory = $resultPageFactory;
$this->menuId = $menuId;
parent::__construct($context);
}

/**
* @inheritDoc
*/
protected function _isAllowed()
{
return parent::_isAllowed();
}

/**
* Bulk list action
*
* @return \Magento\Framework\View\Result\Page
* @return Page
*/
public function execute()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,36 @@
namespace Magento\AsynchronousOperations\Controller\Adminhtml\Notification;

use Magento\AsynchronousOperations\Model\BulkNotificationManagement;
use Magento\Backend\App\Action\Context;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\ResultFactory;

/**
* Class Bulk Notification Dismiss Controller
*/
class Dismiss extends Action
class Dismiss extends Action implements HttpGetActionInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume using of Abstract action is deprecated. Make sence to refactor that? Or we will leave it as it is now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think such refactoring would be excessive for this PR.

{
public const ADMIN_RESOURCE = 'Magento_AsynchronousOperations::system_magento_logging_bulk_operations';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constant used several times, make sense to unify it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constant is required for \Magento\Backend\App\AbstractAction::_isAllowed, so it should be defined separately for each action.


/**
* @var BulkNotificationManagement
*/
private $notificationManagement;

/**
* Class constructor.
*
* @param Context $context
* @param BulkNotificationManagement $notificationManagement
*/
public function __construct(
Context $context,
BulkNotificationManagement $notificationManagement
) {
public function __construct(Context $context, BulkNotificationManagement $notificationManagement)
{
parent::__construct($context);
$this->notificationManagement = $notificationManagement;
}

/**
* @inheritDoc
*/
protected function _isAllowed()
{
return $this->_authorization->isAllowed('Magento_Logging::system_magento_logging_bulk_operations');
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function execute()
{
Expand All @@ -54,7 +46,7 @@ public function execute()

$isAcknowledged = $this->notificationManagement->acknowledgeBulks($bulkUuids);

/** @var \Magento\Framework\Controller\Result\Json $result */
/** @var Json $result */
$result = $this->resultFactory->create(ResultFactory::TYPE_JSON);
if (!$isAcknowledged) {
$result->setHttpResponseCode(400);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
namespace Magento\AsynchronousOperations\Model;

/**
* Class AccessValidator
* Class AccessValidator. Used to validate if user has an access to Bulk Operation
* @deprecated see \Magento\AsynchronousOperations\Model\IsAllowedForBulkUuid
*/
class AccessValidator
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Framework\EntityManager\MetadataPool;
use Magento\AsynchronousOperations\Model\ResourceModel\Bulk\CollectionFactory as BulkCollectionFactory;
use Magento\Framework\Data\Collection;
use Magento\Authorization\Model\UserContextInterface;

/**
* Class for bulk notification manager
Expand Down Expand Up @@ -58,10 +59,12 @@ public function __construct(

/**
* Mark given bulks as acknowledged.
*
* Notifications related to these bulks will not appear in notification area.
*
* @param array $bulkUuids
* @return bool true on success or false on failure
* @throws \Exception
*/
public function acknowledgeBulks(array $bulkUuids)
{
Expand All @@ -83,6 +86,7 @@ public function acknowledgeBulks(array $bulkUuids)

/**
* Remove given bulks from acknowledged list.
*
* Notifications related to these bulks will appear again in notification area.
*
* @param array $bulkUuids
Expand Down Expand Up @@ -119,6 +123,7 @@ public function getAcknowledgedBulksByUser($userId)
'main_table.uuid = acknowledged_bulk.bulk_uuid',
[]
)->addFieldToFilter('user_id', $userId)
->addFieldToFilter('user_type', UserContextInterface::USER_TYPE_ADMIN)
->addOrder('start_time', Collection::SORT_ORDER_DESC)
->getItems();

Expand All @@ -141,6 +146,7 @@ public function getIgnoredBulksByUser($userId)
['acknowledged_bulk.bulk_uuid']
);
$bulks = $bulkCollection->addFieldToFilter('user_id', $userId)
->addFieldToFilter('user_type', UserContextInterface::USER_TYPE_ADMIN)
->addFieldToFilter('acknowledged_bulk.bulk_uuid', ['null' => true])
->addOrder('start_time', Collection::SORT_ORDER_DESC)
->getItems();
Expand Down
Loading