Skip to content

Commit 14cec9b

Browse files
merge magento/2.3.6-develop into magento-borg/MC-34648
2 parents 77f097e + f20fb6d commit 14cec9b

File tree

151 files changed

+6662
-1526
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+6662
-1526
lines changed

app/code/Magento/Authorization/Model/ResourceModel/Role.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ protected function _afterDelete(\Magento\Framework\Model\AbstractModel $role)
119119

120120
$connection->delete($this->_ruleTable, ['role_id = ?' => (int)$role->getId()]);
121121

122+
$this->_cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, [\Magento\Backend\Block\Menu::CACHE_TAGS]);
123+
122124
return $this;
123125
}
124126

app/code/Magento/Authorization/Model/Role.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class Role extends \Magento\Framework\Model\AbstractModel
3333
*/
3434
protected $_eventPrefix = 'authorization_roles';
3535

36+
/**
37+
* @var string
38+
*/
39+
protected $_cacheTag = 'user_assigned_role';
40+
3641
/**
3742
* @param \Magento\Framework\Model\Context $context
3843
* @param \Magento\Framework\Registry $registry

app/code/Magento/Backend/App/AbstractAction.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
*/
66
namespace Magento\Backend\App;
77

8+
use Magento\Framework\Encryption\Helper\Security;
9+
810
/**
911
* Generic backend controller
1012
*
13+
* phpcs:disable Magento2.Classes.AbstractApi
1114
* @api
1215
* @SuppressWarnings(PHPMD.NumberOfChildren)
1316
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -101,6 +104,8 @@ public function __construct(Action\Context $context)
101104
}
102105

103106
/**
107+
* Checking if the user has access to requested component.
108+
*
104109
* @return bool
105110
*/
106111
protected function _isAllowed()
@@ -119,6 +124,8 @@ protected function _getSession()
119124
}
120125

121126
/**
127+
* Get message manager.
128+
*
122129
* @return \Magento\Framework\Message\ManagerInterface
123130
*/
124131
protected function getMessageManager()
@@ -146,6 +153,8 @@ protected function _setActiveMenu($itemId)
146153
}
147154

148155
/**
156+
* Prepare breadcrumbs.
157+
*
149158
* @param string $label
150159
* @param string $title
151160
* @param string|null $link
@@ -158,6 +167,8 @@ protected function _addBreadcrumb($label, $title, $link = null)
158167
}
159168

160169
/**
170+
* Add content to specified block.
171+
*
161172
* @param \Magento\Framework\View\Element\AbstractBlock $block
162173
* @return $this
163174
*/
@@ -167,6 +178,8 @@ protected function _addContent(\Magento\Framework\View\Element\AbstractBlock $bl
167178
}
168179

169180
/**
181+
* Move block to left container.
182+
*
170183
* @param \Magento\Framework\View\Element\AbstractBlock $block
171184
* @return $this
172185
*/
@@ -176,6 +189,8 @@ protected function _addLeft(\Magento\Framework\View\Element\AbstractBlock $block
176189
}
177190

178191
/**
192+
* Add js to specified block.
193+
*
179194
* @param \Magento\Framework\View\Element\AbstractBlock $block
180195
* @return $this
181196
*/
@@ -200,6 +215,8 @@ private function _moveBlockToContainer(\Magento\Framework\View\Element\AbstractB
200215
}
201216

202217
/**
218+
* Dispatch request.
219+
*
203220
* @param \Magento\Framework\App\RequestInterface $request
204221
* @return \Magento\Framework\App\ResponseInterface
205222
*/
@@ -286,8 +303,7 @@ public function _processUrlKeys()
286303
}
287304

288305
/**
289-
* Set session locale,
290-
* process force locale set through url params
306+
* Set session locale, process force locale set through url params.
291307
*
292308
* @return $this
293309
*/
@@ -309,8 +325,8 @@ protected function _processLocaleSettings()
309325
* Set redirect into response
310326
*
311327
* @TODO MAGETWO-28356: Refactor controller actions to new ResultInterface
312-
* @param string $path
313-
* @param array $arguments
328+
* @param string $path
329+
* @param array $arguments
314330
* @return \Magento\Framework\App\ResponseInterface
315331
*/
316332
protected function _redirect($path, $arguments = [])
@@ -333,7 +349,7 @@ protected function _redirect($path, $arguments = [])
333349
protected function _forward($action, $controller = null, $module = null, array $params = null)
334350
{
335351
$this->_getSession()->setIsUrlNotice($this->_actionFlag->get('', self::FLAG_IS_URLS_CHECKED));
336-
return parent::_forward($action, $controller, $module, $params);
352+
parent::_forward($action, $controller, $module, $params);
337353
}
338354

339355
/**
@@ -360,7 +376,7 @@ protected function _validateSecretKey()
360376
}
361377

362378
$secretKey = $this->getRequest()->getParam(\Magento\Backend\Model\UrlInterface::SECRET_KEY_PARAM_NAME, null);
363-
if (!$secretKey || $secretKey != $this->_backendUrl->getSecretKey()) {
379+
if (!$secretKey || !Security::compareStrings($secretKey, $this->_backendUrl->getSecretKey())) {
364380
return false;
365381
}
366382
return true;

app/code/Magento/Backend/Block/Widget/Grid/Export.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Magento\Framework\App\Filesystem\DirectoryList;
1010

1111
/**
12+
* Class Export for exporting grid data as CSV file or MS Excel 2003 XML Document file
13+
*
1214
* @api
1315
* @deprecated 100.2.0 in favour of UI component implementation
1416
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -69,6 +71,8 @@ public function __construct(
6971
}
7072

7173
/**
74+
* Internal constructor, that is called from real constructor
75+
*
7276
* @return void
7377
* @throws \Magento\Framework\Exception\LocalizedException
7478
*/
@@ -242,6 +246,7 @@ protected function _getExportTotals()
242246

243247
/**
244248
* Iterate collection and call callback method per item
249+
*
245250
* For callback method first argument always is item object
246251
*
247252
* @param string $callback
@@ -273,7 +278,12 @@ public function _exportIterateCollection($callback, array $args)
273278

274279
$collection = $this->_getRowCollection($originalCollection);
275280
foreach ($collection as $item) {
276-
call_user_func_array([$this, $callback], array_merge([$item], $args));
281+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
282+
call_user_func_array(
283+
[$this, $callback],
284+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
285+
array_merge([$item], $args)
286+
);
277287
}
278288
}
279289
}
@@ -307,7 +317,7 @@ protected function _exportCsvItem(
307317
*/
308318
public function getCsvFile()
309319
{
310-
$name = md5(microtime());
320+
$name = hash('sha256', microtime());
311321
$file = $this->_path . '/' . $name . '.csv';
312322

313323
$this->_directory->create($this->_path);
@@ -432,11 +442,11 @@ public function getRowRecord(\Magento\Framework\DataObject $data)
432442
*/
433443
public function getExcelFile($sheetName = '')
434444
{
435-
$collection = $this->_getRowCollection();
445+
$collection = $this->_getPreparedCollection();
436446

437447
$convert = new \Magento\Framework\Convert\Excel($collection->getIterator(), [$this, 'getRowRecord']);
438448

439-
$name = md5(microtime());
449+
$name = hash('sha256', microtime());
440450
$file = $this->_path . '/' . $name . '.xml';
441451

442452
$this->_directory->create($this->_path);
@@ -551,6 +561,8 @@ public function _getPreparedCollection()
551561
}
552562

553563
/**
564+
* Get export page size
565+
*
554566
* @return int
555567
*/
556568
public function getExportPageSize()

app/code/Magento/Backend/Block/Widget/Grid/Extended.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Framework\App\Filesystem\DirectoryList;
99

1010
/**
11+
* Extended Grid Widget
12+
*
1113
* @api
1214
* @deprecated 100.2.0 in favour of UI component implementation
1315
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
@@ -177,7 +179,10 @@ class Extended extends \Magento\Backend\Block\Widget\Grid implements \Magento\Ba
177179
protected $_path = 'export';
178180

179181
/**
182+
* Initialization
183+
*
180184
* @return void
185+
* @throws \Magento\Framework\Exception\FileSystemException
181186
*/
182187
protected function _construct()
183188
{
@@ -297,6 +302,7 @@ public function addColumn($columnId, $column)
297302
);
298303
$this->getColumnSet()->getChildBlock($columnId)->setGrid($this);
299304
} else {
305+
// phpcs:ignore Magento2.Exceptions.DirectThrow
300306
throw new \Exception(__('Please correct the column format and try again.'));
301307
}
302308

@@ -471,10 +477,6 @@ protected function _prepareMassactionColumn()
471477
protected function _prepareCollection()
472478
{
473479
if ($this->getCollection()) {
474-
if ($this->getCollection()->isLoaded()) {
475-
$this->getCollection()->clear();
476-
}
477-
478480
parent::_prepareCollection();
479481

480482
if (!$this->_isExport) {
@@ -663,6 +665,7 @@ public function setEmptyCellLabel($label)
663665
*/
664666
public function getRowUrl($item)
665667
{
668+
// phpstan:ignore "Call to an undefined static method"
666669
$res = parent::getRowUrl($item);
667670
return $res ? $res : '#';
668671
}
@@ -680,6 +683,7 @@ public function getMultipleRows($item)
680683

681684
/**
682685
* Retrieve columns for multiple rows
686+
*
683687
* @return array
684688
*/
685689
public function getMultipleRowColumns()
@@ -943,6 +947,7 @@ protected function _getExportTotals()
943947

944948
/**
945949
* Iterate collection and call callback method per item
950+
*
946951
* For callback method first argument always is item object
947952
*
948953
* @param string $callback
@@ -972,7 +977,12 @@ public function _exportIterateCollection($callback, array $args)
972977
$page++;
973978

974979
foreach ($collection as $item) {
975-
call_user_func_array([$this, $callback], array_merge([$item], $args));
980+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
981+
call_user_func_array(
982+
[$this, $callback],
983+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
984+
array_merge([$item], $args)
985+
);
976986
}
977987
}
978988
}
@@ -1009,6 +1019,7 @@ public function getCsvFile()
10091019
$this->_isExport = true;
10101020
$this->_prepareGrid();
10111021

1022+
// phpcs:ignore Magento2.Security.InsecureFunction
10121023
$name = md5(microtime());
10131024
$file = $this->_path . '/' . $name . '.csv';
10141025

@@ -1153,6 +1164,7 @@ public function getExcelFile($sheetName = '')
11531164
[$this, 'getRowRecord']
11541165
);
11551166

1167+
// phpcs:ignore Magento2.Security.InsecureFunction
11561168
$name = md5(microtime());
11571169
$file = $this->_path . '/' . $name . '.xml';
11581170

@@ -1244,7 +1256,7 @@ public function setCollection($collection)
12441256
}
12451257

12461258
/**
1247-
* get collection object
1259+
* Get collection object
12481260
*
12491261
* @return \Magento\Framework\Data\Collection
12501262
*/

app/code/Magento/Backend/Model/Auth/Session.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
*/
66
namespace Magento\Backend\Model\Auth;
77

8+
use Magento\Framework\App\ObjectManager;
89
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
910
use Magento\Framework\Stdlib\CookieManagerInterface;
11+
use Magento\Framework\Message\ManagerInterface;
1012

1113
/**
1214
* Backend Auth session model
@@ -56,6 +58,11 @@ class Session extends \Magento\Framework\Session\SessionManager implements \Mage
5658
*/
5759
protected $_config;
5860

61+
/**
62+
* @var ManagerInterface
63+
*/
64+
private $messageManager;
65+
5966
/**
6067
* @param \Magento\Framework\App\Request\Http $request
6168
* @param \Magento\Framework\Session\SidResolverInterface $sidResolver
@@ -69,6 +76,7 @@ class Session extends \Magento\Framework\Session\SessionManager implements \Mage
6976
* @param \Magento\Framework\Acl\Builder $aclBuilder
7077
* @param \Magento\Backend\Model\UrlInterface $backendUrl
7178
* @param \Magento\Backend\App\ConfigInterface $config
79+
* @param ManagerInterface $messageManager
7280
* @throws \Magento\Framework\Exception\SessionException
7381
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
7482
*/
@@ -84,11 +92,13 @@ public function __construct(
8492
\Magento\Framework\App\State $appState,
8593
\Magento\Framework\Acl\Builder $aclBuilder,
8694
\Magento\Backend\Model\UrlInterface $backendUrl,
87-
\Magento\Backend\App\ConfigInterface $config
95+
\Magento\Backend\App\ConfigInterface $config,
96+
ManagerInterface $messageManager = null
8897
) {
8998
$this->_config = $config;
9099
$this->_aclBuilder = $aclBuilder;
91100
$this->_backendUrl = $backendUrl;
101+
$this->messageManager = $messageManager ?? ObjectManager::getInstance()->get(ManagerInterface::class);
92102
parent::__construct(
93103
$request,
94104
$sidResolver,
@@ -171,6 +181,25 @@ public function isLoggedIn()
171181
*/
172182
public function prolong()
173183
{
184+
$sessionUser = $this->getUser();
185+
$errorMessage = '';
186+
if ($sessionUser !== null) {
187+
if ((int)$sessionUser->getIsActive() !== 1) {
188+
$errorMessage = 'The account sign-in was incorrect or your account is disabled temporarily. '
189+
. 'Please wait and try again later.';
190+
}
191+
if (!$sessionUser->hasAssigned2Role($sessionUser->getId())) {
192+
$errorMessage = 'More permissions are needed to access this.';
193+
}
194+
195+
if (!empty($errorMessage)) {
196+
$this->destroy();
197+
$this->messageManager->addErrorMessage(__($errorMessage));
198+
199+
return;
200+
}
201+
}
202+
174203
$lifetime = $this->_config->getValue(self::XML_PATH_SESSION_LIFETIME);
175204
$cookieValue = $this->cookieManager->getCookie($this->getName());
176205

app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/ExtendedTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public function testPrepareLoadedCollection()
3232
$layout->expects($this->any())->method('getBlock')->will($this->returnValue($columnSet));
3333

3434
$collection = $this->createMock(\Magento\Framework\Data\Collection::class);
35-
$collection->expects($this->atLeastOnce())->method('isLoaded')->will($this->returnValue(true));
36-
$collection->expects($this->atLeastOnce())->method('clear');
35+
$collection->expects($this->never())->method('isLoaded');
36+
$collection->expects($this->never())->method('clear');
3737
$collection->expects($this->atLeastOnce())->method('load');
3838

3939
/** @var \Magento\Backend\Block\Widget\Grid\Extended $block */

0 commit comments

Comments
 (0)