mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-28 16:24:04 +02:00
NavigationConfigForm: Fix name validation when adding or editing items
refs #5600
This commit is contained in:
parent
cd1510d846
commit
3f22469c18
@ -279,11 +279,13 @@ class NavigationConfigForm extends ConfigForm
|
|||||||
throw new InvalidArgumentException('Key \'name\' missing');
|
throw new InvalidArgumentException('Key \'name\' missing');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$shared = false;
|
||||||
$config = $this->getUserConfig();
|
$config = $this->getUserConfig();
|
||||||
if ((isset($data['users']) && $data['users']) || (isset($data['groups']) && $data['groups'])) {
|
if ((isset($data['users']) && $data['users']) || (isset($data['groups']) && $data['groups'])) {
|
||||||
if ($this->getUser()->can('application/share/navigation')) {
|
if ($this->getUser()->can('application/share/navigation')) {
|
||||||
$data['owner'] = $this->getUser()->getUsername();
|
$data['owner'] = $this->getUser()->getUsername();
|
||||||
$config = $this->getShareConfig();
|
$config = $this->getShareConfig();
|
||||||
|
$shared = true;
|
||||||
} else {
|
} else {
|
||||||
unset($data['users']);
|
unset($data['users']);
|
||||||
unset($data['groups']);
|
unset($data['groups']);
|
||||||
@ -291,10 +293,24 @@ class NavigationConfigForm extends ConfigForm
|
|||||||
} elseif (isset($data['parent']) && $data['parent'] && $this->hasBeenShared($data['parent'])) {
|
} elseif (isset($data['parent']) && $data['parent'] && $this->hasBeenShared($data['parent'])) {
|
||||||
$data['owner'] = $this->getUser()->getUsername();
|
$data['owner'] = $this->getUser()->getUsername();
|
||||||
$config = $this->getShareConfig();
|
$config = $this->getShareConfig();
|
||||||
|
$shared = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$itemName = $data['name'];
|
$itemName = $data['name'];
|
||||||
if ($config->hasSection($itemName) || $this->getUserConfig()->hasSection($itemName)) {
|
$exists = $config->hasSection($itemName);
|
||||||
|
if (! $exists) {
|
||||||
|
if ($shared) {
|
||||||
|
$exists = $this->getUserConfig()->hasSection($itemName);
|
||||||
|
} else {
|
||||||
|
$exists = (bool) $this->getShareConfig()
|
||||||
|
->select()
|
||||||
|
->where('name', $itemName)
|
||||||
|
->where('owner', $this->getUser()->getUsername())
|
||||||
|
->count();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($exists) {
|
||||||
throw new IcingaException(
|
throw new IcingaException(
|
||||||
$this->translate('A navigation item with the name "%s" does already exist'),
|
$this->translate('A navigation item with the name "%s" does already exist'),
|
||||||
$itemName
|
$itemName
|
||||||
@ -361,7 +377,26 @@ class NavigationConfigForm extends ConfigForm
|
|||||||
$oldName = $name;
|
$oldName = $name;
|
||||||
$name = $data['name'];
|
$name = $data['name'];
|
||||||
|
|
||||||
if ($config->hasSection($name) || $this->getUserConfig()->hasSection($name)) {
|
$exists = $config->hasSection($name);
|
||||||
|
if (! $exists) {
|
||||||
|
$ownerName = $itemConfig->owner ?: $this->getUser()->getUsername();
|
||||||
|
if ($shared || $this->hasBeenShared($oldName)) {
|
||||||
|
if ($ownerName === $this->getUser()->getUsername()) {
|
||||||
|
$exists = $this->getUserConfig()->hasSection($name);
|
||||||
|
} else {
|
||||||
|
$owner = new User($ownerName);
|
||||||
|
$exists = $owner->loadNavigationConfig()->hasSection($name);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$exists = (bool) $this->getShareConfig()
|
||||||
|
->select()
|
||||||
|
->where('name', $name)
|
||||||
|
->where('owner', $ownerName)
|
||||||
|
->count();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($exists) {
|
||||||
throw new IcingaException(
|
throw new IcingaException(
|
||||||
$this->translate('A navigation item with the name "%s" does already exist'),
|
$this->translate('A navigation item with the name "%s" does already exist'),
|
||||||
$name
|
$name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user