Skip to content

Commit ccf4773

Browse files
authored
Merge pull request #4281 from magento-tsg/2.1.18-develop-pr76
[TSG] Backporting for 2.1 (pr76) (2.1.18-develop)
2 parents 9a54450 + 74f5e76 commit ccf4773

File tree

7 files changed

+194
-11
lines changed

7 files changed

+194
-11
lines changed

app/code/Magento/Config/Controller/Adminhtml/System/AbstractConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function _isAllowed()
6868
{
6969
$sectionId = $this->_request->getParam('section');
7070
return parent::_isAllowed()
71-
&& $this->_configStructure->getElement($sectionId)->isAllowed();
71+
|| $this->_configStructure->getElement($sectionId)->isAllowed();
7272
}
7373

7474
/**

app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,68 @@ public function __construct(
5555
$this->string = $string;
5656
}
5757

58+
/**
59+
* @inheritdoc
60+
*/
61+
protected function _isAllowed()
62+
{
63+
return parent::_isAllowed() && $this->isSectionAllowed();
64+
}
65+
66+
/**
67+
* Checks if user has access to section.
68+
*
69+
* @return bool
70+
*/
71+
private function isSectionAllowed()
72+
{
73+
$sectionId = $this->_request->getParam('section');
74+
$isAllowed = $this->_configStructure->getElement($sectionId)->isAllowed();
75+
if (!$isAllowed) {
76+
$groups = $this->getRequest()->getPost('groups');
77+
$fieldPath = $this->getFirstFieldPath($groups, $sectionId);
78+
79+
$fieldPaths = $this->_configStructure->getFieldPaths();
80+
$fieldPath = !empty($fieldPaths[$fieldPath][0]) ? $fieldPaths[$fieldPath][0] : $sectionId;
81+
$explodedConfigPath = explode('/', $fieldPath);
82+
$configSectionId = !empty($explodedConfigPath[0]) ? $explodedConfigPath[0] : $sectionId;
83+
84+
$isAllowed = $this->_configStructure->getElement($configSectionId)->isAllowed();
85+
}
86+
87+
return $isAllowed;
88+
}
89+
90+
/**
91+
* Return field path as string.
92+
*
93+
* @param array $elements
94+
* @param string $fieldPath
95+
* @return string
96+
*/
97+
private function getFirstFieldPath($elements, $fieldPath)
98+
{
99+
$groupData = [];
100+
foreach ($elements as $elementName => $element) {
101+
if (!empty($element)) {
102+
$fieldPath .= '/' . $elementName;
103+
104+
if (!empty($element['fields'])) {
105+
$groupData = $element['fields'];
106+
} elseif (!empty($element['groups'])) {
107+
$groupData = $element['groups'];
108+
}
109+
110+
if (!empty($groupData)) {
111+
$fieldPath = $this->getFirstFieldPath($groupData, $fieldPath);
112+
}
113+
break;
114+
}
115+
}
116+
117+
return $fieldPath;
118+
}
119+
58120
/**
59121
* Get groups for save
60122
*

app/code/Magento/Sales/Controller/Guest/View.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,13 @@ public function __construct(
4949

5050
/**
5151
* @return \Magento\Framework\Controller\ResultInterface
52-
* @throws \Magento\Framework\Exception\NotFoundException
5352
*/
5453
public function execute()
5554
{
56-
if (!$this->getRequest()->isPost()) {
57-
throw new \Magento\Framework\Exception\NotFoundException(__('Page not found.'));
58-
}
59-
if (!$this->formKeyValidator->validate($this->getRequest())) {
60-
return $this->resultRedirectFactory->create()->setPath('*/*/form/');
55+
if ($this->getRequest()->isPost()) {
56+
if (!$this->formKeyValidator->validate($this->getRequest())) {
57+
return $this->resultRedirectFactory->create()->setPath('*/*/form/');
58+
}
6159
}
6260

6361
$result = $this->guestHelper->loadValidOrder($this->getRequest());

app/code/Magento/Sales/Test/Unit/Controller/Guest/ViewTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,15 @@ public function testExecuteOrderNotFound()
145145

146146
/**
147147
* @return void
148-
* @expectedException \Magento\Framework\Exception\NotFoundException
149-
* @expectedExceptionMessage Page not found.
150148
*/
151149
public function testExecuteWithNonPostRequest()
152150
{
153151
$this->requestMock->expects($this->once())->method('isPost')->willReturn(false);
154152

153+
$this->resultPageFactoryMock->expects($this->once())
154+
->method('create')
155+
->willReturn($this->resultPageMock);
156+
155157
$this->viewController->execute();
156158
}
157159

app/code/Magento/Ups/view/adminhtml/templates/system/shipping/carrier_config.phtml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ require(["prototype"], function(){
6767
upsXml.prototype = {
6868
initialize: function()
6969
{
70+
this.carriersUpsActiveId = 'carriers_ups_active';
7071
this.carriersUpsTypeId = 'carriers_ups_type';
7172
if (!$(this.carriersUpsTypeId)) {
7273
return;
@@ -94,6 +95,7 @@ require(["prototype"], function(){
9495

9596
this.setFormValues();
9697
Event.observe($(this.carriersUpsTypeId), 'change', this.setFormValues.bind(this));
98+
Event.observe($(this.carriersUpsActiveId), 'change', this.setFormValues.bind(this));
9799
},
98100
updateAllowedMethods: function(originShipmentTitle)
99101
{
@@ -148,7 +150,8 @@ require(["prototype"], function(){
148150
$(this.checkingUpsXmlId[a]).removeClassName('required-entry');
149151
}
150152
for (a = 0; a < this.checkingUpsId.length; a++) {
151-
$(this.checkingUpsXmlId[a]).addClassName('required-entry');
153+
$(this.checkingUpsId[a]).addClassName('required-entry');
154+
this.changeFieldsDisabledState(this.checkingUpsId, a);
152155
}
153156
Event.stopObserving($('carriers_ups_origin_shipment'), 'change', this.changeOriginShipment.bind(this));
154157
showRowArrayElements(this.onlyUpsElements);
@@ -157,9 +160,10 @@ require(["prototype"], function(){
157160
} else {
158161
for (a = 0; a < this.checkingUpsXmlId.length; a++) {
159162
$(this.checkingUpsXmlId[a]).addClassName('required-entry');
163+
this.changeFieldsDisabledState(this.checkingUpsXmlId, a);
160164
}
161165
for (a = 0; a < this.checkingUpsId.length; a++) {
162-
$(this.checkingUpsXmlId[a]).removeClassName('required-entry');
166+
$(this.checkingUpsId[a]).removeClassName('required-entry');
163167
}
164168
Event.observe($('carriers_ups_origin_shipment'), 'change', this.changeOriginShipment.bind(this));
165169
showRowArrayElements(this.onlyUpsXmlElements);
@@ -171,6 +175,16 @@ require(["prototype"], function(){
171175
{
172176
this.originShipmentTitle = key ? key : $F('carriers_ups_origin_shipment');
173177
this.updateAllowedMethods(this.originShipmentTitle);
178+
},
179+
changeFieldsDisabledState: function (fields, key) {
180+
$(fields[key]).disabled = $F(this.carriersUpsActiveId) !== '1'
181+
|| $(fields[key] + '_inherit') !== null
182+
&& $F(fields[key] + '_inherit') === '1';
183+
184+
if ($(fields[key]).next() !== undefined) {
185+
$(fields[key]).removeClassName('mage-error').next().remove();
186+
$(fields[key]).removeAttribute('style');
187+
}
174188
}
175189
};
176190
xml = new upsXml();
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Paypal\Controller\Adminhtml\System;
8+
9+
use Magento\Framework\App\Config\ScopeConfigInterface;
10+
use Magento\Framework\App\Request\Http as HttpRequest;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
/**
14+
* @magentoAppArea adminhtml
15+
*/
16+
class ConfigTest extends \Magento\TestFramework\TestCase\AbstractBackendController
17+
{
18+
/**
19+
* @magentoAppIsolation enabled
20+
* @magentoDbIsolation enabled
21+
*
22+
* @dataProvider saveMerchantCountryDataProvider
23+
*
24+
* @param string $section
25+
* @param array $groups
26+
* @return void
27+
*/
28+
public function testSaveMerchantCountry($section, $groups)
29+
{
30+
/** @var ScopeConfigInterface $scopeConfig */
31+
$scopeConfig = Bootstrap::getObjectManager()->get(ScopeConfigInterface::class);
32+
33+
$request = $this->getRequest();
34+
$request->setPostValue($groups)
35+
->setParam('section', $section)
36+
->setMethod(HttpRequest::METHOD_POST);
37+
38+
$this->dispatch('backend/admin/system_config/save');
39+
40+
$this->assertSessionMessages($this->equalTo(['You saved the configuration.']));
41+
42+
$this->assertEquals(
43+
'GB',
44+
$scopeConfig->getValue('paypal/general/merchant_country')
45+
);
46+
}
47+
48+
/**
49+
* @return array
50+
*/
51+
public function saveMerchantCountryDataProvider()
52+
{
53+
return [
54+
[
55+
'section' => 'paypal',
56+
'groups' => [
57+
'groups' => [
58+
'general' => [
59+
'fields' => [
60+
'merchant_country' => ['value' => 'GB'],
61+
],
62+
],
63+
],
64+
],
65+
],
66+
[
67+
'section' => 'payment',
68+
'groups' => [
69+
'groups' => [
70+
'account' => [
71+
'fields' => [
72+
'merchant_country' => ['value' => 'GB'],
73+
],
74+
],
75+
],
76+
],
77+
],
78+
];
79+
}
80+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sales\Controller\Guest;
8+
9+
use Magento\TestFramework\Request;
10+
use Magento\TestFramework\TestCase\AbstractController;
11+
12+
/**
13+
* Test for \Magento\Sales\Controller\Guest\View class.
14+
*/
15+
class ViewTest extends AbstractController
16+
{
17+
/**
18+
* Check that controller applied GET requests.
19+
*/
20+
public function testExecuteWithGetRequest()
21+
{
22+
$this->getRequest()->setMethod(Request::METHOD_GET);
23+
$this->dispatch('sales/guest/view/');
24+
25+
$this->assertRedirect($this->stringContains('sales/guest/form'));
26+
}
27+
}

0 commit comments

Comments
 (0)