Skip to content

Commit

Permalink
Merge pull request #452 from magento-okapis/okapis-2.0.11-pr
Browse files Browse the repository at this point in the history
Fixed issue:
 - MAGETWO-57002: [Backport] - Admin user with access to only one website is unable to edit a product - for 2.0
 - MAGETWO-57715: [Backport] - User with permissions restricted to a single store can view orders on all stores for 2.0.x
  • Loading branch information
Oleksii Korshenko authored Sep 30, 2016
2 parents 7d0ed18 + 44c4cf0 commit 6132d84
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 12 deletions.
8 changes: 6 additions & 2 deletions app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ public function reindexByIds(array $ids)
$this->doReindexByIds($ids);
} catch (\Exception $e) {
$this->critical($e);
throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e);
throw new \Magento\Framework\Exception\LocalizedException(
__("Catalog rule indexing failed. See details in exception log.")
);
}
}

Expand Down Expand Up @@ -186,7 +188,9 @@ public function reindexFull()
$this->doReindexFull();
} catch (\Exception $e) {
$this->critical($e);
throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e);
throw new \Magento\Framework\Exception\LocalizedException(
__("Catalog rule indexing failed. See details in exception log.")
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,18 @@ public function addWebsitesToResult($flag = null)
*/
public function addWebsiteFilter($websiteId)
{
$entityInfo = $this->_getAssociatedEntityInfo('website');
if (!$this->getFlag('is_website_table_joined')) {
$websiteIds = is_array($websiteId) ? $websiteId : [$websiteId];
$entityInfo = $this->_getAssociatedEntityInfo('website');
$this->setFlag('is_website_table_joined', true);
if ($websiteId instanceof \Magento\Store\Model\Website) {
$websiteId = $websiteId->getId();
foreach ($websiteIds as $index => $website) {
if ($website instanceof \Magento\Store\Model\Website) {
$websiteIds[$index] = $website->getId();
}
}
$this->getSelect()->join(
['website' => $this->getTable($entityInfo['associations_table'])],
$this->getConnection()->quoteInto('website.' . $entityInfo['entity_id_field'] . ' = ?', $websiteId)
$this->getConnection()->quoteInto('website.' . $entityInfo['entity_id_field'] . ' IN (?)', $websiteIds)
. ' AND main_table.' . $entityInfo['rule_id_field'] . ' = website.' . $entityInfo['rule_id_field'],
[]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ class AbstractCollectionTest extends \PHPUnit_Framework_TestCase
*/
protected $_db;

/**
* @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $connectionMock;

/**
* @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject
*/
private $selectMock;

protected function setUp()
{
$this->_entityFactoryMock = $this->getMock('Magento\Framework\Data\Collection\EntityFactoryInterface');
Expand Down Expand Up @@ -152,6 +162,30 @@ public function testAddWebsiteFilter()
);
}

public function testAddWebsiteFilterArray()
{
$this->selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
->disableOriginalConstructor()
->getMock();

$this->connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->connectionMock->expects($this->atLeastOnce())
->method('quoteInto')
->with($this->equalTo('website. IN (?)'), $this->equalTo(['2', '3']))
->willReturn(true);

$this->abstractCollection->expects($this->atLeastOnce())->method('getSelect')->willReturn($this->selectMock);
$this->abstractCollection->expects($this->atLeastOnce())->method('getConnection')
->willReturn($this->connectionMock);

$this->assertInstanceOf(
\Magento\Rule\Model\ResourceModel\Rule\Collection\AbstractCollection::class,
$this->abstractCollection->addWebsiteFilter(['2', '3'])
);
}

public function testAddFieldToFilter()
{
$this->_prepareAddFilterStubs();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sales\Model\ResourceModel\Order\Grid;

use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy;
use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory;
use Magento\Framework\Event\ManagerInterface as EventManager;
use Psr\Log\LoggerInterface as Logger;

/**
* Order grid collection
*/
class Collection extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult
{
/**
* Initialize dependencies.
*
* @param EntityFactory $entityFactory
* @param Logger $logger
* @param FetchStrategy $fetchStrategy
* @param EventManager $eventManager
* @param string $mainTable
* @param string $resourceModel
*/
public function __construct(
EntityFactory $entityFactory,
Logger $logger,
FetchStrategy $fetchStrategy,
EventManager $eventManager,
$mainTable = 'sales_order_grid',
$resourceModel = '\Magento\Sales\Model\ResourceModel\Order'
) {
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
}
}
6 changes: 0 additions & 6 deletions app/code/Magento/Sales/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -798,12 +798,6 @@
<argument name="state" xsi:type="object">Magento\Framework\App\State\Proxy</argument>
</arguments>
</type>
<virtualType name="Magento\Sales\Model\ResourceModel\Order\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
<arguments>
<argument name="mainTable" xsi:type="string">sales_order_grid</argument>
<argument name="resourceModel" xsi:type="string">Magento\Sales\Model\ResourceModel\Order</argument>
</arguments>
</virtualType>
<virtualType name="Magento\Sales\Model\ResourceModel\Order\Invoice\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
<arguments>
<argument name="mainTable" xsi:type="string">sales_invoice_grid</argument>
Expand Down

0 comments on commit 6132d84

Please sign in to comment.