Skip to content

Commit 810f7b1

Browse files
author
Ji Lu
committed
MAGETWO-15665: moved the "restrict" group configuration from backend into Developer module.
1 parent e0961f5 commit 810f7b1

File tree

4 files changed

+25
-50
lines changed

4 files changed

+25
-50
lines changed

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,6 @@
154154
<label>Developer</label>
155155
<tab>advanced</tab>
156156
<resource>Magento_Backend::dev</resource>
157-
<group id="restrict" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
158-
<label>Developer Client Restrictions</label>
159-
<field id="allow_ips" translate="label comment" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
160-
<label>Allowed IPs (comma separated)</label>
161-
<comment>Leave empty for access from any location.</comment>
162-
<backend_model>Magento\Developer\Model\Config\Backend\AllowedIps</backend_model>
163-
</field>
164-
</group>
165157
<group id="debug" translate="label" type="text" sortOrder="20" showInDefault="0" showInWebsite="1" showInStore="1">
166158
<label>Debug</label>
167159
<field id="template_hints" translate="label" type="select" sortOrder="20" showInDefault="0" showInWebsite="1" showInStore="1">

app/code/Magento/Developer/Model/Config/Backend/AllowedIps.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,17 @@ public function __construct(
4848
*/
4949
public function beforeSave()
5050
{
51-
$allowedIpsRaw = $this->getFieldsetDataValue('allow_ips');
51+
$allowedIpsRaw = $this->getValue();
5252
$noticeMsgArray = [];
5353
$allowedIpsArray = [];
5454

5555
if (empty($allowedIpsRaw)) {
5656
return parent::beforeSave();
5757
}
5858

59-
$dataArray = preg_split('#\s*,\s*#', $allowedIpsRaw, null, PREG_SPLIT_NO_EMPTY);
59+
$dataArray = explode(',', $allowedIpsRaw);
6060
foreach ($dataArray as $k => $data) {
61-
$data = trim(preg_replace('/\s+/','', $data));
62-
if ( filter_var($data, FILTER_VALIDATE_IP) ) {
61+
if ( filter_var(trim($data), FILTER_VALIDATE_IP) ) {
6362
$allowedIpsArray[] = $data;
6463
} else {
6564
$noticeMsgArray[] = $data;

app/code/Magento/Developer/Test/Unit/Model/Config/Backend/AllowedIpsTest.php

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ protected function setUp()
5555
}
5656

5757
/**
58-
* @param array $fieldSetData
58+
* @param string $value
5959
* @param string $expected
6060
* @dataProvider beforeSaveDataProvider
6161
* @return void
6262
*/
63-
public function testBeforeSave($fieldSetData, $expected)
63+
public function testBeforeSave($value, $expected)
6464
{
65-
$this->assertNull($this->model->getFieldsetDataValue('allow_ips'));
66-
$this->model->setFieldsetData($fieldSetData);
65+
$this->assertNull($this->model->getValue());
66+
$this->model->setValue($value);
6767
$this->model->beforeSave();
68-
$this->assertEquals($expected, $this->model->getData('value'));
68+
$this->assertEquals($expected, trim($this->model->getValue()));
6969
}
7070

7171
/**
@@ -74,39 +74,15 @@ public function testBeforeSave($fieldSetData, $expected)
7474
public function beforeSaveDataProvider()
7575
{
7676
return [
77-
[
78-
['allow_ips' => ''],
79-
'',
80-
],
81-
[
82-
['allow_ips' => ', 10.64.206.85, 10. 64.85.206 '],
83-
'10.64.206.85,10.64.85.206',
84-
],
85-
[
86-
['allow_ips' => '10.64.206.85, 10.64.1a.x'],
87-
'10.64.206.85',
88-
],
89-
[
90-
['allow_ips' => ' 10.64. 206.85, 10.49.a. b '], /* with whitespaces */
91-
'10.64.206.85',
92-
],
93-
[
94-
['allow_ips' => '2001:db8:0:1234:0:567:8:1, '], /* valid IPV6 address */
95-
'2001:db8:0:1234:0:567:8:1',
96-
],
97-
98-
[
99-
['allow_ips' => '2001:0cb8:25a3:04c1:1324:8a2b:0471:8221'], /* valid IPV6 address */
100-
'2001:0cb8:25a3:04c1:1324:8a2b:0471:8221',
101-
],
102-
[
103-
['allow_ips' => '255.255.255.255'], /* valid private ip */
104-
'255.255.255.255',
105-
],
106-
[
107-
['allow_ips' => '127.0.0.1, ::1'], /* valid reserved ip */
108-
'127.0.0.1,::1',
109-
],
77+
[ '', '' ],
78+
[ ', 10.64.206.85, 10. 64.85.206 ', '10.64.206.85' ],
79+
[ '10.64.206.85, 10.64.1a.x, ,,', '10.64.206.85' ],
80+
[ ' ,, 10.64.206.85, 10.49.206.85 , ', '10.64.206.85, 10.49.206.85' ],
81+
[ '2001:db8:0:1234:0:567:8:1, ', '2001:db8:0:1234:0:567:8:1' ], /* valid IPV6 address */
82+
[ '2001:0cb8:25a3:04c1:1324:8a2b:0471:8221', '2001:0cb8:25a3:04c1:1324:8a2b:0471:8221'], /* valid IPV6 address */
83+
[ '255.255.255.255', '255.255.255.255'], /* valid private ip */
84+
[ '127.0.0.1, ::1', '127.0.0.1, ::1'], /* valid reserved ip */
85+
['*[789bo88n=], 12.34.56.78,[,q 049cq9840@@', '12.34.56.78']
11086
];
11187
}
11288
}

app/code/Magento/Developer/etc/adminhtml/system.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
<source_model>Magento\Developer\Model\Config\Source\WorkflowType</source_model>
1616
</field>
1717
</group>
18+
<group id="restrict" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
19+
<label>Developer Client Restrictions</label>
20+
<field id="allow_ips" translate="label comment" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
21+
<label>Allowed IPs (comma separated)</label>
22+
<comment>Leave empty for access from any location.</comment>
23+
<backend_model>Magento\Developer\Model\Config\Backend\AllowedIps</backend_model>
24+
</field>
25+
</group>
1826
</section>
1927
</system>
2028
</config>

0 commit comments

Comments
 (0)