Skip to content

Commit f449e93

Browse files
author
cspruiell
committed
MAGETWO-57001: [Backport] - Admin user with access to only one website is unable to edit a product - for 2.1
- Merge remote-tracking branch 'origin/MAGETWO-57001-Backport-Admin-user-with-access-2.1.3' into okapis-2.1.3-pr
2 parents 8ac0fba + 173ee01 commit f449e93

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ public function reindexByIds(array $ids)
159159
$this->doReindexByIds($ids);
160160
} catch (\Exception $e) {
161161
$this->critical($e);
162-
throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e);
162+
throw new \Magento\Framework\Exception\LocalizedException(
163+
__("Catalog rule indexing failed. See details in exception log.")
164+
);
163165
}
164166
}
165167

app/code/Magento/Rule/Model/ResourceModel/Rule/Collection/AbstractCollection.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,18 @@ public function addWebsitesToResult($flag = null)
7474
*/
7575
public function addWebsiteFilter($websiteId)
7676
{
77-
$entityInfo = $this->_getAssociatedEntityInfo('website');
7877
if (!$this->getFlag('is_website_table_joined')) {
78+
$websiteIds = is_array($websiteId) ? $websiteId : [$websiteId];
79+
$entityInfo = $this->_getAssociatedEntityInfo('website');
7980
$this->setFlag('is_website_table_joined', true);
80-
if ($websiteId instanceof \Magento\Store\Model\Website) {
81-
$websiteId = $websiteId->getId();
81+
foreach ($websiteIds as $index => $website) {
82+
if ($website instanceof \Magento\Store\Model\Website) {
83+
$websiteIds[$index] = $website->getId();
84+
}
8285
}
8386
$this->getSelect()->join(
8487
['website' => $this->getTable($entityInfo['associations_table'])],
85-
$this->getConnection()->quoteInto('website.' . $entityInfo['entity_id_field'] . ' = ?', $websiteId)
88+
$this->getConnection()->quoteInto('website.' . $entityInfo['entity_id_field'] . ' IN (?)', $websiteIds)
8689
. ' AND main_table.' . $entityInfo['rule_id_field'] . ' = website.' . $entityInfo['rule_id_field'],
8790
[]
8891
);

app/code/Magento/Rule/Test/Unit/Model/ResourceModel/Rule/Collection/AbstractCollectionTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ class AbstractCollectionTest extends \PHPUnit_Framework_TestCase
4545
*/
4646
protected $_db;
4747

48+
/**
49+
* @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
50+
*/
51+
private $connectionMock;
52+
53+
/**
54+
* @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject
55+
*/
56+
private $selectMock;
57+
4858
protected function setUp()
4959
{
5060
$this->_entityFactoryMock = $this->getMock('Magento\Framework\Data\Collection\EntityFactoryInterface');
@@ -152,6 +162,30 @@ public function testAddWebsiteFilter()
152162
);
153163
}
154164

165+
public function testAddWebsiteFilterArray()
166+
{
167+
$this->selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
168+
->disableOriginalConstructor()
169+
->getMock();
170+
171+
$this->connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
172+
->disableOriginalConstructor()
173+
->getMockForAbstractClass();
174+
$this->connectionMock->expects($this->atLeastOnce())
175+
->method('quoteInto')
176+
->with($this->equalTo('website. IN (?)'), $this->equalTo(['2', '3']))
177+
->willReturn(true);
178+
179+
$this->abstractCollection->expects($this->atLeastOnce())->method('getSelect')->willReturn($this->selectMock);
180+
$this->abstractCollection->expects($this->atLeastOnce())->method('getConnection')
181+
->willReturn($this->connectionMock);
182+
183+
$this->assertInstanceOf(
184+
\Magento\Rule\Model\ResourceModel\Rule\Collection\AbstractCollection::class,
185+
$this->abstractCollection->addWebsiteFilter(['2', '3'])
186+
);
187+
}
188+
155189
public function testAddFieldToFilter()
156190
{
157191
$this->_prepareAddFilterStubs();

0 commit comments

Comments
 (0)