mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-29 16:54:06 +02:00
HostController: Move ServiceFinder::getRedirectionUrl() method code to findserviceAction()
- This helps to detect backend easily, and was only called in this method anyway. - Add and use helping method getServicesReadOnlyPermission() -
This commit is contained in:
parent
4e6528e862
commit
8a489bcc46
@ -4,6 +4,8 @@ namespace Icinga\Module\Director\Controllers;
|
|||||||
|
|
||||||
use gipfl\Web\Widget\Hint;
|
use gipfl\Web\Widget\Hint;
|
||||||
use Icinga\Module\Director\Auth\Permission;
|
use Icinga\Module\Director\Auth\Permission;
|
||||||
|
use Icinga\Module\Director\Integration\Icingadb\IcingadbBackend;
|
||||||
|
use Icinga\Module\Director\Integration\MonitoringModule\Monitoring;
|
||||||
use Icinga\Module\Director\Web\Table\ObjectsTableService;
|
use Icinga\Module\Director\Web\Table\ObjectsTableService;
|
||||||
use ipl\Html\Html;
|
use ipl\Html\Html;
|
||||||
use gipfl\IcingaWeb2\Link;
|
use gipfl\IcingaWeb2\Link;
|
||||||
@ -39,7 +41,7 @@ class HostController extends ObjectController
|
|||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($auth->hasPermission(Permission::MONITORING_SERVICES_RO) && $this->isServicesReadOnlyAction()) {
|
if ($this->isServicesReadOnlyAction() && $auth->hasPermission($this->getServicesReadOnlyPermission())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($auth->hasPermission(Permission::HOSTS)) { // faster
|
if ($auth->hasPermission(Permission::HOSTS)) { // faster
|
||||||
@ -136,11 +138,35 @@ class HostController extends ObjectController
|
|||||||
|
|
||||||
public function findserviceAction()
|
public function findserviceAction()
|
||||||
{
|
{
|
||||||
|
$auth = $this->Auth();
|
||||||
$host = $this->getHostObject();
|
$host = $this->getHostObject();
|
||||||
$this->redirectNow(
|
$hostName = $host->getObjectName();
|
||||||
(new ServiceFinder($host, $this->getAuth()))
|
$serviceName = $this->params->get('service');
|
||||||
->getRedirectionUrl($this->params->get('service'))
|
$info = ServiceFinder::find($host, $serviceName);
|
||||||
);
|
$backend = $this->backend();
|
||||||
|
|
||||||
|
if ($info && $auth->hasPermission(Permission::HOSTS)) {
|
||||||
|
$redirectUrl = $info->getUrl();
|
||||||
|
} elseif ($info
|
||||||
|
&& (($backend instanceof Monitoring && $auth->hasPermission(Permission::MONITORING_HOSTS))
|
||||||
|
|| ($backend instanceof IcingadbBackend && $auth->hasPermission(Permission::ICINGADB_HOSTS))
|
||||||
|
)
|
||||||
|
&& $backend->canModifyService($hostName, $serviceName)
|
||||||
|
) {
|
||||||
|
$redirectUrl = $info->getUrl();
|
||||||
|
} elseif ($auth->hasPermission($this->getServicesReadOnlyPermission())) {
|
||||||
|
$redirectUrl = Url::fromPath('director/host/servicesro', [
|
||||||
|
'name' => $hostName,
|
||||||
|
'service' => $serviceName
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$redirectUrl = Url::fromPath('director/host/invalidservice', [
|
||||||
|
'name' => $hostName,
|
||||||
|
'service' => $serviceName,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->redirectNow($redirectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -263,7 +289,7 @@ class HostController extends ObjectController
|
|||||||
*/
|
*/
|
||||||
public function servicesroAction()
|
public function servicesroAction()
|
||||||
{
|
{
|
||||||
$this->assertPermission(Permission::MONITORING_SERVICES_RO);
|
$this->assertPermission($this->getServicesReadOnlyPermission());
|
||||||
$host = $this->getHostObject();
|
$host = $this->getHostObject();
|
||||||
$service = $this->params->getRequired('service');
|
$service = $this->params->getRequired('service');
|
||||||
$db = $this->db();
|
$db = $this->db();
|
||||||
@ -618,4 +644,16 @@ class HostController extends ObjectController
|
|||||||
}
|
}
|
||||||
return $this->object;
|
return $this->object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get readOnly permission of the service for the current backend
|
||||||
|
*
|
||||||
|
* @return string permission
|
||||||
|
*/
|
||||||
|
protected function getServicesReadOnlyPermission(): string
|
||||||
|
{
|
||||||
|
return $this->backend() instanceof IcingadbBackend
|
||||||
|
? Permission::ICINGADB_SERVICES_RO
|
||||||
|
: Permission::MONITORING_SERVICES_RO;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,38 +51,4 @@ class ServiceFinder
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $serviceName
|
|
||||||
* @return Url
|
|
||||||
*/
|
|
||||||
public function getRedirectionUrl($serviceName)
|
|
||||||
{
|
|
||||||
if ($this->auth === null) {
|
|
||||||
throw new RuntimeException('Auth is required for ServiceFinder when dealing when asking for URLs');
|
|
||||||
}
|
|
||||||
if ($this->auth->hasPermission(Permission::HOSTS)) {
|
|
||||||
if ($info = $this::find($this->host, $serviceName)) {
|
|
||||||
return $info->getUrl();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($this->auth->hasPermission(Permission::MONITORING_HOSTS)) {
|
|
||||||
if ($info = $this::find($this->host, $serviceName)) {
|
|
||||||
if ((new Monitoring())->canModifyService($this->host->getObjectName(), $serviceName)) {
|
|
||||||
return $info->getUrl();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($this->auth->hasPermission(Permission::MONITORING_SERVICES_RO)) {
|
|
||||||
return Url::fromPath('director/host/servicesro', [
|
|
||||||
'name' => $this->host->getObjectName(),
|
|
||||||
'service' => $serviceName
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Url::fromPath('director/host/invalidservice', [
|
|
||||||
'name' => $this->host->getObjectName(),
|
|
||||||
'service' => $serviceName,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user