Skip to content

Commit e0961f5

Browse files
author
Ji Lu
committed
MAGETWO-15665: Added validation for Developer Client Restriction field
1 parent 1c6faea commit e0961f5

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AllowedIps extends \Magento\Framework\App\Config\Value
1515
/**
1616
* @var \Magento\Framework\Message\ManagerInterface
1717
*/
18-
protected $messageManager;
18+
private $messageManager;
1919

2020
/**
2121
* Constructor
@@ -48,33 +48,33 @@ public function __construct(
4848
*/
4949
public function beforeSave()
5050
{
51-
parent::beforeSave();
52-
$fieldSetData = $this->getFieldsetDataValue('allow_ips');
53-
$noticeMsg = '';
54-
$allowedIps = '';
51+
$allowedIpsRaw = $this->getFieldsetDataValue('allow_ips');
52+
$noticeMsgArray = [];
53+
$allowedIpsArray = [];
5554

56-
if (empty($fieldSetData)) {
57-
return $this;
55+
if (empty($allowedIpsRaw)) {
56+
return parent::beforeSave();
5857
}
5958

60-
$dataArray = preg_split('#\s*,\s*#', $fieldSetData, null, PREG_SPLIT_NO_EMPTY);
59+
$dataArray = preg_split('#\s*,\s*#', $allowedIpsRaw, null, PREG_SPLIT_NO_EMPTY);
6160
foreach ($dataArray as $k => $data) {
6261
$data = trim(preg_replace('/\s+/','', $data));
63-
if ( !filter_var($data, FILTER_VALIDATE_IP) === false ) {
64-
$allowedIps .= (empty($allowedIps)) ? $data : "," . $data;
62+
if ( filter_var($data, FILTER_VALIDATE_IP) ) {
63+
$allowedIpsArray[] = $data;
6564
} else {
66-
$noticeMsg .= (empty($noticeMsg)) ? $data : "," . $data;
65+
$noticeMsgArray[] = $data;
6766
}
6867
}
6968

70-
if (!empty($noticeMsg))
69+
$noticeMsg = implode(',', $noticeMsgArray);
70+
if (!empty($noticeMsgArray))
7171
$this->messageManager->addNotice(
7272
__(
73-
'Invalid values ' . $noticeMsg . ' are not saved.'
73+
__('The following invalid values cannot be saved: %values', ['values' => $noticeMsg])
7474
)
7575
);
7676

77-
$this->setValue($allowedIps);
78-
return $this;
77+
$this->setValue(implode(',', $allowedIpsArray));
78+
return parent::beforeSave();
7979
}
8080
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
namespace Magento\Developer\Test\Unit\Model\Config\Backend;
77

8-
use Magento\Developer\Model\Config\Backend\AllowedIps;
98
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
109

1110
/**
@@ -55,11 +54,6 @@ protected function setUp()
5554
);
5655
}
5756

58-
protected function tearDown()
59-
{
60-
$this->model = null;
61-
}
62-
6357
/**
6458
* @param array $fieldSetData
6559
* @param string $expected

0 commit comments

Comments
 (0)