DashboardManager: Don't raise an error when the passed name is the default home

This commit is contained in:
Yonas Habteab 2022-06-09 10:09:44 +02:00
parent 09a87f105d
commit 641e3042b3

View File

@ -28,9 +28,10 @@ trait DashboardManager
public function load(string $name = null, string $activePane = null, bool $loadAll = false) public function load(string $name = null, string $activePane = null, bool $loadAll = false)
{ {
$query = Model\Home::on(DBUtils::getConn()); $query = Model\Home::on(DBUtils::getConn());
$query->filter(Filter::equal('icingaweb_dashboard_owner.id', $this::getUser()->getAdditional('id'))); $query->filter(Filter::equal('user_id', $this::getUser()->getAdditional('id')));
$this->setEntries([]); $this->setEntries([]);
$home = null;
if ($name !== null && ! $loadAll) { if ($name !== null && ! $loadAll) {
$query->filter(Filter::equal('name', $name)); $query->filter(Filter::equal('name', $name));
@ -38,35 +39,30 @@ trait DashboardManager
if (($row = $query->first()) === null) { if (($row = $query->first()) === null) {
if ($name === DashboardHome::DEFAULT_HOME) { if ($name === DashboardHome::DEFAULT_HOME) {
$home = $this->initGetDefaultHome(); $home = $this->initGetDefaultHome();
} else {
throw new HttpNotFoundException(t('Home "%s" not found'), $name);
} }
} else { } else {
$home = DashboardHome::create($row); $home = DashboardHome::create($row);
$this->addEntry($home); $this->addEntry($home);
} }
$this->activateHome($home);
$home->loadDashboardEntries($activePane);
} else { } else {
foreach ($query as $row) { foreach ($query as $row) {
$this->addEntry(DashboardHome::create($row)); $this->addEntry(DashboardHome::create($row));
} }
}
if ($name !== null && $loadAll) { if ($name === null) {
if (! $this->hasEntry($name)) { $home = $this->rewindEntries();
throw new HttpNotFoundException(t('Home "%s" not found'), $name); } elseif (! $home && $name === DashboardHome::DEFAULT_HOME) {
} $home = $this->initGetDefaultHome();
} elseif (! $home && $this->hasEntry($name)) {
$home = $this->getEntry($name);
} elseif (! $home) {
throw new HttpNotFoundException(t('Home "%s" not found'), $name);
}
$firstHome = $this->getEntry($name); if ($home) {
} else { $this->activateHome($home);
$firstHome = $this->rewindEntries(); $home->loadDashboardEntries($activePane);
}
if ($firstHome) {
$this->activateHome($firstHome);
$firstHome->loadDashboardEntries($activePane);
}
} }
if (Icinga::app()->isWeb()) { if (Icinga::app()->isWeb()) {
@ -122,7 +118,7 @@ trait DashboardManager
* *
* @return ?DashboardHome * @return ?DashboardHome
*/ */
public function getActiveHome() public function getActiveHome(): ?DashboardHome
{ {
/** @var DashboardHome $home */ /** @var DashboardHome $home */
foreach ($this->getEntries() as $home) { foreach ($this->getEntries() as $home) {