Skip to content

Commit 8c0b621

Browse files
authored
Merge pull request #4261 from magento-tsg/2.2.9-develop-pr99
[TSG] Fixes for 2.2.9 (pr99) (2.2.9-develop)
2 parents a270d71 + 7830a90 commit 8c0b621

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
@@ -75,7 +75,7 @@ protected function _isAllowed()
7575
{
7676
$sectionId = $this->_request->getParam('section');
7777
return parent::_isAllowed()
78-
&& $this->_configStructure->getElement($sectionId)->isAllowed();
78+
|| $this->_configStructure->getElement($sectionId)->isAllowed();
7979
}
8080

8181
/**

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(): bool
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 = $fieldPaths[$fieldPath][0] ?? $sectionId;
81+
$explodedConfigPath = explode('/', $fieldPath);
82+
$configSectionId = $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(array $elements, string $fieldPath): string
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
*
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)
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)