Skip to content

Commit

Permalink
Merge pull request magento#4984 from magento-arcticfoxes/MC-19649
Browse files Browse the repository at this point in the history
[arcticfoxes] MC-19649: Granular ACL for B2B modules
  • Loading branch information
joanhe authored Nov 7, 2019
2 parents 0bfb92f + bceda98 commit dfe4125
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 37 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -1135,8 +1135,6 @@ public function reindex()
|| $this->dataHasChangedFor('is_active')) {
if (!$productIndexer->isScheduled()) {
$productIndexer->reindexList($this->getPathIds());
} else {
$productIndexer->invalidate();
}
}
}
Expand Down Expand Up @@ -1294,6 +1292,7 @@ public function getChildrenData()

//@codeCoverageIgnoreEnd

// phpcs:disable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames
/**
* Return Data Object data in array format.
*
Expand All @@ -1302,6 +1301,7 @@ public function getChildrenData()
*/
public function __toArray()
{
// phpcs:enable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames
$data = $this->_data;
$hasToArray = function ($model) {
return is_object($model) && method_exists($model, '__toArray') && is_callable([$model, '__toArray']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
*/
namespace Magento\Catalog\Model\Indexer\Category\Product\Action;

/**
* Reindex multiple rows action.
*
* @package Magento\Catalog\Model\Indexer\Category\Product\Action
*/
class Rows extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractAction
{
/**
Expand All @@ -23,11 +28,19 @@ class Rows extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractActio
*/
public function execute(array $entityIds = [], $useTempTable = false)
{
$this->limitationByCategories = $entityIds;
foreach ($entityIds as $entityId) {
$this->limitationByCategories[] = (int)$entityId;
$path = $this->getPathFromCategoryId($entityId);
if (!empty($path)) {
$pathIds = explode('/', $path);
foreach ($pathIds as $pathId) {
$this->limitationByCategories[] = (int)$pathId;
}
}
}
$this->limitationByCategories = array_unique($this->limitationByCategories);
$this->useTempTable = $useTempTable;

$this->removeEntries();

$this->reindex();

return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,6 @@
<testCaseId value="MC-14784"/>
<group value="CatalogSearch"/>
<group value="mtf_migrated"/>
<skip>
<issueId value="MC-21717"/>
</skip>
</annotations>
<before>
<createData entity="_defaultCategory" stepKey="createCategory"/>
Expand Down
17 changes: 14 additions & 3 deletions app/code/Magento/Indexer/Model/Indexer/DependencyDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ public function __construct(
*/
public function __call(string $method, array $args)
{
//phpcs:ignore Magento2.Functions.DiscouragedFunction
return call_user_func_array([$this->indexer, $method], $args);
}

/**
* Sleep magic.
*
* @return array
* @SuppressWarnings(PHPMD.SerializationAware)
*/
public function __sleep()
{
Expand Down Expand Up @@ -218,9 +222,16 @@ public function isWorking(): bool
public function invalidate()
{
$this->indexer->invalidate();
$dependentIndexerIds = $this->dependencyInfoProvider->getIndexerIdsToRunAfter($this->indexer->getId());
foreach ($dependentIndexerIds as $indexerId) {
$this->indexerRegistry->get($indexerId)->invalidate();
$currentIndexerId = $this->indexer->getId();
$idsToRunBefore = $this->dependencyInfoProvider->getIndexerIdsToRunBefore($currentIndexerId);
$idsToRunAfter = $this->dependencyInfoProvider->getIndexerIdsToRunAfter($currentIndexerId);

$indexersToInvalidate = array_unique(array_merge($idsToRunBefore, $idsToRunAfter));
foreach ($indexersToInvalidate as $indexerId) {
$indexer = $this->indexerRegistry->get($indexerId);
if (!$indexer->isInvalid()) {
$indexer->invalidate();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ abstract class AbstractBackendController extends \Magento\TestFramework\TestCase
*/
protected $httpMethod;

/**
* Expected no access response
*
* @var int
*/
protected $expectedNoAccessResponseCode = 403;

/**
* @inheritDoc
*
Expand Down Expand Up @@ -84,21 +91,6 @@ protected function tearDown()
parent::tearDown();
}

/**
* Utilize backend session model by default
*
* @param \PHPUnit\Framework\Constraint\Constraint $constraint
* @param string|null $messageType
* @param string $messageManagerClass
*/
public function assertSessionMessages(
\PHPUnit\Framework\Constraint\Constraint $constraint,
$messageType = null,
$messageManagerClass = \Magento\Framework\Message\Manager::class
) {
parent::assertSessionMessages($constraint, $messageType, $messageManagerClass);
}

/**
* Test ACL configuration for action working.
*/
Expand All @@ -111,8 +103,8 @@ public function testAclHasAccess()
$this->getRequest()->setMethod($this->httpMethod);
}
$this->dispatch($this->uri);
$this->assertNotSame(403, $this->getResponse()->getHttpResponseCode());
$this->assertNotSame(404, $this->getResponse()->getHttpResponseCode());
$this->assertNotSame($this->expectedNoAccessResponseCode, $this->getResponse()->getHttpResponseCode());
}

/**
Expand All @@ -130,6 +122,6 @@ public function testAclNoAccess()
->getAcl()
->deny(null, $this->resource);
$this->dispatch($this->uri);
$this->assertSame(403, $this->getResponse()->getHttpResponseCode());
$this->assertSame($this->expectedNoAccessResponseCode, $this->getResponse()->getHttpResponseCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public function getUrlsWithSecondStoreProvider()
];
}

/**
* @magentoDbIsolation disabled
*/
public function testGetProductUrl()
{
$repository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
Expand Down Expand Up @@ -121,6 +124,7 @@ public function testGetUrlPath()
}

/**
* @magentoDbIsolation disabled
* @magentoAppArea frontend
*/
public function testGetUrl()
Expand All @@ -142,6 +146,7 @@ public function testGetUrl()
* Check that rearranging product url rewrites do not influence on whether to use category in product links
*
* @magentoConfigFixture current_store catalog/seo/product_use_categories 0
* @magentoDbIsolation disabled
*/
public function testGetProductUrlWithRearrangedUrlRewrites()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class ChangelogTest extends \PHPUnit\Framework\TestCase
protected function setUp()
{
$this->connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class);

$this->resourceMock = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
$this->mockGetConnection($this->connectionMock);

Expand Down Expand Up @@ -98,14 +97,50 @@ public function testGetVersion()
$this->mockIsTableExists($changelogTableName, true);
$this->mockGetTableName();

$selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
->disableOriginalConstructor()
->disableOriginalClone()
->setMethods(['from', 'order', 'limit'])
->getMock();
$selectMock->expects($this->any())->method('from')->willReturn($selectMock);
$selectMock->expects($this->any())->method('order')->willReturn($selectMock);
$selectMock->expects($this->any())->method('limit')->willReturn($selectMock);

$this->connectionMock->expects($this->any())->method('select')->willReturn($selectMock);

$this->connectionMock->expects($this->once())
->method('fetchRow')
->will($this->returnValue(['Auto_increment' => 11]));
->will($this->returnValue(['version_id' => 10]));

$this->model->setViewId('viewIdtest');
$this->assertEquals(10, $this->model->getVersion());
}

public function testGetVersionEmptyChangelog()
{
$changelogTableName = 'viewIdtest_cl';
$this->mockIsTableExists($changelogTableName, true);
$this->mockGetTableName();

$selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
->disableOriginalConstructor()
->disableOriginalClone()
->setMethods(['from', 'order', 'limit'])
->getMock();
$selectMock->expects($this->any())->method('from')->willReturn($selectMock);
$selectMock->expects($this->any())->method('order')->willReturn($selectMock);
$selectMock->expects($this->any())->method('limit')->willReturn($selectMock);

$this->connectionMock->expects($this->any())->method('select')->willReturn($selectMock);

$this->connectionMock->expects($this->once())
->method('fetchRow')
->will($this->returnValue(false));

$this->model->setViewId('viewIdtest');
$this->assertEquals(0, $this->model->getVersion());
}

/**
* @expectedException \Magento\Framework\Exception\RuntimeException
* @expectedExceptionMessage Table status for viewIdtest_cl is incorrect. Can`t fetch version id.
Expand All @@ -116,9 +151,20 @@ public function testGetVersionWithExceptionNoAutoincrement()
$this->mockIsTableExists($changelogTableName, true);
$this->mockGetTableName();

$selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
->disableOriginalConstructor()
->disableOriginalClone()
->setMethods(['from', 'order', 'limit'])
->getMock();
$selectMock->expects($this->any())->method('from')->willReturn($selectMock);
$selectMock->expects($this->any())->method('order')->willReturn($selectMock);
$selectMock->expects($this->any())->method('limit')->willReturn($selectMock);

$this->connectionMock->expects($this->any())->method('select')->willReturn($selectMock);

$this->connectionMock->expects($this->once())
->method('fetchRow')
->will($this->returnValue([]));
->will($this->returnValue(['no_version_column' => 'blabla']));

$this->model->setViewId('viewIdtest');
$this->model->getVersion();
Expand Down
17 changes: 11 additions & 6 deletions lib/internal/Magento/Framework/Mview/View/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,18 @@ public function getVersion()
if (!$this->connection->isTableExists($changelogTableName)) {
throw new ChangelogTableNotExistsException(new Phrase("Table %1 does not exist", [$changelogTableName]));
}
$row = $this->connection->fetchRow('SHOW TABLE STATUS LIKE ?', [$changelogTableName]);
if (isset($row['Auto_increment'])) {
return (int)$row['Auto_increment'] - 1;
$select = $this->connection->select()->from($changelogTableName)->order('version_id DESC')->limit(1);
$row = $this->connection->fetchRow($select);
if ($row === false) {
return 0;
} else {
throw new RuntimeException(
new Phrase("Table status for %1 is incorrect. Can`t fetch version id.", [$changelogTableName])
);
if (is_array($row) && array_key_exists('version_id', $row)) {
return (int)$row['version_id'];
} else {
throw new RuntimeException(
new Phrase("Table status for %1 is incorrect. Can`t fetch version id.", [$changelogTableName])
);
}
}
}

Expand Down

0 comments on commit dfe4125

Please sign in to comment.