mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 15:54:03 +02:00
Merge pull request #2754 from Icinga/feature/api-call-to-add-announcement-2749
Support creating announcements via API
This commit is contained in:
commit
42c7c3ae7a
@ -447,7 +447,9 @@ class ActionController extends Zend_Controller_Action
|
|||||||
public function preDispatch()
|
public function preDispatch()
|
||||||
{
|
{
|
||||||
$form = new AutoRefreshForm();
|
$form = new AutoRefreshForm();
|
||||||
$form->handleRequest();
|
if (! $this->getRequest()->isApiRequest()) {
|
||||||
|
$form->handleRequest();
|
||||||
|
}
|
||||||
$this->_helper->layout()->autoRefreshForm = $form;
|
$this->_helper->layout()->autoRefreshForm = $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1143,7 +1143,11 @@ class Form extends Zend_Form
|
|||||||
}
|
}
|
||||||
|
|
||||||
$formData = $this->getRequestData();
|
$formData = $this->getRequestData();
|
||||||
if ($this->getIsApiTarget() || $this->getUidDisabled() || $this->wasSent($formData)) {
|
if ($this->getIsApiTarget()
|
||||||
|
|| $this->getRequest()->isApiRequest()
|
||||||
|
|| $this->getUidDisabled()
|
||||||
|
|| $this->wasSent($formData)
|
||||||
|
) {
|
||||||
if (($frameUpload = (bool) $request->getUrl()->shift('_frameUpload', false))) {
|
if (($frameUpload = (bool) $request->getUrl()->shift('_frameUpload', false))) {
|
||||||
$this->getView()->layout()->setLayout('wrapped');
|
$this->getView()->layout()->setLayout('wrapped');
|
||||||
}
|
}
|
||||||
@ -1172,7 +1176,7 @@ class Form extends Zend_Form
|
|||||||
} else {
|
} else {
|
||||||
$this->getView()->layout()->redirectUrl = $this->getRedirectUrl()->getAbsoluteUrl();
|
$this->getView()->layout()->redirectUrl = $this->getRedirectUrl()->getAbsoluteUrl();
|
||||||
}
|
}
|
||||||
} elseif ($this->getIsApiTarget()) {
|
} elseif ($this->getIsApiTarget() || $this->getRequest()->isApiRequest()) {
|
||||||
$this->getResponse()->json()->setFailData($this->getMessages())->sendResponse();
|
$this->getResponse()->json()->setFailData($this->getMessages())->sendResponse();
|
||||||
}
|
}
|
||||||
} elseif ($this->getValidatePartial()) {
|
} elseif ($this->getValidatePartial()) {
|
||||||
@ -1198,7 +1202,7 @@ class Form extends Zend_Form
|
|||||||
if (strtolower($this->getRequest()->getMethod()) !== $this->getMethod()) {
|
if (strtolower($this->getRequest()->getMethod()) !== $this->getMethod()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($this->getIsApiTarget()) {
|
if ($this->getIsApiTarget() || $this->getRequest()->isApiRequest()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ($this->getSubmitLabel()) {
|
if ($this->getSubmitLabel()) {
|
||||||
|
@ -56,6 +56,11 @@ class DateTimePicker extends FormElement
|
|||||||
*/
|
*/
|
||||||
public function isValid($value, $context = null)
|
public function isValid($value, $context = null)
|
||||||
{
|
{
|
||||||
|
if (is_scalar($value) && $value !== '' && ! preg_match('/\D/', $value)) {
|
||||||
|
$dateTime = new DateTime();
|
||||||
|
$value = $dateTime->setTimestamp($value)->format($this->getFormat());
|
||||||
|
}
|
||||||
|
|
||||||
if (! parent::isValid($value, $context)) {
|
if (! parent::isValid($value, $context)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
namespace Icinga\Web;
|
namespace Icinga\Web;
|
||||||
|
|
||||||
|
use Icinga\Util\Json;
|
||||||
use Zend_Controller_Request_Http;
|
use Zend_Controller_Request_Http;
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\User;
|
use Icinga\User;
|
||||||
@ -120,4 +121,11 @@ class Request extends Zend_Controller_Request_Http
|
|||||||
|
|
||||||
return $id . '-' . $this->uniqueId;
|
return $id . '-' . $this->uniqueId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPost($key = null, $default = null)
|
||||||
|
{
|
||||||
|
return $key === null && $this->isApiRequest()
|
||||||
|
? Json::decode(file_get_contents('php://input'), true)
|
||||||
|
: parent::getPost($key, $default);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user