Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions application/controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Icinga\Module\Notifications\Controllers;

use Exception;
use Icinga\Exception\Http\HttpBadRequestException;
use Icinga\Module\Notifications\Api\Middleware\DispatchMiddleware;
use Icinga\Module\Notifications\Api\Middleware\EndpointExecutionMiddleware;
use Icinga\Module\Notifications\Api\Middleware\ErrorHandlingMiddleware;
Expand All @@ -14,7 +12,6 @@
use Icinga\Module\Notifications\Api\Middleware\RoutingMiddleware;
use Icinga\Module\Notifications\Api\Middleware\ValidationMiddleware;
use Icinga\Security\SecurityException;
use Icinga\Web\Request;
use ipl\Web\Compat\CompatController;
use Psr\Http\Message\ResponseInterface;

Expand All @@ -26,6 +23,7 @@ class ApiController extends CompatController
* Processes API requests for the Notifications module, serving as the main entry point for all API interactions.
*
* @return never
*
* @throws SecurityException
*/
public function indexAction(): never
Expand Down
3 changes: 2 additions & 1 deletion application/controllers/ChannelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Icinga\Module\Notifications\Common\Database;
use Icinga\Module\Notifications\Forms\ChannelForm;
use Icinga\Web\Notification;
use ipl\Html\Contract\Form;
use ipl\Web\Compat\CompatController;

class ChannelController extends CompatController
Expand All @@ -21,7 +22,7 @@ public function indexAction(): void
$channelId = $this->params->getRequired('id');
$form = (new ChannelForm(Database::get()))
->loadChannel($channelId)
->on(ChannelForm::ON_SUCCESS, function (ChannelForm $form) {
->on(Form::ON_SUBMIT, function (ChannelForm $form) {
if ($form->getPressedSubmitElement()->getName() === 'delete') {
$form->removeChannel();
Notification::success(sprintf(
Expand Down
25 changes: 3 additions & 22 deletions application/controllers/ChannelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
use Icinga\Module\Notifications\Web\Control\SearchBar\ObjectSuggestions;
use Icinga\Module\Notifications\Widget\ItemList\ObjectList;
use Icinga\Web\Notification;
use Icinga\Web\Widget\Tab;
use Icinga\Web\Widget\Tabs;
use ipl\Html\Contract\Form;
use ipl\Sql\Expression;
use ipl\Stdlib\Filter;
use ipl\Web\Compat\CompatController;
use ipl\Web\Compat\SearchControls;
use ipl\Web\Control\LimitControl;
Expand All @@ -29,9 +28,6 @@ class ChannelsController extends CompatController
{
use SearchControls;

/** @var Filter\Rule Filter from query string parameters */
private $filter;

public function init(): void
{
$this->assertPermission('config/modules');
Expand Down Expand Up @@ -64,7 +60,7 @@ public function indexAction(): void

if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
if ($searchBar->hasBeenSubmitted()) {
$filter = $this->getFilter();
$filter = QueryString::parse((string) $this->params);
} else {
$this->addControl($searchBar);
$this->sendMultipartUpdate();
Expand Down Expand Up @@ -110,7 +106,7 @@ public function addAction(): void
{
$this->addTitleTab(t('Add Channel'));
$form = (new ChannelForm(Database::get()))
->on(ChannelForm::ON_SUCCESS, function (ChannelForm $form) {
->on(Form::ON_SUBMIT, function (ChannelForm $form) {
$form->addChannel();
Notification::success(
sprintf(
Expand Down Expand Up @@ -147,20 +143,6 @@ public function searchEditorAction(): void
$this->setTitle($this->translate('Adjust Filter'));
}

/**
* Get the filter created from query string parameters
*
* @return Filter\Rule
*/
protected function getFilter(): Filter\Rule
{
if ($this->filter === null) {
$this->filter = QueryString::parse((string) $this->params);
}

return $this->filter;
}

/**
* Merge tabs with other tabs contained in this tab panel
*
Expand All @@ -170,7 +152,6 @@ protected function getFilter(): Filter\Rule
*/
protected function mergeTabs(Tabs $tabs): void
{
/** @var Tab $tab */
foreach ($tabs->getTabs() as $tab) {
$this->tabs->add($tab->getName(), $tab);
}
Expand Down
9 changes: 4 additions & 5 deletions application/controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@
use Icinga\Application\Config;
use Icinga\Module\Notifications\Forms\DatabaseConfigForm;
use Icinga\Web\Notification;
use Icinga\Web\Widget\Tab;
use Icinga\Web\Widget\Tabs;
use ipl\Html\Contract\Form;
use ipl\Web\Compat\CompatController;

class ConfigController extends CompatController
{
public function init()
public function init(): void
{
$this->assertPermission('config/modules');

parent::init();
}

public function databaseAction()
public function databaseAction(): void
{
$moduleConfig = Config::module('notifications');
$form = (new DatabaseConfigForm())
->populate($moduleConfig->getSection('database'))
->on(DatabaseConfigForm::ON_SUCCESS, function ($form) use ($moduleConfig) {
->on(Form::ON_SUBMIT, function ($form) use ($moduleConfig) {
$moduleConfig->setSection('database', $form->getValues());
$moduleConfig->saveIni();

Expand All @@ -46,7 +46,6 @@ public function databaseAction()
*/
protected function mergeTabs(Tabs $tabs): void
{
/** @var Tab $tab */
foreach ($tabs->getTabs() as $tab) {
$this->tabs->add($tab->getName(), $tab);
}
Expand Down
3 changes: 2 additions & 1 deletion application/controllers/ContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Icinga\Module\Notifications\Web\Form\ContactForm;
use Icinga\Repository\Repository;
use Icinga\Web\Notification;
use ipl\Html\Contract\Form;
use ipl\Web\Compat\CompatController;
use ipl\Web\FormElement\SearchSuggestions;

Expand All @@ -29,7 +30,7 @@ public function indexAction(): void

$form = (new ContactForm(Database::get()))
->loadContact($contactId)
->on(ContactForm::ON_SUCCESS, function (ContactForm $form) {
->on(Form::ON_SUBMIT, function (ContactForm $form) {
$form->editContact();
Notification::success(sprintf(
t('Contact "%s" has successfully been saved'),
Expand Down
8 changes: 5 additions & 3 deletions application/controllers/ContactGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
use Icinga\Module\Notifications\Widget\Detail\ObjectHeader;
use Icinga\Module\Notifications\Widget\ItemList\ObjectList;
use Icinga\Web\Notification;
use ipl\Html\Form;
use ipl\Html\Attributes;
use ipl\Html\Contract\Form;
use ipl\Html\Text;
use ipl\Stdlib\Filter;
use ipl\Web\Compat\CompatController;
Expand All @@ -35,12 +36,13 @@ public function indexAction(): void
->columns(['id', 'name'])
->filter(Filter::equal('id', $groupId));

/** @var ?Contactgroup $group */
$group = $query->first();
if ($group === null) {
$this->httpNotFound(t('Contact group not found'));
}

$this->controls->addAttributes(['class' => 'contactgroup-detail']);
$this->controls->addAttributes(Attributes::create(['class' => 'contactgroup-detail']));

$this->addControl(new ObjectHeader($group));

Expand Down Expand Up @@ -97,7 +99,7 @@ public function editAction(): void
}
}
})
->on(Form::ON_SUCCESS, function (ContactGroupForm $form) use ($groupId) {
->on(Form::ON_SUBMIT, function (ContactGroupForm $form) use ($groupId) {
$form->editGroup();
Notification::success(sprintf(
t('Successfully updated contact group %s'),
Expand Down
22 changes: 2 additions & 20 deletions application/controllers/ContactGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use ipl\Html\HtmlString;
use ipl\Html\TemplateString;
use ipl\Sql\Expression;
use ipl\Stdlib\Filter;
use ipl\Web\Compat\CompatController;
use ipl\Web\Compat\SearchControls;
use ipl\Web\Control\LimitControl;
Expand All @@ -35,9 +34,6 @@ class ContactGroupsController extends CompatController
use ConfigurationTabs;
use SearchControls;

/** @var Filter\Rule Filter from query string parameters */
private $filter;

public function init(): void
{
$this->assertPermission('notifications/config/contacts');
Expand Down Expand Up @@ -70,7 +66,7 @@ public function indexAction(): void

if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
if ($searchBar->hasBeenSubmitted()) {
$filter = $this->getFilter();
$filter = QueryString::parse((string) $this->params);
} else {
$this->addControl($searchBar);
$this->sendMultipartUpdate();
Expand Down Expand Up @@ -160,7 +156,7 @@ public function addAction(): void
}
}
})
->on(Form::ON_SUCCESS, function (ContactGroupForm $form) {
->on(Form::ON_SUBMIT, function (ContactGroupForm $form) {
$groupIdentifier = $form->addGroup();

Notification::success($this->translate('New contact group has been successfully added'));
Expand Down Expand Up @@ -203,18 +199,4 @@ public function suggestMemberAction(): void

$this->getDocument()->addHtml($members);
}

/**
* Get the filter created from query string parameters
*
* @return Filter\Rule
*/
private function getFilter(): Filter\Rule
{
if ($this->filter === null) {
$this->filter = QueryString::parse((string) $this->params);
}

return $this->filter;
}
}
30 changes: 6 additions & 24 deletions application/controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
namespace Icinga\Module\Notifications\Controllers;

use Icinga\Module\Notifications\Common\ConfigurationTabs;
use Icinga\Module\Notifications\Common\Database;
use Icinga\Module\Notifications\Common\Links;
use Icinga\Module\Notifications\Model\Channel;
use Icinga\Module\Notifications\Model\Contact;
use Icinga\Module\Notifications\View\ContactRenderer;
use Icinga\Module\Notifications\Web\Control\SearchBar\ObjectSuggestions;
use Icinga\Module\Notifications\Common\Database;
use Icinga\Module\Notifications\Model\Contact;
use Icinga\Module\Notifications\Web\Form\ContactForm;
use Icinga\Module\Notifications\Widget\ItemList\ObjectList;
use Icinga\Web\Notification;
use ipl\Html\Contract\Form;
use ipl\Html\TemplateString;
use ipl\Sql\Connection;
use ipl\Sql\Expression;
use ipl\Stdlib\Filter;
use ipl\Web\Compat\CompatController;
use ipl\Web\Compat\SearchControls;
use ipl\Web\Control\LimitControl;
Expand All @@ -34,19 +33,16 @@ class ContactsController extends CompatController
use SearchControls;

/** @var Connection */
private $db;

/** @var Filter\Rule Filter from query string parameters */
private $filter;
private Connection $db;

public function init()
public function init(): void
{
$this->assertPermission('notifications/config/contacts');

$this->db = Database::get();
}

public function indexAction()
public function indexAction(): void
{
$this->setTitle($this->translate('Contacts'));
$this->getTabs()->activate('contacts');
Expand All @@ -73,7 +69,7 @@ public function indexAction()

if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
if ($searchBar->hasBeenSubmitted()) {
$filter = $this->getFilter();
$filter = QueryString::parse((string) $this->params);
} else {
$this->addControl($searchBar);
$this->sendMultipartUpdate();
Expand Down Expand Up @@ -164,18 +160,4 @@ public function searchEditorAction(): void
$this->getDocument()->add($editor);
$this->setTitle($this->translate('Adjust Filter'));
}

/**
* Get the filter created from query string parameters
*
* @return Filter\Rule
*/
protected function getFilter(): Filter\Rule
{
if ($this->filter === null) {
$this->filter = QueryString::parse((string) $this->params);
}

return $this->filter;
}
}
2 changes: 1 addition & 1 deletion application/controllers/DaemonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function scriptAction(): void
->getBaseDir() . '/public/js';

$filePath = realpath($root . DIRECTORY_SEPARATOR . 'notifications-' . $fileName . $extension);
if ($filePath === false || substr($filePath, 0, strlen($root)) !== $root) {
if ($filePath === false || ! str_starts_with($filePath, $root)) {
if ($fileName === 'undefined') {
$this->httpNotFound(t("No file name submitted"));
}
Expand Down
3 changes: 2 additions & 1 deletion application/controllers/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Icinga\Module\Notifications\Model\Event;
use Icinga\Module\Notifications\Widget\Detail\EventDetail;
use Icinga\Module\Notifications\Widget\Detail\ObjectHeader;
use ipl\Html\Attributes;
use ipl\Stdlib\Filter;
use ipl\Web\Compat\CompatController;

Expand Down Expand Up @@ -40,7 +41,7 @@ public function indexAction(): void

$this->addControl(new ObjectHeader($event));

$this->controls->addAttributes(['class' => 'event-detail']);
$this->controls->addAttributes(Attributes::create(['class' => 'event-detail']));

$this->addContent(new EventDetail($event));
}
Expand Down
Loading
Loading