Merge pull request #2754 from Icinga/feature/api-call-to-add-announcement-2749

Support creating announcements via API
This commit is contained in:
Eric Lippmann 2018-06-25 09:32:06 +02:00 committed by GitHub
commit 42c7c3ae7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 4 deletions

View File

@ -447,7 +447,9 @@ class ActionController extends Zend_Controller_Action
public function preDispatch()
{
$form = new AutoRefreshForm();
if (! $this->getRequest()->isApiRequest()) {
$form->handleRequest();
}
$this->_helper->layout()->autoRefreshForm = $form;
}

View File

@ -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()) {

View File

@ -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;
}

View File

@ -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);
}
}