Verified Commit 2d6632bb authored by Côme Chilliet's avatar Côme Chilliet
Browse files

🚑 fix(systems) Improve template support for new interfaces

issue #6039
parent 7c7625eb
......@@ -35,8 +35,17 @@ class InterfacesAttribute extends Attribute
$this->plugin = $plugin;
}
function renderAttribute (array &$attributes, bool $readOnly, bool $readable, bool $writable)
//~ function renderAttribute (array &$attributes, bool $readOnly, bool $readable, bool $writable)
//~ {
Please register or sign in to reply
//~ }
function renderFormInput (): string
{
$value = $this->getValue();
if (is_array($value)) {
$value = join(', ', $value);
}
return '{literal}'.htmlescape($value).'{/literal}';
}
function getValue ()
......
......@@ -308,12 +308,14 @@ class interfacesManagement extends management implements SimpleTab
$macAddress = [];
$ipHostNumber = [];
foreach ($entryIterator as $entry) {
if (!empty($entry['macAddress'])) {
array_push($macAddress, ...$entry['macAddress']);
}
if (!empty($entry['ipHostNumber'])) {
array_push($ipHostNumber, ...$entry['ipHostNumber']);
if (!$this->is_template) {
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));
......
......@@ -112,7 +112,25 @@ class networkInterface extends simplePlugin
}
}
function vlanChanged ()
/* Override setTemplate method to hide the _template_cn special field */
public function setTemplate (bool $bool)
{
$this->is_template = $bool;
if ($this->is_template && $this->mainTab) {
$this->attributesInfo['main']['attrs']['_template_cn'] = new HiddenAttribute(
_('Template name'), _('This is the name of the template'),
'_template_cn', TRUE,
'', 'template_cn'
);
$this->attributesAccess['_template_cn'] =& $this->attributesInfo['main']['attrs']['_template_cn'];
$this->attributesAccess['_template_cn']->setInLdap(FALSE);
$this->attributesAccess['_template_cn']->setValue($this->_template_cn);
$this->attributesAccess['_template_cn']->setParent($this);
unset($this->_template_cn);
}
}
public function vlanChanged ()
{
if ($this->fdNetworkInterfaceVlanDN != '') {
/* List subnets associated to our VLAN */
......
......@@ -314,17 +314,17 @@ class fdRestService extends fdRPCService
$object = $tabobject->by_object[$tab];
//~ if (!is_subclass_of($object, 'simplePlugin')) {
//~ throw new WebServiceError('Invalid tab', 501);
//~ }
if (!is_subclass_of($object, 'SimpleTab')) {
throw new WebServiceError('Invalid tab', 501);
}
if (!isset($object->attributesAccess[$attribute])) {
throw new WebServiceError('Unknown attribute', 404);
}
//~ if (!$object->attrIsReadable($attribute)) {
//~ throw new WebServiceError('Not enough rights to read "'.$attribute.'"', 403);
//~ }
if (!$object->attrIsReadable($attribute)) {
throw new WebServiceError('Not enough rights to read "'.$attribute.'"', 403);
}
if (!$object->isActive()) {
throw new WebServiceError(sprintf('Tab "%s" is inactive', $tab));
......
  • SonarQube analysis reported 3 issues

    • 3 major

    Watch the comments in this conversation to review them.

    2 extra issues

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. Take the required action to fix the issue indicated by this "FIXME" comment. 📘
    2. Take the required action to fix the issue indicated by this "FIXME" comment. 📘
Markdown is supported
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