From fd5e0e542d8bc7502ce6e34717773c62a2298aad Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Fri, 27 Mar 2020 11:30:08 +0100 Subject: [PATCH 1/8] Start implementing of correct Auth rules --- .../Controller/Adminhtml/Bulk/Details.php | 5 +- .../Controller/Adminhtml/Bulk/Retry.php | 1 + .../Model/AccessValidator.php | 72 ++++++++++++++++--- .../Component/DataProvider/SearchResult.php | 13 +--- .../AsynchronousOperations/etc/acl.xml | 9 ++- 5 files changed, 73 insertions(+), 27 deletions(-) diff --git a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Details.php b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Details.php index a450187dd094b..281ca809e26ce 100644 --- a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Details.php +++ b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Details.php @@ -49,10 +49,9 @@ 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->accessValidator->isAllowed($this->getRequest()->getParam('uuid')); } - + /** * Bulk details action * diff --git a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Retry.php b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Retry.php index 62e6b9ba4551b..a283f1a5351f9 100644 --- a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Retry.php +++ b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Retry.php @@ -35,6 +35,7 @@ class Retry extends Action /** * Retry constructor. + * * @param Context $context * @param BulkManagement $bulkManagement * @param BulkNotificationManagement $notificationManagement diff --git a/app/code/Magento/AsynchronousOperations/Model/AccessValidator.php b/app/code/Magento/AsynchronousOperations/Model/AccessValidator.php index a14ec254cf897..695a61b4cd7ea 100644 --- a/app/code/Magento/AsynchronousOperations/Model/AccessValidator.php +++ b/app/code/Magento/AsynchronousOperations/Model/AccessValidator.php @@ -6,40 +6,61 @@ namespace Magento\AsynchronousOperations\Model; +use Magento\AsynchronousOperations\Api\Data\BulkSummaryInterfaceFactory; +use Magento\Authorization\Model\UserContextInterface; +use Magento\Framework\AuthorizationInterface; +use Magento\Framework\EntityManager\EntityManager; + /** * Class AccessValidator */ class AccessValidator { + public const BULK_LOGGING_ACL_ALL = "Magento_Logging::system_magento_logging_bulk_operations"; + public const BULK_LOGGING_ACL_GUESTS = "Magento_Logging::system_magento_logging_bulk_operations_guests"; + public const BULK_LOGGING_ACL_INTEGRATIONS = "Magento_Logging::system_magento_logging_bulk_operations_integrations"; + public const BULK_LOGGING_ACL_ADMIN = "Magento_Logging::system_magento_logging_bulk_operations_admin"; + public const BULK_LOGGING_ACL_CUSTOMERS = "Magento_Logging::system_magento_logging_bulk_operations_customers"; + public const BULK_LOGGING_ACL_OWN = "Magento_Logging::system_magento_logging_bulk_operations_admin_own"; + /** - * @var \Magento\Authorization\Model\UserContextInterface + * @var UserContextInterface */ private $userContext; /** - * @var \Magento\Framework\EntityManager\EntityManager + * @var EntityManager */ private $entityManager; /** - * @var \Magento\AsynchronousOperations\Api\Data\BulkSummaryInterfaceFactory + * @var BulkSummaryInterfaceFactory */ private $bulkSummaryFactory; + /** + * @var AuthorizationInterface + */ + private $authorization; + /** * AccessValidator constructor. - * @param \Magento\Authorization\Model\UserContextInterface $userContext - * @param \Magento\Framework\EntityManager\EntityManager $entityManager - * @param \Magento\AsynchronousOperations\Api\Data\BulkSummaryInterfaceFactory $bulkSummaryFactory + * + * @param UserContextInterface $userContext + * @param EntityManager $entityManager + * @param BulkSummaryInterfaceFactory $bulkSummaryFactory + * @param AuthorizationInterface $authorization */ public function __construct( - \Magento\Authorization\Model\UserContextInterface $userContext, - \Magento\Framework\EntityManager\EntityManager $entityManager, - \Magento\AsynchronousOperations\Api\Data\BulkSummaryInterfaceFactory $bulkSummaryFactory + UserContextInterface $userContext, + EntityManager $entityManager, + BulkSummaryInterfaceFactory $bulkSummaryFactory, + AuthorizationInterface $authorization ) { $this->userContext = $userContext; $this->entityManager = $entityManager; $this->bulkSummaryFactory = $bulkSummaryFactory; + $this->authorization = $authorization; } /** @@ -50,11 +71,40 @@ public function __construct( */ public function isAllowed($bulkUuid) { - /** @var \Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface $bulkSummary */ + if ($this->authorization->isAllowed(self::BULK_LOGGING_ACL_ALL)) { + return true; + } + + /** @var BulkSummaryInterface $bulkSummary */ $bulkSummary = $this->entityManager->load( $this->bulkSummaryFactory->create(), $bulkUuid ); - return $bulkSummary->getUserId() === $this->userContext->getUserId(); + + $allowedUserTypes = $this->getAllowedUserTypes(); + if (in_array($bulkSummary->getUserType(), $allowedUserTypes)){ + return true; + } + + exit; + + return $bulkSummary->getUserId() === $this->userContext->getUserId() + && $bulkSummary->getUserType(), === $this->userContext->getUserType(); + } + + public function getAllowedUserTypes() + { + $userTypes = [ + self::BULK_LOGGING_ACL_GUESTS => UserContextInterface::USER_TYPE_GUEST, + self::BULK_LOGGING_ACL_INTEGRATIONS => UserContextInterface::USER_TYPE_INTEGRATION, + self::BULK_LOGGING_ACL_ADMIN => UserContextInterface::USER_TYPE_ADMIN, + self::BULK_LOGGING_ACL_CUSTOMERS => UserContextInterface::USER_TYPE_CUSTOMER + ]; + + return array_map(function ($resourceId, $userTypeId) { + if ($this->authorization->isAllowed($resourceId)) { + return $userTypeId; + } + }, array_keys($userTypes), $userTypes); } } diff --git a/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php b/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php index 5f2fbd9ea8b11..93c644ad92ffc 100644 --- a/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php +++ b/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php @@ -9,7 +9,6 @@ use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory; use Magento\Framework\Event\ManagerInterface as EventManager; use Psr\Log\LoggerInterface as Logger; -use Magento\Authorization\Model\UserContextInterface; use Magento\Framework\Bulk\BulkSummaryInterface; use Magento\AsynchronousOperations\Model\StatusMapper; use Magento\AsynchronousOperations\Model\BulkStatus\CalculatedStatusSql; @@ -19,11 +18,6 @@ */ class SearchResult extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult { - /** - * @var UserContextInterface - */ - private $userContext; - /** * @var StatusMapper */ @@ -45,27 +39,25 @@ class SearchResult extends \Magento\Framework\View\Element\UiComponent\DataProvi * @param Logger $logger * @param FetchStrategy $fetchStrategy * @param EventManager $eventManager - * @param UserContextInterface $userContextInterface * @param StatusMapper $statusMapper * @param CalculatedStatusSql $calculatedStatusSql * @param string $mainTable * @param null $resourceModel * @param string $identifierName * @SuppressWarnings(PHPMD.ExcessiveParameterList) + * @throws \Magento\Framework\Exception\LocalizedException */ public function __construct( EntityFactory $entityFactory, Logger $logger, FetchStrategy $fetchStrategy, EventManager $eventManager, - UserContextInterface $userContextInterface, StatusMapper $statusMapper, CalculatedStatusSql $calculatedStatusSql, $mainTable = 'magento_bulk', $resourceModel = null, $identifierName = 'uuid' ) { - $this->userContext = $userContextInterface; $this->statusMapper = $statusMapper; $this->calculatedStatusSql = $calculatedStatusSql; parent::__construct( @@ -90,9 +82,6 @@ protected function _initSelect() '*', 'status' => $this->calculatedStatusSql->get($this->getTable('magento_operation')) ] - )->where( - 'user_id=?', - $this->userContext->getUserId() ); return $this; } diff --git a/app/code/Magento/AsynchronousOperations/etc/acl.xml b/app/code/Magento/AsynchronousOperations/etc/acl.xml index 42521ad40ff63..1e097c55c1e8c 100644 --- a/app/code/Magento/AsynchronousOperations/etc/acl.xml +++ b/app/code/Magento/AsynchronousOperations/etc/acl.xml @@ -12,7 +12,14 @@ - + + + + + + + + From f59fcbb0f240652c50f164862f79e8ac681a630d Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Sat, 4 Apr 2020 12:25:30 +0200 Subject: [PATCH 2/8] Implement of custom ACL and filtering by User Type in Bulk Operations UI --- .../Controller/Adminhtml/Bulk/Details.php | 31 ++-- .../Controller/Adminhtml/Bulk/Retry.php | 15 +- .../Controller/Adminhtml/Index/Index.php | 37 ++--- .../Adminhtml/Notification/Dismiss.php | 13 +- .../Model/AccessManager.php | 133 ++++++++++++++++++ .../Model/BulkNotificationManagement.php | 4 + .../Model/BulkOperationsStatus.php | 8 ++ .../Model/BulkStatus.php | 25 ++++ .../Collection/Synchronized/Plugin.php | 69 +++++---- .../Ui/Component/AdminNotification/Plugin.php | 22 +-- .../DataProvider/Bulk/DataProvider.php | 90 ++++++++++++ .../AsynchronousOperations/etc/acl.xml | 12 +- .../Magento/AsynchronousOperations/etc/di.xml | 3 - .../adminhtml/ui_component/bulk_listing.xml | 2 +- .../Framework/Bulk/BulkStatusInterface.php | 11 ++ 15 files changed, 391 insertions(+), 84 deletions(-) create mode 100644 app/code/Magento/AsynchronousOperations/Model/AccessManager.php create mode 100644 app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/Bulk/DataProvider.php diff --git a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Details.php b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Details.php index 281ca809e26ce..b159e7fbd3e42 100644 --- a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Details.php +++ b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Details.php @@ -5,20 +5,26 @@ */ namespace Magento\AsynchronousOperations\Controller\Adminhtml\Bulk; +use Magento\AsynchronousOperations\Model\AccessManager; +use Magento\Framework\View\Result\PageFactory; +use Magento\Backend\App\Action\Context; +use Magento\Backend\App\Action; +use Magento\Framework\App\Action\HttpGetActionInterface; + /** * 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 AccessManager */ - private $accessValidator; + private $accessManager; /** * @var string @@ -27,19 +33,20 @@ class Details extends \Magento\Backend\App\Action implements \Magento\Framework\ /** * Details constructor. - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\AsynchronousOperations\Model\AccessValidator $accessValidator + * + * @param Context $context + * @param PageFactory $resultPageFactory + * @param AccessManager $accessManager * @param string $menuId */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\View\Result\PageFactory $resultPageFactory, - \Magento\AsynchronousOperations\Model\AccessValidator $accessValidator, + Context $context, + PageFactory $resultPageFactory, + AccessManager $accessManager, $menuId = 'Magento_AsynchronousOperations::system_magento_logging_bulk_operations' ) { $this->resultPageFactory = $resultPageFactory; - $this->accessValidator = $accessValidator; + $this->accessManager = $accessManager; $this->menuId = $menuId; parent::__construct($context); } @@ -49,7 +56,7 @@ public function __construct( */ protected function _isAllowed() { - return $this->accessValidator->isAllowed($this->getRequest()->getParam('uuid')); + return $this->accessManager->isAllowedForBulkUuid($this->getRequest()->getParam('uuid')); } /** diff --git a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Retry.php b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Retry.php index a283f1a5351f9..e208efccee8be 100644 --- a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Retry.php +++ b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Retry.php @@ -10,7 +10,7 @@ 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\AsynchronousOperations\Model\AccessManager; use Magento\Framework\Controller\ResultFactory; /** @@ -29,9 +29,9 @@ class Retry extends Action private $notificationManagement; /** - * @var \Magento\AsynchronousOperations\Model\AccessValidator + * @var AccessManager */ - private $accessValidator; + private $accessManager; /** * Retry constructor. @@ -39,18 +39,18 @@ class Retry extends Action * @param Context $context * @param BulkManagement $bulkManagement * @param BulkNotificationManagement $notificationManagement - * @param AccessValidator $accessValidator + * @param AccessManager $accessManager */ public function __construct( Context $context, BulkManagement $bulkManagement, BulkNotificationManagement $notificationManagement, - AccessValidator $accessValidator + AccessManager $accessManager ) { parent::__construct($context); $this->bulkManagement = $bulkManagement; $this->notificationManagement = $notificationManagement; - $this->accessValidator = $accessValidator; + $this->accessManager = $accessManager; } /** @@ -58,8 +58,7 @@ 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->accessManager->isAllowedForBulkUuid($this->getRequest()->getParam('uuid')); } /** diff --git a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Index/Index.php b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Index/Index.php index 5a2b9c0a34e64..eb055e258590d 100644 --- a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Index/Index.php +++ b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Index/Index.php @@ -6,19 +6,24 @@ namespace Magento\AsynchronousOperations\Controller\Adminhtml\Index; +use Magento\Backend\App\Action\Context; +use Magento\Framework\View\Result\PageFactory; +use Magento\Framework\View\Result\Page; +use Magento\AsynchronousOperations\Model\AccessManager; + class Index extends \Magento\Backend\App\Action { + public const BULK_OPERATIONS_MENU_ID = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations"; + /** - * Authorization level of a basic admin session - * - * @see _isAllowed() + * @var PageFactory */ - const ADMIN_RESOURCE = 'Magento_Logging::system_magento_logging_bulk_operations'; + private $resultPageFactory; /** - * @var \Magento\Framework\View\Result\PageFactory + * @var AccessManager */ - private $resultPageFactory; + private $accessManager; /** * @var string @@ -27,17 +32,17 @@ class Index extends \Magento\Backend\App\Action /** * Details constructor. - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param string $menuId + * @param Context $context + * @param PageFactory $resultPageFactory + * @param AccessManager $accessManager */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\View\Result\PageFactory $resultPageFactory, - $menuId = 'Magento_AsynchronousOperations::system_magento_logging_bulk_operations' + Context $context, + PageFactory $resultPageFactory, + AccessManager $accessManager ) { $this->resultPageFactory = $resultPageFactory; - $this->menuId = $menuId; + $this->accessManager = $accessManager; parent::__construct($context); } @@ -46,19 +51,19 @@ public function __construct( */ protected function _isAllowed() { - return parent::_isAllowed(); + return $this->accessManager->isOwnActionsAllowed(); } /** * Bulk list action * - * @return \Magento\Framework\View\Result\Page + * @return Page */ public function execute() { $resultPage = $this->resultPageFactory->create(); $resultPage->initLayout(); - $this->_setActiveMenu($this->menuId); + $this->_setActiveMenu(self::BULK_OPERATIONS_MENU_ID); $resultPage->getConfig()->getTitle()->prepend(__('Bulk Actions Log')); return $resultPage; } diff --git a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Notification/Dismiss.php b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Notification/Dismiss.php index 0a71c130fb20a..5ee239d53fa08 100644 --- a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Notification/Dismiss.php +++ b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Notification/Dismiss.php @@ -9,6 +9,7 @@ use Magento\Backend\App\Action\Context; use Magento\Backend\App\Action; use Magento\Framework\Controller\ResultFactory; +use Magento\AsynchronousOperations\Model\AccessManager; /** * Class Bulk Notification Dismiss Controller @@ -20,18 +21,26 @@ class Dismiss extends Action */ private $notificationManagement; + /** + * @var AccessManager + */ + private $accessManager; + /** * Class constructor. * * @param Context $context * @param BulkNotificationManagement $notificationManagement + * @param AccessManager $accessManager */ public function __construct( Context $context, - BulkNotificationManagement $notificationManagement + BulkNotificationManagement $notificationManagement, + AccessManager $accessManager ) { parent::__construct($context); $this->notificationManagement = $notificationManagement; + $this->accessManager = $accessManager; } /** @@ -39,7 +48,7 @@ public function __construct( */ protected function _isAllowed() { - return $this->_authorization->isAllowed('Magento_Logging::system_magento_logging_bulk_operations'); + return $this->accessManager->isOwnActionsAllowed(); } /** diff --git a/app/code/Magento/AsynchronousOperations/Model/AccessManager.php b/app/code/Magento/AsynchronousOperations/Model/AccessManager.php new file mode 100644 index 0000000000000..42510732f373e --- /dev/null +++ b/app/code/Magento/AsynchronousOperations/Model/AccessManager.php @@ -0,0 +1,133 @@ +userContext = $userContext; + $this->entityManager = $entityManager; + $this->bulkSummaryFactory = $bulkSummaryFactory; + $this->authorization = $authorization; + $this->allowedUserTypes = $this->getGlobalAllowedUserTypes(); + } + + /** + * Check if content allowed for current user + * depends from assigned user roles and bulkUuid + * + * @param int $bulkUuid + * @return bool + */ + public function isAllowedForBulkUuid($bulkUuid) + { + + /** @var BulkSummaryInterface $bulkSummary */ + $bulkSummary = $this->entityManager->load( + $this->bulkSummaryFactory->create(), + $bulkUuid + ); + + if (in_array($bulkSummary->getUserType(), $this->allowedUserTypes)) { + return true; + } + + if ($bulkSummary->getUserType() === $this->userContext->getUserType() + && $bulkSummary->getUserId() === $this->userContext->getUserId()) { + return true; + } + + return false; + } + + /** + * Get Allowed user types for current user + * + * @return array + */ + public function getGlobalAllowedUserTypes() + { + $userTypes = [ + self::BULK_LOGGING_ACL_GUESTS => UserContextInterface::USER_TYPE_GUEST, + self::BULK_LOGGING_ACL_INTEGRATIONS => UserContextInterface::USER_TYPE_INTEGRATION, + self::BULK_LOGGING_ACL_ADMIN => UserContextInterface::USER_TYPE_ADMIN, + self::BULK_LOGGING_ACL_CUSTOMERS => UserContextInterface::USER_TYPE_CUSTOMER + ]; + + $allowedUserTypes = []; + foreach ($userTypes as $resourceId => $userTypeId) { + if ($this->authorization->isAllowed($resourceId)) { + $allowedUserTypes[] = $userTypeId; + } + } + + return $allowedUserTypes; + } + + /** + * Check if it allowed to see own bulk operations. + * + * @return bool + */ + public function isOwnActionsAllowed() + { + return $this->authorization->isAllowed(self::BULK_LOGGING_ACL); + } +} diff --git a/app/code/Magento/AsynchronousOperations/Model/BulkNotificationManagement.php b/app/code/Magento/AsynchronousOperations/Model/BulkNotificationManagement.php index 2ba7f7fe5e3ee..b6f8dd0696a47 100644 --- a/app/code/Magento/AsynchronousOperations/Model/BulkNotificationManagement.php +++ b/app/code/Magento/AsynchronousOperations/Model/BulkNotificationManagement.php @@ -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 @@ -62,6 +63,7 @@ public function __construct( * * @param array $bulkUuids * @return bool true on success or false on failure + * @throws \Exception */ public function acknowledgeBulks(array $bulkUuids) { @@ -119,6 +121,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(); @@ -141,6 +144,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(); diff --git a/app/code/Magento/AsynchronousOperations/Model/BulkOperationsStatus.php b/app/code/Magento/AsynchronousOperations/Model/BulkOperationsStatus.php index 5fc164ec833d8..0d96a4905bdea 100644 --- a/app/code/Magento/AsynchronousOperations/Model/BulkOperationsStatus.php +++ b/app/code/Magento/AsynchronousOperations/Model/BulkOperationsStatus.php @@ -93,6 +93,14 @@ public function getBulksByUser($userId) return $this->bulkStatus->getBulksByUser($userId); } + /** + * @inheritDoc + */ + public function getBulksByUserAndType($userId, $userTypeId) + { + return $this->bulkStatus->getBulksByUser($userId, $userTypeId); + } + /** * @inheritDoc */ diff --git a/app/code/Magento/AsynchronousOperations/Model/BulkStatus.php b/app/code/Magento/AsynchronousOperations/Model/BulkStatus.php index 6290ac00ce87f..74c84e9bfe876 100644 --- a/app/code/Magento/AsynchronousOperations/Model/BulkStatus.php +++ b/app/code/Magento/AsynchronousOperations/Model/BulkStatus.php @@ -118,6 +118,31 @@ public function getBulksByUser($userId) return $collection->getItems(); } + /** + * @inheritDoc + */ + public function getBulksByUserAndType($userId, $userTypeId) + { + /** @var ResourceModel\Bulk\Collection $collection */ + $collection = $this->bulkCollectionFactory->create(); + $operationTableName = $this->resourceConnection->getTableName('magento_operation'); + $statusesArray = [ + OperationInterface::STATUS_TYPE_RETRIABLY_FAILED, + OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED, + BulkSummaryInterface::NOT_STARTED, + OperationInterface::STATUS_TYPE_OPEN, + OperationInterface::STATUS_TYPE_COMPLETE + ]; + $select = $collection->getSelect(); + $select->columns(['status' => $this->calculatedStatusSql->get($operationTableName)]) + ->order(new \Zend_Db_Expr('FIELD(status, ' . implode(',', $statusesArray) . ')')); + $collection->addFieldToFilter('user_id', $userId) + ->addFieldToFilter('user_type', $userTypeId) + ->addOrder('start_time'); + + return $collection->getItems(); + } + /** * @inheritDoc */ diff --git a/app/code/Magento/AsynchronousOperations/Model/ResourceModel/System/Message/Collection/Synchronized/Plugin.php b/app/code/Magento/AsynchronousOperations/Model/ResourceModel/System/Message/Collection/Synchronized/Plugin.php index 8457a641ed9a9..20c8cdd6bd593 100644 --- a/app/code/Magento/AsynchronousOperations/Model/ResourceModel/System/Message/Collection/Synchronized/Plugin.php +++ b/app/code/Magento/AsynchronousOperations/Model/ResourceModel/System/Message/Collection/Synchronized/Plugin.php @@ -5,65 +5,82 @@ */ namespace Magento\AsynchronousOperations\Model\ResourceModel\System\Message\Collection\Synchronized; +use Magento\AdminNotification\Model\ResourceModel\System\Message\Collection\Synchronized; +use Magento\AdminNotification\Model\System\MessageFactory; +use Magento\AsynchronousOperations\Model\AccessManager; +use Magento\AsynchronousOperations\Model\BulkNotificationManagement; +use Magento\AsynchronousOperations\Model\Operation\Details; +use Magento\AsynchronousOperations\Model\StatusMapper; +use Magento\Authorization\Model\UserContextInterface; +use Magento\Framework\AuthorizationInterface; +use Magento\Framework\Bulk\BulkStatusInterface; + /** * Class Plugin to add bulks related notification messages to Synchronized Collection */ class Plugin { /** - * @var \Magento\AdminNotification\Model\System\MessageFactory + * @var MessageFactory */ private $messageFactory; /** - * @var \Magento\Framework\Bulk\BulkStatusInterface + * @var BulkStatusInterface */ private $bulkStatus; /** - * @var \Magento\Authorization\Model\UserContextInterface + * @var UserContextInterface */ private $userContext; /** - * @var \Magento\AsynchronousOperations\Model\Operation\Details + * @var Details */ private $operationDetails; /** - * @var \Magento\AsynchronousOperations\Model\BulkNotificationManagement + * @var AccessManager + */ + private $accessManager; + + /** + * @var BulkNotificationManagement */ private $bulkNotificationManagement; /** - * @var \Magento\Framework\AuthorizationInterface + * @var AuthorizationInterface */ private $authorization; /** - * @var \Magento\AsynchronousOperations\Model\StatusMapper + * @var StatusMapper */ private $statusMapper; /** * Plugin constructor. * - * @param \Magento\AdminNotification\Model\System\MessageFactory $messageFactory - * @param \Magento\Framework\Bulk\BulkStatusInterface $bulkStatus - * @param \Magento\AsynchronousOperations\Model\BulkNotificationManagement $bulkNotificationManagement - * @param \Magento\Authorization\Model\UserContextInterface $userContext - * @param \Magento\AsynchronousOperations\Model\Operation\Details $operationDetails - * @param \Magento\Framework\AuthorizationInterface $authorization - * @param \Magento\AsynchronousOperations\Model\StatusMapper $statusMapper + * @param MessageFactory $messageFactory + * @param BulkStatusInterface $bulkStatus + * @param BulkNotificationManagement $bulkNotificationManagement + * @param UserContextInterface $userContext + * @param Details $operationDetails + * @param AuthorizationInterface $authorization + * @param StatusMapper $statusMapper + * @param AccessManager $accessManager; */ public function __construct( - \Magento\AdminNotification\Model\System\MessageFactory $messageFactory, - \Magento\Framework\Bulk\BulkStatusInterface $bulkStatus, - \Magento\AsynchronousOperations\Model\BulkNotificationManagement $bulkNotificationManagement, - \Magento\Authorization\Model\UserContextInterface $userContext, - \Magento\AsynchronousOperations\Model\Operation\Details $operationDetails, - \Magento\Framework\AuthorizationInterface $authorization, - \Magento\AsynchronousOperations\Model\StatusMapper $statusMapper + MessageFactory $messageFactory, + BulkStatusInterface $bulkStatus, + BulkNotificationManagement $bulkNotificationManagement, + UserContextInterface $userContext, + Details $operationDetails, + AuthorizationInterface $authorization, + StatusMapper $statusMapper, + AccessManager $accessManager ) { $this->messageFactory = $messageFactory; $this->bulkStatus = $bulkStatus; @@ -72,25 +89,27 @@ public function __construct( $this->bulkNotificationManagement = $bulkNotificationManagement; $this->authorization = $authorization; $this->statusMapper = $statusMapper; + $this->accessManager = $accessManager; } /** * Adding bulk related messages to notification area * - * @param \Magento\AdminNotification\Model\ResourceModel\System\Message\Collection\Synchronized $collection + * @param Synchronized $collection * @param array $result * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterToArray( - \Magento\AdminNotification\Model\ResourceModel\System\Message\Collection\Synchronized $collection, + Synchronized $collection, $result ) { - if (!$this->authorization->isAllowed('Magento_Logging::system_magento_logging_bulk_operations')) { + if (!$this->accessManager->isOwnActionsAllowed()) { return $result; } $userId = $this->userContext->getUserId(); - $userBulks = $this->bulkStatus->getBulksByUser($userId); + $userType = $this->userContext->getUserType(); + $userBulks = $this->bulkStatus->getBulksByUserAndType($userId, $userType); $acknowledgedBulks = $this->getAcknowledgedBulksUuid( $this->bulkNotificationManagement->getAcknowledgedBulksByUser($userId) ); diff --git a/app/code/Magento/AsynchronousOperations/Ui/Component/AdminNotification/Plugin.php b/app/code/Magento/AsynchronousOperations/Ui/Component/AdminNotification/Plugin.php index b5670639dce09..69371444d77b9 100644 --- a/app/code/Magento/AsynchronousOperations/Ui/Component/AdminNotification/Plugin.php +++ b/app/code/Magento/AsynchronousOperations/Ui/Component/AdminNotification/Plugin.php @@ -6,15 +6,18 @@ namespace Magento\AsynchronousOperations\Ui\Component\AdminNotification; +use Magento\AdminNotification\Ui\Component\DataProvider\DataProvider; +use Magento\AsynchronousOperations\Model\AccessManager; + /** * Class Plugin to eliminate Bulk related links in the notification area */ class Plugin { /** - * @var \Magento\Framework\AuthorizationInterface + * @var AccessManager */ - private $authorization; + private $accessManager; /** * @var bool @@ -23,30 +26,29 @@ class Plugin /** * Plugin constructor. - * @param \Magento\Framework\AuthorizationInterface $authorization + * + * @param AccessManager $accessManager */ public function __construct( - \Magento\Framework\AuthorizationInterface $authorization + AccessManager $accessManager ) { - $this->authorization = $authorization; + $this->accessManager = $accessManager; } /** * Prepares Meta * - * @param \Magento\AdminNotification\Ui\Component\DataProvider\DataProvider $dataProvider + * @param DataProvider $dataProvider * @param array $result * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterGetMeta( - \Magento\AdminNotification\Ui\Component\DataProvider\DataProvider $dataProvider, + DataProvider $dataProvider, $result ) { if (!isset($this->isAllowed)) { - $this->isAllowed = $this->authorization->isAllowed( - 'Magento_Logging::system_magento_logging_bulk_operations' - ); + $this->isAllowed = $this->accessManager->isOwnActionsAllowed(); } $result['columns']['arguments']['data']['config']['isAllowed'] = $this->isAllowed; return $result; diff --git a/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/Bulk/DataProvider.php b/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/Bulk/DataProvider.php new file mode 100644 index 0000000000000..46890e5d99a88 --- /dev/null +++ b/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/Bulk/DataProvider.php @@ -0,0 +1,90 @@ +filterBuilder = $filterBuilder; + $this->accessManager = $accessManager; + $this->userContext = $userContext; + $this->collection = $collectionFactory->create(); + parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data); + } + + public function getData() + { + $allowedUserTypes = $this->accessManager->getGlobalAllowedUserTypes(); + $connection = $this->getCollection()->getConnection(); + $whereOr = []; + if (count($allowedUserTypes) > 0) { + $whereOr[] = $connection->quoteInto("user_type IN(?)", $allowedUserTypes); + } + + if ($this->accessManager->isOwnActionsAllowed()) { + $whereOr[] = implode( + ' AND ', + [ + $connection->quoteInto('user_type = ?', $this->userContext->getUserType()), + $connection->quoteInto('user_id = ?', $this->userContext->getUserId()) + ] + ); + } + + $whereCond = '(' . implode(') OR (', $whereOr) . ')'; + $this->getCollection()->getSelect()->where($whereCond); + + return $this->getCollection()->toArray(); + } +} diff --git a/app/code/Magento/AsynchronousOperations/etc/acl.xml b/app/code/Magento/AsynchronousOperations/etc/acl.xml index 1e097c55c1e8c..bd5d6b10ba6b4 100644 --- a/app/code/Magento/AsynchronousOperations/etc/acl.xml +++ b/app/code/Magento/AsynchronousOperations/etc/acl.xml @@ -12,13 +12,11 @@ - - - - - - - + + + + + diff --git a/app/code/Magento/AsynchronousOperations/etc/di.xml b/app/code/Magento/AsynchronousOperations/etc/di.xml index 171a01cedf289..e2fe8eb5aa59d 100644 --- a/app/code/Magento/AsynchronousOperations/etc/di.xml +++ b/app/code/Magento/AsynchronousOperations/etc/di.xml @@ -91,9 +91,6 @@ - diff --git a/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/bulk_listing.xml b/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/bulk_listing.xml index 87dc0525eb1c0..6499781983240 100644 --- a/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/bulk_listing.xml +++ b/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/bulk_listing.xml @@ -25,7 +25,7 @@ Magento_Logging::system_magento_logging_bulk_operations - + id id diff --git a/lib/internal/Magento/Framework/Bulk/BulkStatusInterface.php b/lib/internal/Magento/Framework/Bulk/BulkStatusInterface.php index 0f1deb0ceeeaf..9318218c8a7af 100644 --- a/lib/internal/Magento/Framework/Bulk/BulkStatusInterface.php +++ b/lib/internal/Magento/Framework/Bulk/BulkStatusInterface.php @@ -38,9 +38,20 @@ public function getOperationsCountByBulkIdAndStatus($bulkUuid, $status); * @param int $userId * @return BulkSummaryInterface[] * @since 100.2.0 + * @deprecated 100.3.0 */ public function getBulksByUser($userId); + /** + * Get all bulks created by user and user type + * + * @param int $userId + * @param int $userTypeId + * @return BulkSummaryInterface[] + * @since 100.2.0 + */ + public function getBulksByUserAndType($userId, $userTypeId); + /** * Computational status based on statuses of belonging operations * From 2febfb7baea89a27442b1af36f5712b0e6bd0577 Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Sat, 4 Apr 2020 15:28:04 +0200 Subject: [PATCH 3/8] Manage tests --- .../Model/AccessValidator.php | 73 +++----------- .../Collection/Synchronized/Plugin.php | 9 -- .../Test/Unit/Model/AccessManagerTest.php | 96 +++++++++++++++++++ .../Collection/Synchronized/PluginTest.php | 27 +++--- .../AdminNotification/PluginTest.php | 17 ++-- 5 files changed, 130 insertions(+), 92 deletions(-) create mode 100644 app/code/Magento/AsynchronousOperations/Test/Unit/Model/AccessManagerTest.php diff --git a/app/code/Magento/AsynchronousOperations/Model/AccessValidator.php b/app/code/Magento/AsynchronousOperations/Model/AccessValidator.php index 695a61b4cd7ea..a32a226f0aa61 100644 --- a/app/code/Magento/AsynchronousOperations/Model/AccessValidator.php +++ b/app/code/Magento/AsynchronousOperations/Model/AccessValidator.php @@ -6,61 +6,41 @@ namespace Magento\AsynchronousOperations\Model; -use Magento\AsynchronousOperations\Api\Data\BulkSummaryInterfaceFactory; -use Magento\Authorization\Model\UserContextInterface; -use Magento\Framework\AuthorizationInterface; -use Magento\Framework\EntityManager\EntityManager; - /** * Class AccessValidator + * @deprecated 100.3.0, use Magento\AsynchronousOperations\Model\AccessManager instead */ class AccessValidator { - public const BULK_LOGGING_ACL_ALL = "Magento_Logging::system_magento_logging_bulk_operations"; - public const BULK_LOGGING_ACL_GUESTS = "Magento_Logging::system_magento_logging_bulk_operations_guests"; - public const BULK_LOGGING_ACL_INTEGRATIONS = "Magento_Logging::system_magento_logging_bulk_operations_integrations"; - public const BULK_LOGGING_ACL_ADMIN = "Magento_Logging::system_magento_logging_bulk_operations_admin"; - public const BULK_LOGGING_ACL_CUSTOMERS = "Magento_Logging::system_magento_logging_bulk_operations_customers"; - public const BULK_LOGGING_ACL_OWN = "Magento_Logging::system_magento_logging_bulk_operations_admin_own"; - /** - * @var UserContextInterface + * @var \Magento\Authorization\Model\UserContextInterface */ private $userContext; /** - * @var EntityManager + * @var \Magento\Framework\EntityManager\EntityManager */ private $entityManager; /** - * @var BulkSummaryInterfaceFactory + * @var \Magento\AsynchronousOperations\Api\Data\BulkSummaryInterfaceFactory */ private $bulkSummaryFactory; - /** - * @var AuthorizationInterface - */ - private $authorization; - /** * AccessValidator constructor. - * - * @param UserContextInterface $userContext - * @param EntityManager $entityManager - * @param BulkSummaryInterfaceFactory $bulkSummaryFactory - * @param AuthorizationInterface $authorization + * @param \Magento\Authorization\Model\UserContextInterface $userContext + * @param \Magento\Framework\EntityManager\EntityManager $entityManager + * @param \Magento\AsynchronousOperations\Api\Data\BulkSummaryInterfaceFactory $bulkSummaryFactory */ public function __construct( - UserContextInterface $userContext, - EntityManager $entityManager, - BulkSummaryInterfaceFactory $bulkSummaryFactory, - AuthorizationInterface $authorization + \Magento\Authorization\Model\UserContextInterface $userContext, + \Magento\Framework\EntityManager\EntityManager $entityManager, + \Magento\AsynchronousOperations\Api\Data\BulkSummaryInterfaceFactory $bulkSummaryFactory ) { $this->userContext = $userContext; $this->entityManager = $entityManager; $this->bulkSummaryFactory = $bulkSummaryFactory; - $this->authorization = $authorization; } /** @@ -71,40 +51,11 @@ public function __construct( */ public function isAllowed($bulkUuid) { - if ($this->authorization->isAllowed(self::BULK_LOGGING_ACL_ALL)) { - return true; - } - - /** @var BulkSummaryInterface $bulkSummary */ + /** @var \Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface $bulkSummary */ $bulkSummary = $this->entityManager->load( $this->bulkSummaryFactory->create(), $bulkUuid ); - - $allowedUserTypes = $this->getAllowedUserTypes(); - if (in_array($bulkSummary->getUserType(), $allowedUserTypes)){ - return true; - } - - exit; - - return $bulkSummary->getUserId() === $this->userContext->getUserId() - && $bulkSummary->getUserType(), === $this->userContext->getUserType(); - } - - public function getAllowedUserTypes() - { - $userTypes = [ - self::BULK_LOGGING_ACL_GUESTS => UserContextInterface::USER_TYPE_GUEST, - self::BULK_LOGGING_ACL_INTEGRATIONS => UserContextInterface::USER_TYPE_INTEGRATION, - self::BULK_LOGGING_ACL_ADMIN => UserContextInterface::USER_TYPE_ADMIN, - self::BULK_LOGGING_ACL_CUSTOMERS => UserContextInterface::USER_TYPE_CUSTOMER - ]; - - return array_map(function ($resourceId, $userTypeId) { - if ($this->authorization->isAllowed($resourceId)) { - return $userTypeId; - } - }, array_keys($userTypes), $userTypes); + return $bulkSummary->getUserId() === $this->userContext->getUserId(); } } diff --git a/app/code/Magento/AsynchronousOperations/Model/ResourceModel/System/Message/Collection/Synchronized/Plugin.php b/app/code/Magento/AsynchronousOperations/Model/ResourceModel/System/Message/Collection/Synchronized/Plugin.php index 20c8cdd6bd593..2a8114e55edd6 100644 --- a/app/code/Magento/AsynchronousOperations/Model/ResourceModel/System/Message/Collection/Synchronized/Plugin.php +++ b/app/code/Magento/AsynchronousOperations/Model/ResourceModel/System/Message/Collection/Synchronized/Plugin.php @@ -12,7 +12,6 @@ use Magento\AsynchronousOperations\Model\Operation\Details; use Magento\AsynchronousOperations\Model\StatusMapper; use Magento\Authorization\Model\UserContextInterface; -use Magento\Framework\AuthorizationInterface; use Magento\Framework\Bulk\BulkStatusInterface; /** @@ -50,11 +49,6 @@ class Plugin */ private $bulkNotificationManagement; - /** - * @var AuthorizationInterface - */ - private $authorization; - /** * @var StatusMapper */ @@ -68,7 +62,6 @@ class Plugin * @param BulkNotificationManagement $bulkNotificationManagement * @param UserContextInterface $userContext * @param Details $operationDetails - * @param AuthorizationInterface $authorization * @param StatusMapper $statusMapper * @param AccessManager $accessManager; */ @@ -78,7 +71,6 @@ public function __construct( BulkNotificationManagement $bulkNotificationManagement, UserContextInterface $userContext, Details $operationDetails, - AuthorizationInterface $authorization, StatusMapper $statusMapper, AccessManager $accessManager ) { @@ -87,7 +79,6 @@ public function __construct( $this->userContext = $userContext; $this->operationDetails = $operationDetails; $this->bulkNotificationManagement = $bulkNotificationManagement; - $this->authorization = $authorization; $this->statusMapper = $statusMapper; $this->accessManager = $accessManager; } diff --git a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/AccessManagerTest.php b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/AccessManagerTest.php new file mode 100644 index 0000000000000..fe62d6bb29368 --- /dev/null +++ b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/AccessManagerTest.php @@ -0,0 +1,96 @@ +userContextMock = $this->createMock(UserContextInterface::class); + $this->entityManagerMock = $this->createMock(EntityManager::class); + $this->bulkSummaryFactoryMock = $this->createPartialMock( + BulkSummaryInterfaceFactory::class, + ['create'] + ); + $this->authorizationMock = $this->createMock(AuthorizationInterface::class); + + $this->model = new AccessManager( + $this->userContextMock, + $this->entityManagerMock, + $this->bulkSummaryFactoryMock, + $this->authorizationMock + ); + } + + /** + * @dataProvider summaryDataProvider + * @param string $bulkUserId + * @param bool $expectedResult + */ + public function testIsAllowedForBulkUuid($bulkUserId, $expectedResult) + { + $adminId = 1; + $uuid = 'test-001'; + $bulkSummaryMock = $this->createMock(BulkSummaryInterface::class); + + $this->bulkSummaryFactoryMock->expects($this->once())->method('create')->willReturn($bulkSummaryMock); + $this->entityManagerMock->expects($this->once()) + ->method('load') + ->with($bulkSummaryMock, $uuid) + ->willReturn($bulkSummaryMock); + + $bulkSummaryMock->expects($this->once())->method('getUserId')->willReturn($bulkUserId); + $this->userContextMock->expects($this->once())->method('getUserId')->willReturn($adminId); + + $this->assertEquals($this->model->isAllowedForBulkUuid($uuid), $expectedResult); + } + + + + /** + * @return array + */ + public static function summaryDataProvider() + { + return [ + [2, false], + [1, true] + ]; + } +} diff --git a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php index 6a51258b34afc..a3c51270bccd4 100644 --- a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php +++ b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php @@ -10,7 +10,6 @@ use Magento\Framework\Bulk\BulkStatusInterface; use Magento\AsynchronousOperations\Model\BulkNotificationManagement; use Magento\AsynchronousOperations\Model\Operation\Details; -use Magento\Framework\AuthorizationInterface; use Magento\AdminNotification\Model\ResourceModel\System\Message\Collection\Synchronized; /** @@ -53,22 +52,22 @@ class PluginTest extends \PHPUnit\Framework\TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject */ - private $authorizationMock; + private $messageMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - private $messageMock; + private $collectionMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - private $collectionMock; + private $statusMapper; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - private $statusMapper; + private $accessManager; /** * @var string @@ -85,29 +84,28 @@ protected function setUp() $this->userContextMock = $this->createMock(UserContextInterface::class); $this->operationsDetailsMock = $this->createMock(Details::class); - $this->authorizationMock = $this->createMock(AuthorizationInterface::class); $this->messageMock = $this->createMock(\Magento\AdminNotification\Model\System\Message::class); $this->collectionMock = $this->createMock(Synchronized::class); $this->bulkNotificationMock = $this->createMock(BulkNotificationManagement::class); $this->statusMapper = $this->createMock(\Magento\AsynchronousOperations\Model\StatusMapper::class); + $this->accessManager = $this->createMock(\Magento\AsynchronousOperations\Model\AccessManager::class); $this->plugin = new Plugin( $this->messagefactoryMock, $this->bulkStatusMock, $this->bulkNotificationMock, $this->userContextMock, $this->operationsDetailsMock, - $this->authorizationMock, - $this->statusMapper + $this->statusMapper, + $this->accessManager ); } public function testAfterToArrayIfNotAllowed() { $result = []; - $this->authorizationMock + $this->accessManager ->expects($this->once()) - ->method('isAllowed') - ->with($this->resourceName) + ->method('isOwnActionsAllowed') ->willReturn(false); $this->assertEquals($result, $this->plugin->afterToArray($this->collectionMock, $result)); } @@ -136,10 +134,9 @@ public function testAfterTo($operationDetails) $bulkMock->expects($this->once())->method('getDescription')->willReturn('Bulk Description'); $this->messagefactoryMock->expects($this->once())->method('create')->willReturn($this->messageMock); $this->messageMock->expects($this->once())->method('toArray')->willReturn($bulkArray); - $this->authorizationMock + $this->accessManager ->expects($this->once()) - ->method('isAllowed') - ->with($this->resourceName) + ->method('isOwnActionsAllowed') ->willReturn(true); $this->userContextMock->expects($this->once())->method('getUserId')->willReturn($userId); $this->bulkNotificationMock @@ -148,7 +145,7 @@ public function testAfterTo($operationDetails) ->with($userId) ->willReturn([]); $this->statusMapper->expects($this->once())->method('operationStatusToBulkSummaryStatus'); - $this->bulkStatusMock->expects($this->once())->method('getBulksByUser')->willReturn($userBulks); + $this->bulkStatusMock->expects($this->once())->method('getBulksByUserAndType')->willReturn($userBulks); $result2 = $this->plugin->afterToArray($this->collectionMock, $result); $this->assertEquals(2, $result2['totalRecords']); } diff --git a/app/code/Magento/AsynchronousOperations/Test/Unit/Ui/Component/AdminNotification/PluginTest.php b/app/code/Magento/AsynchronousOperations/Test/Unit/Ui/Component/AdminNotification/PluginTest.php index cc0b3a3da38a7..c883aca7f1f94 100644 --- a/app/code/Magento/AsynchronousOperations/Test/Unit/Ui/Component/AdminNotification/PluginTest.php +++ b/app/code/Magento/AsynchronousOperations/Test/Unit/Ui/Component/AdminNotification/PluginTest.php @@ -6,24 +6,27 @@ namespace Magento\AsynchronousOperations\Test\Unit\Ui\Component\AdminNotification; use Magento\Framework\AuthorizationInterface; +use Magento\AsynchronousOperations\Model\AccessManager; +use Magento\AdminNotification\Ui\Component\DataProvider\DataProvider; +use Magento\AsynchronousOperations\Ui\Component\AdminNotification\Plugin; class PluginTest extends \PHPUnit\Framework\TestCase { /** - * @var \Magento\AsynchronousOperations\Ui\Component\AdminNotification\Plugin + * @var Plugin */ private $plugin; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - private $authorizationMock; + private $accessManagerMock; protected function setUp() { - $this->authorizationMock = $this->createMock(AuthorizationInterface::class); - $this->plugin = new \Magento\AsynchronousOperations\Ui\Component\AdminNotification\Plugin( - $this->authorizationMock + $this->accessManagerMock = $this->createMock(AccessManager::class); + $this->plugin = new Plugin( + $this->accessManagerMock ); } @@ -41,8 +44,8 @@ public function testAfterGetMeta() ] ] ]; - $dataProviderMock = $this->createMock(\Magento\AdminNotification\Ui\Component\DataProvider\DataProvider::class); - $this->authorizationMock->expects($this->once())->method('isAllowed')->willReturn(true); + $dataProviderMock = $this->createMock(DataProvider::class); + $this->accessManagerMock->expects($this->once())->method('isOwnActionsAllowed')->willReturn(true); $this->assertEquals($expectedResult, $this->plugin->afterGetMeta($dataProviderMock, $result)); } } From 2f4ef9f3dde8ecb7f38c605a8f53c748835da6dc Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Wed, 8 Apr 2020 11:20:56 +0200 Subject: [PATCH 4/8] Fix static tests --- .../Controller/Adminhtml/Bulk/Retry.php | 5 +++-- .../Controller/Adminhtml/Index/Index.php | 9 +++------ .../Controller/Adminhtml/Notification/Dismiss.php | 5 +++-- .../Model/AccessManager.php | 3 +-- .../Model/AccessValidator.php | 2 +- .../Model/BulkNotificationManagement.php | 2 ++ .../AsynchronousOperations/Model/BulkStatus.php | 2 +- .../Message/Collection/Synchronized/Plugin.php | 15 ++++++++++++--- .../Test/Unit/Model/AccessManagerTest.php | 2 -- .../Collection/Synchronized/PluginTest.php | 7 +------ .../Component/DataProvider/Bulk/DataProvider.php | 15 ++++++++++----- .../Ui/Component/DataProvider/SearchResult.php | 12 ++++++------ 12 files changed, 43 insertions(+), 36 deletions(-) diff --git a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Retry.php b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Retry.php index e208efccee8be..484af0dbe32eb 100644 --- a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Retry.php +++ b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Bulk/Retry.php @@ -12,11 +12,12 @@ use Magento\Backend\App\Action; use Magento\AsynchronousOperations\Model\AccessManager; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\App\Action\HttpPostActionInterface; /** * Class Bulk Retry Controller */ -class Retry extends Action +class Retry extends Action implements HttpPostActionInterface { /** * @var BulkManagement @@ -62,7 +63,7 @@ protected function _isAllowed() } /** - * {@inheritdoc} + * @inheritdoc */ public function execute() { diff --git a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Index/Index.php b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Index/Index.php index eb055e258590d..292f9a95594af 100644 --- a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Index/Index.php +++ b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Index/Index.php @@ -10,8 +10,10 @@ use Magento\Framework\View\Result\PageFactory; use Magento\Framework\View\Result\Page; use Magento\AsynchronousOperations\Model\AccessManager; +use Magento\Backend\App\Action; +use Magento\Framework\App\Action\HttpGetActionInterface; -class Index extends \Magento\Backend\App\Action +class Index extends Action implements HttpGetActionInterface { public const BULK_OPERATIONS_MENU_ID = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations"; @@ -25,11 +27,6 @@ class Index extends \Magento\Backend\App\Action */ private $accessManager; - /** - * @var string - */ - private $menuId; - /** * Details constructor. * @param Context $context diff --git a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Notification/Dismiss.php b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Notification/Dismiss.php index 5ee239d53fa08..bb38733546ecd 100644 --- a/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Notification/Dismiss.php +++ b/app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Notification/Dismiss.php @@ -10,11 +10,12 @@ use Magento\Backend\App\Action; use Magento\Framework\Controller\ResultFactory; use Magento\AsynchronousOperations\Model\AccessManager; +use Magento\Framework\App\Action\HttpGetActionInterface; /** * Class Bulk Notification Dismiss Controller */ -class Dismiss extends Action +class Dismiss extends Action implements HttpGetActionInterface { /** * @var BulkNotificationManagement @@ -52,7 +53,7 @@ protected function _isAllowed() } /** - * {@inheritdoc} + * @inheritdoc */ public function execute() { diff --git a/app/code/Magento/AsynchronousOperations/Model/AccessManager.php b/app/code/Magento/AsynchronousOperations/Model/AccessManager.php index 42510732f373e..251a835a46313 100644 --- a/app/code/Magento/AsynchronousOperations/Model/AccessManager.php +++ b/app/code/Magento/AsynchronousOperations/Model/AccessManager.php @@ -70,8 +70,7 @@ public function __construct( } /** - * Check if content allowed for current user - * depends from assigned user roles and bulkUuid + * Check if content allowed for current use depends from assigned user roles and bulkUuid * * @param int $bulkUuid * @return bool diff --git a/app/code/Magento/AsynchronousOperations/Model/AccessValidator.php b/app/code/Magento/AsynchronousOperations/Model/AccessValidator.php index a32a226f0aa61..8a5830f6f73a4 100644 --- a/app/code/Magento/AsynchronousOperations/Model/AccessValidator.php +++ b/app/code/Magento/AsynchronousOperations/Model/AccessValidator.php @@ -7,7 +7,7 @@ namespace Magento\AsynchronousOperations\Model; /** - * Class AccessValidator + * Class AccessValidator. Used to validate if user has an access to Bulk Operation * @deprecated 100.3.0, use Magento\AsynchronousOperations\Model\AccessManager instead */ class AccessValidator diff --git a/app/code/Magento/AsynchronousOperations/Model/BulkNotificationManagement.php b/app/code/Magento/AsynchronousOperations/Model/BulkNotificationManagement.php index b6f8dd0696a47..d0dd965980100 100644 --- a/app/code/Magento/AsynchronousOperations/Model/BulkNotificationManagement.php +++ b/app/code/Magento/AsynchronousOperations/Model/BulkNotificationManagement.php @@ -59,6 +59,7 @@ public function __construct( /** * Mark given bulks as acknowledged. + * * Notifications related to these bulks will not appear in notification area. * * @param array $bulkUuids @@ -85,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 diff --git a/app/code/Magento/AsynchronousOperations/Model/BulkStatus.php b/app/code/Magento/AsynchronousOperations/Model/BulkStatus.php index 74c84e9bfe876..31e85a05013da 100644 --- a/app/code/Magento/AsynchronousOperations/Model/BulkStatus.php +++ b/app/code/Magento/AsynchronousOperations/Model/BulkStatus.php @@ -13,7 +13,7 @@ use Magento\Framework\EntityManager\MetadataPool; /** - * Class BulkStatus + * Class Provides method for manipulate with Status data */ class BulkStatus implements \Magento\Framework\Bulk\BulkStatusInterface { diff --git a/app/code/Magento/AsynchronousOperations/Model/ResourceModel/System/Message/Collection/Synchronized/Plugin.php b/app/code/Magento/AsynchronousOperations/Model/ResourceModel/System/Message/Collection/Synchronized/Plugin.php index 2a8114e55edd6..bb5c555f42c98 100644 --- a/app/code/Magento/AsynchronousOperations/Model/ResourceModel/System/Message/Collection/Synchronized/Plugin.php +++ b/app/code/Magento/AsynchronousOperations/Model/ResourceModel/System/Message/Collection/Synchronized/Plugin.php @@ -13,6 +13,7 @@ use Magento\AsynchronousOperations\Model\StatusMapper; use Magento\Authorization\Model\UserContextInterface; use Magento\Framework\Bulk\BulkStatusInterface; +use Magento\Framework\Encryption\Encryptor; /** * Class Plugin to add bulks related notification messages to Synchronized Collection @@ -54,6 +55,11 @@ class Plugin */ private $statusMapper; + /** + * @var Encryptor + */ + private $encryptor; + /** * Plugin constructor. * @@ -63,7 +69,8 @@ class Plugin * @param UserContextInterface $userContext * @param Details $operationDetails * @param StatusMapper $statusMapper - * @param AccessManager $accessManager; + * @param AccessManager $accessManager + * @param Encryptor $encryptor */ public function __construct( MessageFactory $messageFactory, @@ -72,7 +79,8 @@ public function __construct( UserContextInterface $userContext, Details $operationDetails, StatusMapper $statusMapper, - AccessManager $accessManager + AccessManager $accessManager, + Encryptor $encryptor ) { $this->messageFactory = $messageFactory; $this->bulkStatus = $bulkStatus; @@ -81,6 +89,7 @@ public function __construct( $this->bulkNotificationManagement = $bulkNotificationManagement; $this->statusMapper = $statusMapper; $this->accessManager = $accessManager; + $this->encryptor = $encryptor; } /** @@ -118,7 +127,7 @@ public function afterToArray( 'data' => [ 'text' => __('Task "%1": ', $bulk->getDescription()) . $text, 'severity' => \Magento\Framework\Notification\MessageInterface::SEVERITY_MAJOR, - 'identity' => md5('bulk' . $bulkUuid), + 'identity' => $this->encryptor->hash('bulk' . $bulkUuid, Encryptor::HASH_VERSION_SHA256), 'uuid' => $bulkUuid, 'status' => $bulkStatus, 'created_at' => $bulk->getStartTime() diff --git a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/AccessManagerTest.php b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/AccessManagerTest.php index fe62d6bb29368..2d6e20ae12aa9 100644 --- a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/AccessManagerTest.php +++ b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/AccessManagerTest.php @@ -81,8 +81,6 @@ public function testIsAllowedForBulkUuid($bulkUserId, $expectedResult) $this->assertEquals($this->model->isAllowedForBulkUuid($uuid), $expectedResult); } - - /** * @return array */ diff --git a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php index a3c51270bccd4..b901ca9bb68bb 100644 --- a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php +++ b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php @@ -13,7 +13,7 @@ use Magento\AdminNotification\Model\ResourceModel\System\Message\Collection\Synchronized; /** - * Class PluginTest + * Test cases for Plugin implementation * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ @@ -69,11 +69,6 @@ class PluginTest extends \PHPUnit\Framework\TestCase */ private $accessManager; - /** - * @var string - */ - private $resourceName = 'Magento_Logging::system_magento_logging_bulk_operations'; - protected function setUp() { $this->messagefactoryMock = $this->createPartialMock( diff --git a/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/Bulk/DataProvider.php b/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/Bulk/DataProvider.php index 46890e5d99a88..cae5c66ce4b8b 100644 --- a/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/Bulk/DataProvider.php +++ b/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/Bulk/DataProvider.php @@ -39,22 +39,22 @@ class DataProvider extends AbstractDataProvider * @param string $primaryFieldName * @param string $requestFieldName * @param CollectionFactory $collectionFactory - * @param array $meta - * @param array $data * @param AccessManager $accessManager * @param FilterBuilder $filterBuilder * @param UserContextInterface $userContext + * @param array $meta + * @param array $data */ public function __construct( $name, $primaryFieldName, $requestFieldName, CollectionFactory $collectionFactory, - array $meta = [], - array $data = [], AccessManager $accessManager, FilterBuilder $filterBuilder, - UserContextInterface $userContext + UserContextInterface $userContext, + array $meta = [], + array $data = [] ) { $this->filterBuilder = $filterBuilder; $this->accessManager = $accessManager; @@ -63,6 +63,11 @@ public function __construct( parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data); } + /** + * Get data for Bulk Operations Grid + * + * @return array + */ public function getData() { $allowedUserTypes = $this->accessManager->getGlobalAllowedUserTypes(); diff --git a/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php b/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php index 93c644ad92ffc..4b38a2e001fa3 100644 --- a/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php +++ b/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php @@ -14,7 +14,7 @@ use Magento\AsynchronousOperations\Model\BulkStatus\CalculatedStatusSql; /** - * Class SearchResult + * Implementing of Search Results for Bulk Operations */ class SearchResult extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult { @@ -42,7 +42,7 @@ class SearchResult extends \Magento\Framework\View\Element\UiComponent\DataProvi * @param StatusMapper $statusMapper * @param CalculatedStatusSql $calculatedStatusSql * @param string $mainTable - * @param null $resourceModel + * @param null|string $resourceModel * @param string $identifierName * @SuppressWarnings(PHPMD.ExcessiveParameterList) * @throws \Magento\Framework\Exception\LocalizedException @@ -72,7 +72,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ protected function _initSelect() { @@ -87,7 +87,7 @@ protected function _initSelect() } /** - * {@inheritdoc} + * @inheritdoc */ protected function _afterLoad() { @@ -99,7 +99,7 @@ protected function _afterLoad() } /** - * {@inheritdoc} + * Add additional field for filter request */ public function addFieldToFilter($field, $condition = null) { @@ -122,7 +122,7 @@ public function addFieldToFilter($field, $condition = null) } /** - * {@inheritdoc} + * @inheritdoc */ public function getSelectCountSql() { From 7d50e3905b94b5eb292f981f3ef69bc7732ba907 Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Wed, 8 Apr 2020 13:26:15 +0200 Subject: [PATCH 5/8] Fix Static tests --- .../Message/Collection/Synchronized/PluginTest.php | 9 ++++++++- .../Ui/Component/DataProvider/SearchResult.php | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php index b901ca9bb68bb..cab1bb92ce636 100644 --- a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php +++ b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php @@ -69,6 +69,11 @@ class PluginTest extends \PHPUnit\Framework\TestCase */ private $accessManager; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $encryptor; + protected function setUp() { $this->messagefactoryMock = $this->createPartialMock( @@ -84,6 +89,7 @@ protected function setUp() $this->bulkNotificationMock = $this->createMock(BulkNotificationManagement::class); $this->statusMapper = $this->createMock(\Magento\AsynchronousOperations\Model\StatusMapper::class); $this->accessManager = $this->createMock(\Magento\AsynchronousOperations\Model\AccessManager::class); + $this->encryptor = $this->createMock(\Magento\Framework\Encryption\Encryptor::class); $this->plugin = new Plugin( $this->messagefactoryMock, $this->bulkStatusMock, @@ -91,7 +97,8 @@ protected function setUp() $this->userContextMock, $this->operationsDetailsMock, $this->statusMapper, - $this->accessManager + $this->accessManager, + $this->encryptor ); } diff --git a/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php b/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php index 4b38a2e001fa3..1505c550c9f43 100644 --- a/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php +++ b/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php @@ -100,6 +100,11 @@ protected function _afterLoad() /** * Add additional field for filter request + * + * @param array|string $field + * @param null $condition + * + * @return $this */ public function addFieldToFilter($field, $condition = null) { From dd345429e65861fdad2000042ae7b031a3831cab Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Wed, 8 Apr 2020 13:57:51 +0200 Subject: [PATCH 6/8] Fix Static Test --- .../Ui/Component/DataProvider/SearchResult.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php b/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php index 1505c550c9f43..0a337b620e6ba 100644 --- a/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php +++ b/app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php @@ -102,7 +102,7 @@ protected function _afterLoad() * Add additional field for filter request * * @param array|string $field - * @param null $condition + * @param string|array $condition * * @return $this */ From 1d082809096013a677a4e07454dcb58520b8882b Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Wed, 15 Apr 2020 17:47:33 +0200 Subject: [PATCH 7/8] Iliminate Magento_Logging dependency --- .../AsynchronousOperations/Model/AccessManager.php | 10 +++++----- .../Magento/AsynchronousOperations/etc/acl.xml | 14 +++++++------- .../AsynchronousOperations/etc/adminhtml/menu.xml | 4 ++-- .../etc/extension_attributes.xml | 2 +- .../Magento/AsynchronousOperations/etc/webapi.xml | 8 ++++---- .../view/adminhtml/ui_component/bulk_listing.xml | 2 +- .../ui_component/failed_operation_listing.xml | 2 +- .../failed_operation_modal_listing.xml | 2 +- .../ui_component/retriable_operation_listing.xml | 2 +- .../retriable_operation_modal_listing.xml | 2 +- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/code/Magento/AsynchronousOperations/Model/AccessManager.php b/app/code/Magento/AsynchronousOperations/Model/AccessManager.php index 251a835a46313..58ee4a82bdbec 100644 --- a/app/code/Magento/AsynchronousOperations/Model/AccessManager.php +++ b/app/code/Magento/AsynchronousOperations/Model/AccessManager.php @@ -17,11 +17,11 @@ */ class AccessManager { - public const BULK_LOGGING_ACL_GUESTS = "Magento_Logging::system_magento_logging_bulk_operations_guests"; - public const BULK_LOGGING_ACL_CUSTOMERS = "Magento_Logging::system_magento_logging_bulk_operations_customers"; - public const BULK_LOGGING_ACL_INTEGRATIONS = "Magento_Logging::system_magento_logging_bulk_operations_integrations"; - public const BULK_LOGGING_ACL_ADMIN = "Magento_Logging::system_magento_logging_bulk_operations_admin"; - public const BULK_LOGGING_ACL = "Magento_Logging::system_magento_logging_bulk_operations"; + public const BULK_LOGGING_ACL_GUESTS = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations_guests"; + public const BULK_LOGGING_ACL_CUSTOMERS = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations_customers"; + public const BULK_LOGGING_ACL_INTEGRATIONS = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations_integrations"; + public const BULK_LOGGING_ACL_ADMIN = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations_admin"; + public const BULK_LOGGING_ACL = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations"; /** * @var UserContextInterface diff --git a/app/code/Magento/AsynchronousOperations/etc/acl.xml b/app/code/Magento/AsynchronousOperations/etc/acl.xml index bd5d6b10ba6b4..b49d327a78fba 100644 --- a/app/code/Magento/AsynchronousOperations/etc/acl.xml +++ b/app/code/Magento/AsynchronousOperations/etc/acl.xml @@ -10,13 +10,13 @@ - - - - - - - + + + + + + + diff --git a/app/code/Magento/AsynchronousOperations/etc/adminhtml/menu.xml b/app/code/Magento/AsynchronousOperations/etc/adminhtml/menu.xml index 2e9fe34c45cec..455041f7d01ec 100644 --- a/app/code/Magento/AsynchronousOperations/etc/adminhtml/menu.xml +++ b/app/code/Magento/AsynchronousOperations/etc/adminhtml/menu.xml @@ -13,7 +13,7 @@ module="Magento_AsynchronousOperations" sortOrder="70" parent="Magento_Backend::system" dependsOnModule="Magento_AsynchronousOperations" - resource="Magento_Logging::magento_logging"/> + resource="Magento_AsynchronousOperations::magento_logging"/> + resource="Magento_AsynchronousOperations::system_magento_logging_bulk_operations"/> diff --git a/app/code/Magento/AsynchronousOperations/etc/extension_attributes.xml b/app/code/Magento/AsynchronousOperations/etc/extension_attributes.xml index 6eeda62373f06..dbbeda4900006 100644 --- a/app/code/Magento/AsynchronousOperations/etc/extension_attributes.xml +++ b/app/code/Magento/AsynchronousOperations/etc/extension_attributes.xml @@ -9,7 +9,7 @@ - + start_time diff --git a/app/code/Magento/AsynchronousOperations/etc/webapi.xml b/app/code/Magento/AsynchronousOperations/etc/webapi.xml index 4c10a5756c8d6..97b6c09f88285 100644 --- a/app/code/Magento/AsynchronousOperations/etc/webapi.xml +++ b/app/code/Magento/AsynchronousOperations/etc/webapi.xml @@ -11,28 +11,28 @@ - + - + - + - + diff --git a/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/bulk_listing.xml b/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/bulk_listing.xml index 6499781983240..25b9c76fd5e3e 100644 --- a/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/bulk_listing.xml +++ b/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/bulk_listing.xml @@ -24,7 +24,7 @@ - Magento_Logging::system_magento_logging_bulk_operations + Magento_AsynchronousOperations::system_magento_logging_bulk_operations id diff --git a/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/failed_operation_listing.xml b/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/failed_operation_listing.xml index 2ac762e398521..dc8e1d2d689c8 100644 --- a/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/failed_operation_listing.xml +++ b/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/failed_operation_listing.xml @@ -24,7 +24,7 @@ - Magento_Logging::system_magento_logging_bulk_operations + Magento_AsynchronousOperations::system_magento_logging_bulk_operations id diff --git a/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/failed_operation_modal_listing.xml b/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/failed_operation_modal_listing.xml index 62a4935da8ba7..c10c9e7b3b63c 100644 --- a/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/failed_operation_modal_listing.xml +++ b/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/failed_operation_modal_listing.xml @@ -24,7 +24,7 @@ - Magento_Logging::system_magento_logging_bulk_operations + Magento_AsynchronousOperations::system_magento_logging_bulk_operations id diff --git a/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/retriable_operation_listing.xml b/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/retriable_operation_listing.xml index 3618e10ee77d8..ab2bf3542d8c4 100644 --- a/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/retriable_operation_listing.xml +++ b/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/retriable_operation_listing.xml @@ -24,7 +24,7 @@ - Magento_Logging::system_magento_logging_bulk_operations + Magento_AsynchronousOperations::system_magento_logging_bulk_operations id diff --git a/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/retriable_operation_modal_listing.xml b/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/retriable_operation_modal_listing.xml index 97e3e897c2533..6014c14281e47 100644 --- a/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/retriable_operation_modal_listing.xml +++ b/app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/retriable_operation_modal_listing.xml @@ -24,7 +24,7 @@ - Magento_Logging::system_magento_logging_bulk_operations + Magento_AsynchronousOperations::system_magento_logging_bulk_operations id From 552f1e78be8d388a91b4d6c20450ab5007645369 Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Thu, 16 Apr 2020 14:06:47 +0200 Subject: [PATCH 8/8] Fix tests --- .../Model/AccessManager.php | 15 +++++++++----- .../Test/Unit/Model/AccessManagerTest.php | 8 ++++---- .../Collection/Synchronized/PluginTest.php | 20 +++++++++---------- .../AdminNotification/PluginTest.php | 2 +- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/app/code/Magento/AsynchronousOperations/Model/AccessManager.php b/app/code/Magento/AsynchronousOperations/Model/AccessManager.php index 58ee4a82bdbec..7b420f10f03ab 100644 --- a/app/code/Magento/AsynchronousOperations/Model/AccessManager.php +++ b/app/code/Magento/AsynchronousOperations/Model/AccessManager.php @@ -17,11 +17,16 @@ */ class AccessManager { - public const BULK_LOGGING_ACL_GUESTS = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations_guests"; - public const BULK_LOGGING_ACL_CUSTOMERS = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations_customers"; - public const BULK_LOGGING_ACL_INTEGRATIONS = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations_integrations"; - public const BULK_LOGGING_ACL_ADMIN = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations_admin"; - public const BULK_LOGGING_ACL = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations"; + public const BULK_LOGGING_ACL_GUESTS + = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations_guests"; + public const BULK_LOGGING_ACL_CUSTOMERS + = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations_customers"; + public const BULK_LOGGING_ACL_INTEGRATIONS + = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations_integrations"; + public const BULK_LOGGING_ACL_ADMIN + = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations_admin"; + public const BULK_LOGGING_ACL + = "Magento_AsynchronousOperations::system_magento_logging_bulk_operations"; /** * @var UserContextInterface diff --git a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/AccessManagerTest.php b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/AccessManagerTest.php index 2d6e20ae12aa9..b50d848c10421 100644 --- a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/AccessManagerTest.php +++ b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/AccessManagerTest.php @@ -21,22 +21,22 @@ class AccessManagerTest extends \PHPUnit\Framework\TestCase private $model; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit\Framework\MockObject\MockObject */ private $userContextMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit\Framework\MockObject\MockObject */ private $entityManagerMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit\Framework\MockObject\MockObject */ private $bulkSummaryFactoryMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit\Framework\MockObject\MockObject */ private $authorizationMock; diff --git a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php index cab1bb92ce636..e4454f2170acc 100644 --- a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php +++ b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php @@ -25,52 +25,52 @@ class PluginTest extends \PHPUnit\Framework\TestCase private $plugin; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit\Framework\MockObject\MockObject */ private $messagefactoryMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit\Framework\MockObject\MockObject */ private $bulkStatusMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit\Framework\MockObject\MockObject */ private $bulkNotificationMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit\Framework\MockObject\MockObject */ private $userContextMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit\Framework\MockObject\MockObject */ private $operationsDetailsMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit\Framework\MockObject\MockObject */ private $messageMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit\Framework\MockObject\MockObject */ private $collectionMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit\Framework\MockObject\MockObject */ private $statusMapper; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit\Framework\MockObject\MockObject */ private $accessManager; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit\Framework\MockObject\MockObject */ private $encryptor; diff --git a/app/code/Magento/AsynchronousOperations/Test/Unit/Ui/Component/AdminNotification/PluginTest.php b/app/code/Magento/AsynchronousOperations/Test/Unit/Ui/Component/AdminNotification/PluginTest.php index c883aca7f1f94..a51abd37b9e73 100644 --- a/app/code/Magento/AsynchronousOperations/Test/Unit/Ui/Component/AdminNotification/PluginTest.php +++ b/app/code/Magento/AsynchronousOperations/Test/Unit/Ui/Component/AdminNotification/PluginTest.php @@ -18,7 +18,7 @@ class PluginTest extends \PHPUnit\Framework\TestCase private $plugin; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit\Framework\MockObject\MockObject */ private $accessManagerMock;