Verified Commit 5d55120b authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:sparkles: feat(ipam) Sync System fields with interfaces IP and Macs

issue #6039
Showing with 41 additions and 6 deletions
+41 -6
......@@ -46,7 +46,6 @@ class interfacesManagement extends management implements SimpleTab
var $cn;
public static $columns = [
['ObjectTypeColumn', []],
['LinkColumn', ['attributes' => 'nameAttr', 'label' => 'Name']],
['Column', ['attributes' => 'macAddress', 'label' => 'Mac']],
['Column', ['attributes' => 'fdNetworkInterfaceVlanId', 'label' => 'VLAN id']],
......@@ -81,6 +80,8 @@ class interfacesManagement extends management implements SimpleTab
$this->parent = $parent;
parent::__construct(['networkInterface'], []);
$this->parent->getBaseObject()->setNetworkAttributesReadOnly(TRUE);
}
protected function setUpListing ()
......@@ -108,18 +109,32 @@ class interfacesManagement extends management implements SimpleTab
function save_object ()
{
// save_object of the dialog is called in management::execute
/* Sync base tab fields with interfaces */
$entryIterator = $this->listing->getIterator();
$macAddress = [];
$ipHostNumber = [];
foreach ($entryIterator as $entry) {
if (!empty($entry['macAddress'])) {
array_push($macAddress, ...$entry['macAddress']);
}
if (!empty($entry['ipHostNumber'])) {
array_push($ipHostNumber, ...$entry['ipHostNumber']);
}
}
$this->parent->getBaseObject()->macAddress = array_values(array_unique($macAddress));
$this->parent->getBaseObject()->ipHostNumber = array_values(array_unique($ipHostNumber));
}
public function remove (bool $fulldelete = FALSE): array
{
$errors = [];
return $errors;
return [];
}
public function save (): array
{
$errors = [];
return $errors;
return [];
}
/*! \brief Prepare active services to be copied.
......
......@@ -32,7 +32,8 @@ class networkInterface extends simplePlugin
'plObjectType' => ['networkInterface' => [
'name' => _('Network interface'),
'ou' => '',
'icon' => 'geticon.php?context=category&icon=network&size=16',
'icon' => 'images/empty.png',
'tabClass' => 'simpleTabs_noSpecial',
]],
'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo())
......
......@@ -25,6 +25,8 @@
*/
class ipHostPlugin extends simplePlugin
{
protected $networkAttributesReadOnly = FALSE;
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
{
global $config;
......@@ -51,4 +53,21 @@ class ipHostPlugin extends simplePlugin
}
return parent::mergeObjectClasses($objectclasses);
}
public function setNetworkAttributesReadOnly (bool $networkAttributesReadOnly)
{
$this->networkAttributesReadOnly = $networkAttributesReadOnly;
}
public function attrIsWriteable ($attr): bool
{
if (!is_object($attr)) {
$attr = $this->attributesAccess[$attr];
}
if ($this->networkAttributesReadOnly && in_array($attr->getLdapName(), ['ipHostNumber','macAddress'])) {
return FALSE;
} else {
return parent::attrIsWriteable($attr);
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment