Skip to content

Commit 97936c0

Browse files
author
Slabko,Michael(mslabko)
committed
Merge pull request #10 from magento-troll/MAGETWO-47285-2.0
Magetwo 47285 2.0
2 parents d95ffa1 + 49fe15f commit 97936c0

File tree

18 files changed

+225
-267
lines changed

18 files changed

+225
-267
lines changed

app/code/Magento/Store/Model/Plugin/StoreCookie.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,25 @@ public function __construct(
5252
* Delete cookie "store" if the store (a value in the cookie) does not exist or is inactive
5353
*
5454
* @param \Magento\Framework\App\FrontController $subject
55-
* @param callable $proceed
5655
* @param \Magento\Framework\App\RequestInterface $request
57-
* @return mixed
56+
* @return void
5857
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5958
*/
60-
public function aroundDispatch(
59+
public function beforeDispatch(
6160
\Magento\Framework\App\FrontController $subject,
62-
\Closure $proceed,
6361
\Magento\Framework\App\RequestInterface $request
6462
) {
65-
$defaultStore = $this->storeManager->getDefaultStoreView();
6663
$storeCodeFromCookie = $this->storeCookieManager->getStoreCodeFromCookie();
6764
if ($storeCodeFromCookie) {
6865
try {
6966
$this->storeRepository->getActiveStoreByCode($storeCodeFromCookie);
7067
} catch (StoreIsInactiveException $e) {
71-
$this->storeCookieManager->deleteStoreCookie($defaultStore);
68+
$this->storeCookieManager->deleteStoreCookie($this->storeManager->getDefaultStoreView());
7269
} catch (NoSuchEntityException $e) {
73-
$this->storeCookieManager->deleteStoreCookie($defaultStore);
70+
$this->storeCookieManager->deleteStoreCookie($this->storeManager->getDefaultStoreView());
7471
} catch (InvalidArgumentException $e) {
75-
$this->storeCookieManager->deleteStoreCookie($defaultStore);
72+
$this->storeCookieManager->deleteStoreCookie($this->storeManager->getDefaultStoreView());
7673
}
7774
}
78-
return $proceed($request);
7975
}
8076
}

app/code/Magento/Store/Model/StoreResolver.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class StoreResolver implements \Magento\Store\Api\StoreResolverInterface
4545
*/
4646
protected $scopeCode;
4747

48+
/*
49+
* @var \Magento\Framework\App\RequestInterface
50+
*/
51+
protected $request;
52+
4853
/**
4954
* @param \Magento\Store\Api\StoreRepositoryInterface $storeRepository
5055
* @param StoreCookieManagerInterface $storeCookieManager

app/code/Magento/Store/Test/Unit/Model/Plugin/StoreCookieTest.php

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ class StoreCookieTest extends \PHPUnit_Framework_TestCase
3737
*/
3838
protected $storeMock;
3939

40-
/**
41-
* @var \Closure
42-
*/
43-
protected $closureMock;
44-
4540
/**
4641
* @var \Magento\Framework\App\FrontController|\PHPUnit_Framework_MockObject_MockObject
4742
*/
@@ -77,10 +72,6 @@ public function setUp()
7772
->setMethods([])
7873
->getMock();
7974

80-
$this->closureMock = function () {
81-
return 'ExpectedValue';
82-
};
83-
8475
$this->subjectMock = $this->getMockBuilder('Magento\Framework\App\FrontController')
8576
->disableOriginalConstructor()
8677
->setMethods([])
@@ -106,7 +97,7 @@ public function setUp()
10697
);
10798
}
10899

109-
public function testAroundDispatchNoSuchEntity()
100+
public function testBeforeDispatchNoSuchEntity()
110101
{
111102
$storeCode = 'store';
112103
$this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($this->storeMock);
@@ -115,13 +106,10 @@ public function testAroundDispatchNoSuchEntity()
115106
->method('getActiveStoreByCode')
116107
->willThrowException(new NoSuchEntityException);
117108
$this->storeCookieManagerMock->expects($this->once())->method('deleteStoreCookie')->with($this->storeMock);
118-
$this->assertEquals(
119-
'ExpectedValue',
120-
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
121-
);
109+
$this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
122110
}
123111

124-
public function testAroundDispatchStoreIsInactive()
112+
public function testBeforeDispatchStoreIsInactive()
125113
{
126114
$storeCode = 'store';
127115
$this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($this->storeMock);
@@ -130,13 +118,10 @@ public function testAroundDispatchStoreIsInactive()
130118
->method('getActiveStoreByCode')
131119
->willThrowException(new StoreIsInactiveException);
132120
$this->storeCookieManagerMock->expects($this->once())->method('deleteStoreCookie')->with($this->storeMock);
133-
$this->assertEquals(
134-
'ExpectedValue',
135-
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
136-
);
121+
$this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
137122
}
138123

139-
public function testAroundDispatchInvalidArgument()
124+
public function testBeforeDispatchInvalidArgument()
140125
{
141126
$storeCode = 'store';
142127
$this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($this->storeMock);
@@ -145,22 +130,16 @@ public function testAroundDispatchInvalidArgument()
145130
->method('getActiveStoreByCode')
146131
->willThrowException(new InvalidArgumentException);
147132
$this->storeCookieManagerMock->expects($this->once())->method('deleteStoreCookie')->with($this->storeMock);
148-
$this->assertEquals(
149-
'ExpectedValue',
150-
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
151-
);
133+
$this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
152134
}
153135

154-
public function testAroundDispatchNoStoreCookie()
136+
public function testBeforeDispatchNoStoreCookie()
155137
{
156138
$storeCode = null;
157-
$this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($this->storeMock);
158139
$this->storeCookieManagerMock->expects($this->once())->method('getStoreCodeFromCookie')->willReturn($storeCode);
140+
$this->storeManagerMock->expects($this->never())->method('getDefaultStoreView')->willReturn($this->storeMock);
159141
$this->storeRepositoryMock->expects($this->never())->method('getActiveStoreByCode');
160142
$this->storeCookieManagerMock->expects($this->never())->method('deleteStoreCookie')->with($this->storeMock);
161-
$this->assertEquals(
162-
'ExpectedValue',
163-
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
164-
);
143+
$this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
165144
}
166145
}

app/code/Magento/Store/etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@
281281
<plugin name="install" type="Magento\Framework\Module\Plugin\DbStatusValidator" sortOrder="40"/>
282282
<plugin name="storeCookieValidate" type="Magento\Store\Model\Plugin\StoreCookie" sortOrder="10"/>
283283
</type>
284+
<type name="Magento\Store\Model\Plugin\StoreCookie">
285+
<arguments>
286+
<argument name="storeManager" xsi:type="object">Magento\Store\Model\StoreManagerInterface\Proxy</argument>
287+
</arguments>
288+
</type>
284289
<type name="Magento\Framework\Module\Plugin\DbStatusValidator">
285290
<arguments>
286291
<argument name="cache" xsi:type="object">Magento\Framework\App\Cache\Type\Config</argument>

app/code/Magento/Ui/view/base/web/js/grid/columns/onoff.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,38 @@ define([
4141
*/
4242
setDefaultSelections: function () {
4343
var positionCacheValid = registry.get('position_cache_valid'),
44+
selectedFromCache = registry.get('selected_cache'),
4445
key,
4546
i;
4647

47-
registry.set('position_cache_valid', true);
48+
if (positionCacheValid && this.selected().length === 0) {
49+
// Check selected data
50+
selectedFromCache = JSON.parse(selectedFromCache);
51+
52+
for (i = 0; i < selectedFromCache.length; i++) {
53+
this.selected.push(selectedFromCache[i]);
54+
}
55+
56+
registry.set('position_cache_valid', true);
57+
registry.set('selected_cache', JSON.stringify(this.selected()));
4858

49-
if (this.selectedData.length === 0 || positionCacheValid) {
5059
return;
5160
}
61+
62+
if (positionCacheValid && this.selected().length > 0) {
63+
registry.set('position_cache_valid', true);
64+
registry.set('selected_cache', JSON.stringify(this.selected()));
65+
66+
return;
67+
}
68+
69+
if (this.selectedData.length === 0) {
70+
registry.set('position_cache_valid', true);
71+
registry.set('selected_cache', JSON.stringify([]));
72+
73+
return;
74+
}
75+
5276
// Check selected data
5377
for (key in this.selectedData) {
5478
if (this.selectedData.hasOwnProperty(key) && this.selected().indexOf(key) === -1) {
@@ -61,6 +85,8 @@ define([
6185
this.selectedData.hasOwnProperty(key) || this.selected.splice(this.selected().indexOf(key), 1);
6286
this.selectedData.hasOwnProperty(key) || i--;
6387
}
88+
registry.set('position_cache_valid', true);
89+
registry.set('selected_cache', JSON.stringify(this.selected()));
6490
},
6591

6692
/**
@@ -91,12 +117,18 @@ define([
91117
* @returns {Object} Chainable.
92118
*/
93119
updateState: function () {
94-
var totalRecords = this.totalRecords(),
120+
var positionCacheValid = registry.get('position_cache_valid'),
121+
totalRecords = this.totalRecords(),
95122
selected = this.selected().length,
96123
excluded = this.excluded().length,
97124
totalSelected = this.totalSelected(),
98125
allSelected;
99126

127+
if (positionCacheValid && this.selected().length > 0) {
128+
registry.set('position_cache_valid', true);
129+
registry.set('selected_cache', JSON.stringify(this.selected()));
130+
}
131+
100132
// When filters are enabled then totalRecords is unknown
101133
if (this.getFiltering()) {
102134
if (this.getFiltering().search !== '') {

app/code/Magento/User/Model/ResourceModel/User.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ public function getOldPasswords($user, $retainLimit = 4)
539539
$userId = (int)$user->getId();
540540
$table = $this->getTable('admin_passwords');
541541

542-
// purge expired passwords, except that should retain
542+
// purge expired passwords, except those which should be retained
543543
$retainPasswordIds = $this->getConnection()->fetchCol(
544544
$this->getConnection()
545545
->select()
@@ -556,7 +556,7 @@ public function getOldPasswords($user, $retainLimit = 4)
556556
}
557557
$this->getConnection()->delete($table, $where);
558558

559-
// now get all remained passwords
559+
// get all remaining passwords
560560
return $this->getConnection()->fetchCol(
561561
$this->getConnection()
562562
->select()

app/code/Magento/User/Model/User.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ protected function _getValidationRulesBeforeSave()
256256
}
257257

258258
/**
259-
* Validate customer attribute values.
260-
* For existing customer password + confirmation will be validated only when password is set
261-
* (i.e. its change is requested)
259+
* Validate admin user data.
260+
*
261+
* Existing user password confirmation will be validated only when password is set
262262
*
263263
* @return bool|string[]
264264
*/
@@ -272,8 +272,35 @@ public function validate()
272272
return $validator->getMessages();
273273
}
274274

275-
return true;
275+
return $this->validatePasswordChange();
276+
}
277+
278+
/**
279+
* Make sure admin password was changed.
280+
*
281+
* New password is compared to at least 4 previous passwords to prevent setting them again
282+
*
283+
* @return bool|string[]
284+
*/
285+
protected function validatePasswordChange()
286+
{
287+
$password = $this->getPassword();
288+
if ($password && !$this->getForceNewPassword() && $this->getId()) {
289+
$errorMessage = __('Sorry, but this password has already been used. Please create another.');
290+
// Check if password is equal to the current one
291+
if ($this->_encryptor->isValidHash($password, $this->getOrigData('password'))) {
292+
return [$errorMessage];
293+
}
276294

295+
// Check whether password was used before
296+
$passwordHash = $this->_encryptor->getHash($password, false);
297+
foreach ($this->getResource()->getOldPasswords($this) as $oldPasswordHash) {
298+
if ($passwordHash === $oldPasswordHash) {
299+
return [$errorMessage];
300+
}
301+
}
302+
}
303+
return true;
277304
}
278305

279306
/**

app/code/Magento/User/Observer/Backend/CheckAdminPasswordChangeObserver.php

Lines changed: 0 additions & 82 deletions
This file was deleted.

app/code/Magento/User/Observer/Backend/TrackAdminNewPasswordObserver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function __construct(
7171
}
7272

7373
/**
74-
* Save new admin password
74+
* Save current admin password to prevent its usage when changed in the future.
7575
*
7676
* @param EventObserver $observer
7777
* @return void
@@ -81,7 +81,7 @@ public function execute(EventObserver $observer)
8181
/* @var $user \Magento\User\Model\User */
8282
$user = $observer->getEvent()->getObject();
8383
if ($user->getId()) {
84-
$password = $user->getNewPassword();
84+
$password = $user->getCurrentPassword();
8585
$passwordLifetime = $this->observerConfig->getAdminPasswordLifetime();
8686
if ($passwordLifetime && $password && !$user->getForceNewPassword()) {
8787
$passwordHash = $this->encryptor->getHash($password, false);

0 commit comments

Comments
 (0)