Skip to content

Commit 3aa9070

Browse files
committed
Merge remote-tracking branch 'origin/MC-16370' into 2.3.2-develop-pr52
2 parents 2391741 + dd2b8fc commit 3aa9070

File tree

3 files changed

+144
-1
lines changed

3 files changed

+144
-1
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
@@ -77,7 +77,7 @@ protected function _isAllowed()
7777
{
7878
$sectionId = $this->_request->getParam('section');
7979
return parent::_isAllowed()
80-
&& $this->_configStructure->getElement($sectionId)->isAllowed();
80+
|| $this->_configStructure->getElement($sectionId)->isAllowed();
8181
}
8282

8383
/**

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

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

59+
/**
60+
* @inheritdoc
61+
*/
62+
protected function _isAllowed()
63+
{
64+
return parent::_isAllowed() && $this->isSectionAllowed();
65+
}
66+
67+
/**
68+
* Checks if user has access to section.
69+
*
70+
* @return bool
71+
*/
72+
private function isSectionAllowed(): bool
73+
{
74+
$sectionId = $this->_request->getParam('section');
75+
$isAllowed = $this->_configStructure->getElement($sectionId)->isAllowed();
76+
if (!$isAllowed) {
77+
$groups = $this->getRequest()->getPost('groups');
78+
$fieldPath = $this->getFirstFieldPath($groups, $sectionId);
79+
80+
$fieldPaths = $this->_configStructure->getFieldPaths();
81+
$fieldPath = $fieldPaths[$fieldPath][0] ?? $sectionId;
82+
$explodedConfigPath = explode('/', $fieldPath);
83+
$configSectionId = $explodedConfigPath[0] ?? $sectionId;
84+
85+
$isAllowed = $this->_configStructure->getElement($configSectionId)->isAllowed();
86+
}
87+
88+
return $isAllowed;
89+
}
90+
91+
/**
92+
* Return field path as string.
93+
*
94+
* @param array $elements
95+
* @param string $fieldPath
96+
* @return string
97+
*/
98+
private function getFirstFieldPath(array $elements, string $fieldPath): string
99+
{
100+
$groupData = [];
101+
foreach ($elements as $elementName => $element) {
102+
if (!empty($element)) {
103+
$fieldPath .= '/' . $elementName;
104+
105+
if (!empty($element['fields'])) {
106+
$groupData = $element['fields'];
107+
} elseif (!empty($element['groups'])) {
108+
$groupData = $element['groups'];
109+
}
110+
111+
if (!empty($groupData)) {
112+
$fieldPath = $this->getFirstFieldPath($groupData, $fieldPath);
113+
}
114+
break;
115+
}
116+
}
117+
118+
return $fieldPath;
119+
}
120+
59121
/**
60122
* Get groups for save
61123
*
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Paypal\Controller\Adminhtml\System;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\App\Request\Http as HttpRequest;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
/**
15+
* @magentoAppArea adminhtml
16+
*/
17+
class ConfigTest extends \Magento\TestFramework\TestCase\AbstractBackendController
18+
{
19+
/**
20+
* @magentoAppIsolation enabled
21+
* @magentoDbIsolation enabled
22+
*
23+
* @dataProvider saveMerchantCountryDataProvider
24+
*
25+
* @param string $section
26+
* @param array $groups
27+
* @return void
28+
*/
29+
public function testSaveMerchantCountry(string $section, array $groups): void
30+
{
31+
/** @var ScopeConfigInterface $scopeConfig */
32+
$scopeConfig = Bootstrap::getObjectManager()->get(ScopeConfigInterface::class);
33+
34+
$request = $this->getRequest();
35+
$request->setPostValue($groups)
36+
->setParam('section', $section)
37+
->setMethod(HttpRequest::METHOD_POST);
38+
39+
$this->dispatch('backend/admin/system_config/save');
40+
41+
$this->assertSessionMessages($this->equalTo(['You saved the configuration.']));
42+
43+
$this->assertEquals(
44+
'GB',
45+
$scopeConfig->getValue('paypal/general/merchant_country')
46+
);
47+
}
48+
49+
/**
50+
* @return array
51+
*/
52+
public function saveMerchantCountryDataProvider(): array
53+
{
54+
return [
55+
[
56+
'section' => 'paypal',
57+
'groups' => [
58+
'groups' => [
59+
'general' => [
60+
'fields' => [
61+
'merchant_country' => ['value' => 'GB'],
62+
],
63+
],
64+
],
65+
],
66+
],
67+
[
68+
'section' => 'payment',
69+
'groups' => [
70+
'groups' => [
71+
'account' => [
72+
'fields' => [
73+
'merchant_country' => ['value' => 'GB'],
74+
],
75+
],
76+
],
77+
],
78+
],
79+
];
80+
}
81+
}

0 commit comments

Comments
 (0)