diff --git a/vendor/magento/module-admin-gws/Observer/SetDataBeforeRoleSave.php b/vendor/magento/module-admin-gws/Observer/SetDataBeforeRoleSave.php index 2ab3cda1f449..ce27d50873ec 100644 --- a/vendor/magento/module-admin-gws/Observer/SetDataBeforeRoleSave.php +++ b/vendor/magento/module-admin-gws/Observer/SetDataBeforeRoleSave.php @@ -85,6 +85,11 @@ public function execute(\Magento\Framework\Event\Observer $observer) } } } + + if (!empty($storeGroupIds) && !is_array($storeGroupIds)) { + $storeGroupIds = explode(',', $storeGroupIds); + } + $allStoreGroups = []; $allStoreGroupIds = []; $gwsStoreGroupIds = []; @@ -97,9 +102,6 @@ public function execute(\Magento\Framework\Event\Observer $observer) $allStoreGroups = array_merge($allStoreGroups, ...$allStoreGroupIds); $storeGroupIds = array_merge($storeGroupIds, ...$gwsStoreGroupIds); if (!empty($storeGroupIds)) { - if (!is_array($storeGroupIds)) { - $storeGroupIds = explode(',', $storeGroupIds); - } if ($notExistStoreGroups = array_diff($storeGroupIds, $allStoreGroups)) { throw new LocalizedException( __( diff --git a/vendor/magento/module-admin-gws/Plugin/Customer/Model/ResourceModel/Customer/Collection.php b/vendor/magento/module-admin-gws/Plugin/Customer/Model/ResourceModel/Customer/Collection.php new file mode 100644 index 000000000000..6e47f4b73eec --- /dev/null +++ b/vendor/magento/module-admin-gws/Plugin/Customer/Model/ResourceModel/Customer/Collection.php @@ -0,0 +1,141 @@ +backendSession = $backendSession; + } + + /** + * Get admin role for backend and webapi requests. + * + * @return Role|null + * @throws LocalizedException + */ + private function getAdminRole(): Role|null + { + if (!$this->adminRole || $this->adminUserId !== $this->userContext->getUserId()) { + if ($this->backendSession->getUser()) { + $this->adminRole = $this->backendSession->getUser()->getRole(); + $this->adminUserId = (int)$this->backendSession->getUser()->getId(); + + } elseif ($this->userContext->getUserId() + && $this->userContext->getUserType() === UserContextInterface::USER_TYPE_ADMIN + ) { + $user = $this->userFactory->create(); + $user->load($this->userContext->getUserId()); + $this->adminRole = $user->getRole(); + $this->adminUserId = $this->userContext->getUserId(); + } + } + return $this->adminRole; + } + + /** + * Adds allowed websites to query filter. + * + * @param CustomerCollection $collection + * @param bool $printQuery + * @param bool $logQuery + * @return void + * @throws LocalizedException + * @throws Zend_Db_Select_Exception + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function beforeLoadWithFilter(CustomerCollection $collection, $printQuery = false, $logQuery = false): void + { + $this->filterCollection($collection); + } + + /** + * Adds allowed websites to query filter. + * + * @param CustomerCollection $collection + * @throws Zend_Db_Select_Exception|LocalizedException + */ + public function beforeGetSelectCountSql(CustomerCollection $collection): void + { + $this->filterCollection($collection); + } + + /** + * Add website filter to a customer grid collection. + * + * @param CustomerCollection $collection + * @throws Zend_Db_Select_Exception|LocalizedException + */ + private function filterCollection(CustomerCollection $collection): void + { + $role = $this->getAdminRole(); + if ($role && $role->getId() && !$role->getGwsIsAll() && !$collection->getFlag(self::FILTERED_FLAG_NAME)) { + $mainTableAlias = current(array_keys($collection->getSelect()->getPart(Select::FROM))); + $whereCondition = "$mainTableAlias.website_id IN (?) OR $mainTableAlias.website_id IS NULL"; + $collection->getSelect()->where($whereCondition, $role->getGwsWebsites(), \Zend_Db::INT_TYPE); + $collection->setFlag(self::FILTERED_FLAG_NAME); + } + } +} diff --git a/vendor/magento/module-admin-gws/etc/adminhtml/di.xml b/vendor/magento/module-admin-gws/etc/adminhtml/di.xml index f59767dc54d5..5c70ce465457 100644 --- a/vendor/magento/module-admin-gws/etc/adminhtml/di.xml +++ b/vendor/magento/module-admin-gws/etc/adminhtml/di.xml @@ -134,4 +134,12 @@ + + + + + + Magento\Backend\Model\Auth\Session\Proxy + + diff --git a/vendor/magento/module-admin-gws/etc/webapi_rest/di.xml b/vendor/magento/module-admin-gws/etc/webapi_rest/di.xml new file mode 100644 index 000000000000..c432d5e80573 --- /dev/null +++ b/vendor/magento/module-admin-gws/etc/webapi_rest/di.xml @@ -0,0 +1,26 @@ + + + + + + + diff --git a/vendor/magento/module-admin-gws/etc/webapi_soap/di.xml b/vendor/magento/module-admin-gws/etc/webapi_soap/di.xml new file mode 100644 index 000000000000..5decf150a9f9 --- /dev/null +++ b/vendor/magento/module-admin-gws/etc/webapi_soap/di.xml @@ -0,0 +1,26 @@ + + + + + + +