Merge branch 'bugfix/wrong-url-makes-whole-dashboard-unusable-11920'
fixes #11920
This commit is contained in:
commit
4398267db5
|
@ -3,10 +3,11 @@
|
||||||
|
|
||||||
namespace Icinga\Forms\Dashboard;
|
namespace Icinga\Forms\Dashboard;
|
||||||
|
|
||||||
use Icinga\Web\Widget\Dashboard;
|
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
|
use Icinga\Web\Form\Validator\InternalUrlValidator;
|
||||||
use Icinga\Web\Form\Validator\UrlValidator;
|
use Icinga\Web\Form\Validator\UrlValidator;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
|
use Icinga\Web\Widget\Dashboard;
|
||||||
use Icinga\Web\Widget\Dashboard\Dashlet;
|
use Icinga\Web\Widget\Dashboard\Dashlet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,7 +71,7 @@ class DashletForm extends Form
|
||||||
'description' => $this->translate(
|
'description' => $this->translate(
|
||||||
'Enter url being loaded in the dashlet. You can paste the full URL, including filters.'
|
'Enter url being loaded in the dashlet. You can paste the full URL, including filters.'
|
||||||
),
|
),
|
||||||
'validators' => array(new UrlValidator())
|
'validators' => array(new UrlValidator(), new InternalUrlValidator())
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
|
namespace Icinga\Web\Form\Validator;
|
||||||
|
|
||||||
|
use Zend_Validate_Abstract;
|
||||||
|
use Icinga\Web\Url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator that checks whether a textfield doesn't contain an external URL
|
||||||
|
*/
|
||||||
|
class InternalUrlValidator extends Zend_Validate_Abstract
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function isValid($value)
|
||||||
|
{
|
||||||
|
if (Url::fromPath($value)->isExternal()) {
|
||||||
|
$this->_error('IS_EXTERNAL');
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function _error($messageKey, $value = null)
|
||||||
|
{
|
||||||
|
if ($messageKey === 'IS_EXTERNAL') {
|
||||||
|
$this->_messages[$messageKey] = t('The url must not be external.');
|
||||||
|
} else {
|
||||||
|
parent::_error($messageKey, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue