Skip to content

Commit 0ec5ddf

Browse files
author
ogorkun
committed
Merge branch 'MC-36790' of https://github.com/magento-qwerty/magento2ce into MC-36790
2 parents b03eaa9 + f3dd77d commit 0ec5ddf

File tree

208 files changed

+14587
-3847
lines changed

Some content is hidden

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

208 files changed

+14587
-3847
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ protected function add(UserContextInterface $userContext)
5656
}
5757

5858
/**
59-
* {@inheritdoc}
59+
* @inheritDoc
6060
*/
6161
public function getUserId()
6262
{
6363
return $this->getUserContext() ? $this->getUserContext()->getUserId() : null;
6464
}
6565

6666
/**
67-
* {@inheritdoc}
67+
* @inheritDoc
6868
*/
6969
public function getUserType()
7070
{
@@ -78,7 +78,7 @@ public function getUserType()
7878
*/
7979
protected function getUserContext()
8080
{
81-
if ($this->chosenUserContext === null) {
81+
if (!$this->chosenUserContext) {
8282
/** @var UserContextInterface $userContext */
8383
foreach ($this->userContexts as $userContext) {
8484
if ($userContext->getUserType() && $userContext->getUserId() !== null) {

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/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/view/adminhtml/web/js/media-uploader.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ define([
3737
progressTmpl = mageTemplate('[data-template="uploader"]'),
3838
isResizeEnabled = this.options.isResizeEnabled,
3939
resizeConfiguration = {
40-
action: 'resize',
40+
action: 'resizeImage',
4141
maxWidth: this.options.maxWidth,
4242
maxHeight: this.options.maxHeight
4343
};
4444

4545
if (!isResizeEnabled) {
4646
resizeConfiguration = {
47-
action: 'resize'
47+
action: 'resizeImage'
4848
};
4949
}
5050

@@ -131,13 +131,13 @@ define([
131131
});
132132

133133
this.element.find('input[type=file]').fileupload('option', {
134-
process: [{
135-
action: 'load',
134+
processQueue: [{
135+
action: 'loadImage',
136136
fileTypes: /^image\/(gif|jpeg|png)$/
137137
},
138138
resizeConfiguration,
139139
{
140-
action: 'save'
140+
action: 'saveImage'
141141
}]
142142
});
143143
}

app/code/Magento/Captcha/Model/DefaultModel.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
namespace Magento\Captcha\Model;
99

10+
use Magento\Authorization\Model\UserContextInterface;
1011
use Magento\Captcha\Helper\Data;
12+
use Magento\Framework\App\ObjectManager;
1113
use Magento\Framework\Math\Random;
1214

1315
/**
@@ -93,27 +95,35 @@ class DefaultModel extends \Zend\Captcha\Image implements \Magento\Captcha\Model
9395
*/
9496
private $randomMath;
9597

98+
/**
99+
* @var UserContextInterface
100+
*/
101+
private $userContext;
102+
96103
/**
97104
* @param \Magento\Framework\Session\SessionManagerInterface $session
98105
* @param \Magento\Captcha\Helper\Data $captchaData
99106
* @param ResourceModel\LogFactory $resLogFactory
100107
* @param string $formId
101-
* @param Random $randomMath
108+
* @param Random|null $randomMath
109+
* @param UserContextInterface|null $userContext
102110
* @throws \Zend\Captcha\Exception\ExtensionNotLoadedException
103111
*/
104112
public function __construct(
105113
\Magento\Framework\Session\SessionManagerInterface $session,
106114
\Magento\Captcha\Helper\Data $captchaData,
107115
\Magento\Captcha\Model\ResourceModel\LogFactory $resLogFactory,
108116
$formId,
109-
Random $randomMath = null
117+
Random $randomMath = null,
118+
?UserContextInterface $userContext = null
110119
) {
111120
parent::__construct();
112121
$this->session = $session;
113122
$this->captchaData = $captchaData;
114123
$this->resLogFactory = $resLogFactory;
115124
$this->formId = $formId;
116-
$this->randomMath = $randomMath ?? \Magento\Framework\App\ObjectManager::getInstance()->get(Random::class);
125+
$this->randomMath = $randomMath ?? ObjectManager::getInstance()->get(Random::class);
126+
$this->userContext = $userContext ?? ObjectManager::getInstance()->get(UserContextInterface::class);
117127
}
118128

119129
/**
@@ -152,6 +162,7 @@ public function isRequired($login = null)
152162
$this->formId,
153163
$this->getTargetForms()
154164
)
165+
|| $this->userContext->getUserType() === UserContextInterface::USER_TYPE_INTEGRATION
155166
) {
156167
return false;
157168
}
@@ -241,7 +252,7 @@ private function isOverLimitLoginAttempts($login)
241252
*/
242253
private function isUserAuth()
243254
{
244-
return $this->session->isLoggedIn();
255+
return $this->session->isLoggedIn() || $this->userContext->getUserId();
245256
}
246257

247258
/**
@@ -427,7 +438,7 @@ public function getWordLen()
427438
$to = self::DEFAULT_WORD_LENGTH_TO;
428439
}
429440

430-
return \Magento\Framework\Math\Random::getRandomNumber($from, $to);
441+
return Random::getRandomNumber($from, $to);
431442
}
432443

433444
/**
@@ -544,7 +555,7 @@ private function clearWord()
544555
*/
545556
protected function randomSize()
546557
{
547-
return \Magento\Framework\Math\Random::getRandomNumber(280, 300) / 100;
558+
return Random::getRandomNumber(280, 300) / 100;
548559
}
549560

550561
/**

app/code/Magento/Captcha/Observer/CaptchaStringResolver.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\Captcha\Observer;
710

811
use Magento\Framework\App\RequestInterface;
912
use Magento\Framework\App\Request\Http as HttpRequest;
13+
use Magento\Captcha\Helper\Data as CaptchaHelper;
1014

1115
/**
1216
* Extract given captcha word.
@@ -22,12 +26,13 @@ class CaptchaStringResolver
2226
*/
2327
public function resolve(RequestInterface $request, $formId)
2428
{
25-
$captchaParams = $request->getPost(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE);
29+
$value = '';
30+
$captchaParams = $request->getPost(CaptchaHelper::INPUT_NAME_FIELD_VALUE);
2631
if (!empty($captchaParams) && !empty($captchaParams[$formId])) {
2732
$value = $captchaParams[$formId];
28-
} else {
29-
//For Web APIs
30-
$value = $request->getHeader('X-Captcha');
33+
} elseif ($headerValue = $request->getHeader('X-Captcha')) {
34+
//CAPTCHA was provided via header for this XHR/web API request.
35+
$value = $headerValue;
3136
}
3237

3338
return $value;

0 commit comments

Comments
 (0)