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()
|
||||
{
|
||||
$form = new AutoRefreshForm();
|
||||
$form->handleRequest();
|
||||
if (! $this->getRequest()->isApiRequest()) {
|
||||
$form->handleRequest();
|
||||
}
|
||||
$this->_helper->layout()->autoRefreshForm = $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -1143,7 +1143,11 @@ class Form extends Zend_Form
|
|||
}
|
||||
|
||||
$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))) {
|
||||
$this->getView()->layout()->setLayout('wrapped');
|
||||
}
|
||||
|
@ -1172,7 +1176,7 @@ class Form extends Zend_Form
|
|||
} else {
|
||||
$this->getView()->layout()->redirectUrl = $this->getRedirectUrl()->getAbsoluteUrl();
|
||||
}
|
||||
} elseif ($this->getIsApiTarget()) {
|
||||
} elseif ($this->getIsApiTarget() || $this->getRequest()->isApiRequest()) {
|
||||
$this->getResponse()->json()->setFailData($this->getMessages())->sendResponse();
|
||||
}
|
||||
} elseif ($this->getValidatePartial()) {
|
||||
|
@ -1198,7 +1202,7 @@ class Form extends Zend_Form
|
|||
if (strtolower($this->getRequest()->getMethod()) !== $this->getMethod()) {
|
||||
return false;
|
||||
}
|
||||
if ($this->getIsApiTarget()) {
|
||||
if ($this->getIsApiTarget() || $this->getRequest()->isApiRequest()) {
|
||||
return true;
|
||||
}
|
||||
if ($this->getSubmitLabel()) {
|
||||
|
|
|
@ -56,6 +56,11 @@ class DateTimePicker extends FormElement
|
|||
*/
|
||||
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)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
namespace Icinga\Web;
|
||||
|
||||
use Icinga\Util\Json;
|
||||
use Zend_Controller_Request_Http;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\User;
|
||||
|
@ -120,4 +121,11 @@ class Request extends Zend_Controller_Request_Http
|
|||
|
||||
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…
Reference in New Issue