Skip to content

Commit

Permalink
Merge pull request #1654 from magento-engcom/develop-prs
Browse files Browse the repository at this point in the history
[EngCom] Public Pull Requests - develop
 - MAGETWO-83154: [2.3-develop] Order grid - Sort by Purchase Date Desc by default #11931
 - MAGETWO-83101: [Backport 2.3-develop] #8236 FIX CMS blocks #11805
 - MAGETWO-83092: Remove unneeded, also mistyped, saveHandler from CatalogSearch indexer declaration #11626
 - MAGETWO-83091: Remove "Undefined fields" from under lib folder #11662
 - MAGETWO-83083: 10195: Order relation child is not set during edit operation #11909
 - MAGETWO-82998: [2.3-develop] X-Magento-Tags header containing whitespaces causes exception #11849
 - MAGETWO-82633: #11409: Too many password reset requests even when disabled in settings #11434
  • Loading branch information
ishakhsuvarov authored Nov 2, 2017
2 parents 8462688 + a7c9272 commit 84e7c86
Show file tree
Hide file tree
Showing 41 changed files with 339 additions and 100 deletions.
2 changes: 0 additions & 2 deletions app/code/Magento/CatalogSearch/etc/indexer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
<indexer id="catalogsearch_fulltext" view_id="catalogsearch_fulltext" class="Magento\CatalogSearch\Model\Indexer\Fulltext">
<title translate="true">Catalog Search</title>
<description translate="true">Rebuild Catalog product fulltext search index</description>

<saveHandler class="Magento\CatalogSearch\Model\Indexer\IndexHandler" />
<structure class="Magento\CatalogSearch\Model\Indexer\IndexStructure" />
</indexer>
</config>
6 changes: 3 additions & 3 deletions app/code/Magento/Cms/Model/ResourceModel/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ public function getIsUniqueBlockToStores(AbstractModel $object)
$entityMetadata = $this->metadataPool->getMetadata(BlockInterface::class);
$linkField = $entityMetadata->getLinkField();

if ($this->_storeManager->hasSingleStore()) {
if ($this->_storeManager->isSingleStoreMode()) {
$stores = [Store::DEFAULT_STORE_ID];
} else {
$stores = (array)$object->getData('stores');
$stores = (array)$object->getData('store_id');
}

$select = $this->getConnection()->select()
Expand Down Expand Up @@ -230,7 +230,7 @@ public function lookupStoreIds($id)
'cbs.' . $linkField . ' = cb.' . $linkField,
[]
)
->where('cb.' . $entityMetadata->getIdentifierField() . ' = :block_id');
->where('cb.' . $entityMetadata->getIdentifierField() . ' = :block_id');

return $connection->fetchCol($select, ['block_id' => (int)$id]);
}
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Sales/Model/AdminOrder/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -1907,6 +1907,7 @@ public function createOrder()
$oldOrder = $this->getSession()->getOrder();
$oldOrder->setRelationChildId($order->getId());
$oldOrder->setRelationChildRealId($order->getIncrementId());
$oldOrder->save();
$this->orderManagement->cancel($oldOrder->getEntityId());
$order->save();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
<settings>
<filter>text</filter>
<label translate="true">ID</label>
<sorting>desc</sorting>
</settings>
</column>
<column name="store_id" class="Magento\Store\Ui\Component\Listing\Column\Store">
Expand All @@ -154,6 +153,7 @@
<filter>dateRange</filter>
<dataType>date</dataType>
<label translate="true">Purchase Date</label>
<sorting>desc</sorting>
</settings>
</column>
<column name="billing_name">
Expand Down
11 changes: 9 additions & 2 deletions app/code/Magento/Security/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ class Config implements ConfigInterface
*/
const XML_PATH_ADMIN_AREA = 'admin/security/';

/**
* Configuration path to frontend area
*/
const XML_PATH_FRONTEND_AREA = 'customer/password/';

/**
* Configuration path to fronted area
* @deprecated
* @see \Magento\Security\Model\Config::XML_PATH_FRONTEND_AREA
*/
const XML_PATH_FRONTED_AREA = 'customer/password/';
const XML_PATH_FRONTED_AREA = self::XML_PATH_FRONTEND_AREA;

/**
* Configuration path to admin account sharing
Expand Down Expand Up @@ -134,7 +141,7 @@ protected function getXmlPathPrefix()
if ($this->scope->getCurrentScope() == \Magento\Framework\App\Area::AREA_ADMINHTML) {
return self::XML_PATH_ADMIN_AREA;
}
return self::XML_PATH_FRONTED_AREA;
return self::XML_PATH_FRONTEND_AREA;
}

/**
Expand Down
26 changes: 20 additions & 6 deletions app/code/Magento/Security/Model/Plugin/AccountManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
*/
namespace Magento\Security\Model\Plugin;

use Magento\Security\Model\SecurityManager;
use Magento\Customer\Model\AccountManagement as AccountManagementOriginal;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Config\ScopeInterface;
use Magento\Framework\Exception\SecurityViolationException;
use Magento\Security\Model\PasswordResetRequestEvent;
use Magento\Security\Model\SecurityManager;

/**
* Magento\Customer\Model\AccountManagement decorator
Expand All @@ -30,21 +32,29 @@ class AccountManagement
*/
protected $passwordRequestEvent;

/**
* @var ScopeInterface
*/
private $scope;

/**
* AccountManagement constructor.
*
* @param \Magento\Framework\App\RequestInterface $request
* @param SecurityManager $securityManager
* @param int $passwordRequestEvent
* @param ScopeInterface $scope
*/
public function __construct(
\Magento\Framework\App\RequestInterface $request,
\Magento\Security\Model\SecurityManager $securityManager,
$passwordRequestEvent = PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST
$passwordRequestEvent = PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST,
ScopeInterface $scope = null
) {
$this->request = $request;
$this->securityManager = $securityManager;
$this->passwordRequestEvent = $passwordRequestEvent;
$this->scope = $scope ?: ObjectManager::getInstance()->get(ScopeInterface::class);
}

/**
Expand All @@ -63,10 +73,14 @@ public function beforeInitiatePasswordReset(
$template,
$websiteId = null
) {
$this->securityManager->performSecurityCheck(
$this->passwordRequestEvent,
$email
);
if ($this->scope->getCurrentScope() == \Magento\Framework\App\Area::AREA_FRONTEND
|| $this->passwordRequestEvent == PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST) {
$this->securityManager->performSecurityCheck(
$this->passwordRequestEvent,
$email
);
}

return [$email, $template, $websiteId];
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Security/Test/Unit/Model/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected function getXmlPathPrefix($scope)
if ($scope == \Magento\Framework\App\Area::AREA_ADMINHTML) {
return \Magento\Security\Model\Config::XML_PATH_ADMIN_AREA;
}
return \Magento\Security\Model\Config::XML_PATH_FRONTED_AREA;
return \Magento\Security\Model\Config::XML_PATH_FRONTEND_AREA;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

namespace Magento\Security\Test\Unit\Model\Plugin;

use Magento\Customer\Model\AccountManagement;
use Magento\Framework\App\Area;
use Magento\Framework\Config\ScopeInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Security\Model\PasswordResetRequestEvent;

/**
* Test class for \Magento\Security\Model\Plugin\AccountManagement testing
Expand All @@ -19,20 +23,25 @@ class AccountManagementTest extends \PHPUnit\Framework\TestCase
protected $model;

/**
* @var \Magento\Framework\App\RequestInterface
* @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $request;

/**
* @var \Magento\Security\Model\SecurityManager
* @var \Magento\Security\Model\SecurityManager|\PHPUnit_Framework_MockObject_MockObject
*/
protected $securityManager;

/**
* @var \Magento\Customer\Model\AccountManagement
* @var AccountManagement|\PHPUnit_Framework_MockObject_MockObject
*/
protected $accountManagement;

/**
* @var ScopeInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $scope;

/**
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
*/
Expand All @@ -53,28 +62,38 @@ public function setUp()
['performSecurityCheck']
);

$this->accountManagement = $this->createMock(\Magento\Customer\Model\AccountManagement::class);
$this->accountManagement = $this->createMock(AccountManagement::class);
$this->scope = $this->createMock(ScopeInterface::class);
}

/**
* @param $area
* @param $passwordRequestEvent
* @param $expectedTimes
* @dataProvider beforeInitiatePasswordResetDataProvider
*/
public function testBeforeInitiatePasswordReset($area, $passwordRequestEvent, $expectedTimes)
{
$email = 'test@example.com';
$template = AccountManagement::EMAIL_RESET;

$this->model = $this->objectManager->getObject(
\Magento\Security\Model\Plugin\AccountManagement::class,
[
'passwordRequestEvent' => $passwordRequestEvent,
'request' => $this->request,
'securityManager' => $this->securityManager
'securityManager' => $this->securityManager,
'scope' => $this->scope
]
);
}

/**
* @return void
*/
public function testBeforeInitiatePasswordReset()
{
$email = 'test@example.com';
$template = \Magento\Customer\Model\AccountManagement::EMAIL_RESET;
$this->scope->expects($this->once())
->method('getCurrentScope')
->willReturn($area);

$this->securityManager->expects($this->once())
$this->securityManager->expects($this->exactly($expectedTimes))
->method('performSecurityCheck')
->with(\Magento\Security\Model\PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST, $email)
->with($passwordRequestEvent, $email)
->willReturnSelf();

$this->model->beforeInitiatePasswordReset(
Expand All @@ -83,4 +102,18 @@ public function testBeforeInitiatePasswordReset()
$template
);
}

/**
* @return array
*/
public function beforeInitiatePasswordResetDataProvider()
{
return [
[Area::AREA_ADMINHTML, PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST, 0],
[Area::AREA_ADMINHTML, PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST, 1],
[Area::AREA_FRONTEND, PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST, 1],
// This should never happen, but let's cover it with tests
[Area::AREA_FRONTEND, PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST, 1],
];
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Security/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</type>
<type name="Magento\Security\Model\Plugin\AccountManagement">
<arguments>
<argument name="passwordRequestEvent" xsi:type="const">Magento\Security\Model\PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST</argument>
<argument name="passwordRequestEvent" xsi:type="const">Magento\Security\Model\PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST</argument>
</arguments>
</type>
<type name="Magento\Security\Model\SecurityManager">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@
use Magento\Customer\Api\Data\CustomerInterface as Customer;
use Magento\Customer\Model\AccountManagement;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Webapi\Exception as HTTPExceptionCodes;
use Magento\Newsletter\Model\Subscriber;
use Magento\Security\Model\Config;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\Customer as CustomerHelper;
use Magento\TestFramework\TestCase\WebapiAbstract;
use Magento\Framework\Webapi\Exception as HTTPExceptionCodes;
use Magento\Security\Model\Config;
use Magento\Newsletter\Model\Plugin\CustomerPlugin;
use Magento\Framework\Webapi\Rest\Request as RestRequest;
use Magento\Newsletter\Model\Subscriber;
use Magento\Customer\Model\Data\Customer as CustomerData;

/**
* Test class for Magento\Customer\Api\AccountManagementInterface
Expand Down Expand Up @@ -112,16 +108,16 @@ public function setUp()
$this->initSubscriber();

if ($this->config->getConfigDataValue(
Config::XML_PATH_FRONTED_AREA .
Config::XML_PATH_FRONTEND_AREA .
Config::XML_PATH_PASSWORD_RESET_PROTECTION_TYPE
) != 0) {
$this->configValue = $this->config
->getConfigDataValue(
Config::XML_PATH_FRONTED_AREA .
Config::XML_PATH_FRONTEND_AREA .
Config::XML_PATH_PASSWORD_RESET_PROTECTION_TYPE
);
$this->config->setDataByPath(
Config::XML_PATH_FRONTED_AREA . Config::XML_PATH_PASSWORD_RESET_PROTECTION_TYPE,
Config::XML_PATH_FRONTEND_AREA . Config::XML_PATH_PASSWORD_RESET_PROTECTION_TYPE,
0
);
$this->config->save();
Expand Down Expand Up @@ -150,7 +146,7 @@ public function tearDown()
}
}
$this->config->setDataByPath(
Config::XML_PATH_FRONTED_AREA . Config::XML_PATH_PASSWORD_RESET_PROTECTION_TYPE,
Config::XML_PATH_FRONTEND_AREA . Config::XML_PATH_PASSWORD_RESET_PROTECTION_TYPE,
$this->configValue
);
$this->config->save();
Expand Down
Loading

0 comments on commit 84e7c86

Please sign in to comment.