Skip to content

Commit

Permalink
Introduce CommandForm#filterGrantedOn()
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Jul 25, 2023
1 parent c73c171 commit a4a4f9e
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 34 deletions.
20 changes: 20 additions & 0 deletions application/forms/Command/CommandForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace Icinga\Module\Icingadb\Forms\Command;

use Exception;
use Generator;
use Icinga\Application\Logger;
use Icinga\Module\Icingadb\Command\IcingaCommand;
use Icinga\Module\Icingadb\Command\Transport\CommandTransport;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Web\Notification;
use Icinga\Web\Session;
use ipl\Html\Form;
Expand All @@ -17,6 +19,7 @@

abstract class CommandForm extends Form
{
use Auth;
use CsrfCounterMeasure;

protected $defaultAttributes = ['class' => 'icinga-form icinga-controls'];
Expand Down Expand Up @@ -124,4 +127,21 @@ protected function sendCommand(IcingaCommand $command)
{
(new CommandTransport())->send($command);
}

/**
* Yield the $objects the currently logged in user has the permission $permission for
*
* @param string $permission
* @param Traversable $objects
*
* @return Generator
*/
protected function filterGrantedOn(string $permission, Traversable $objects): Generator
{
foreach ($objects as $object) {
if ($this->isGrantedOn($permission, $object)) {
yield $object;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
namespace Icinga\Module\Icingadb\Forms\Command\Instance;

use Icinga\Module\Icingadb\Command\Instance\ToggleInstanceFeatureCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Web\Notification;
use ipl\Web\FormDecorator\IcingaFormDecorator;
use Traversable;

class ToggleInstanceFeaturesForm extends CommandForm
{
use Auth;

protected $features;

protected $featureStatus;
Expand Down
3 changes: 0 additions & 3 deletions application/forms/Command/Object/AcknowledgeProblemForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use DateTime;
use Icinga\Application\Config;
use Icinga\Module\Icingadb\Command\Object\AcknowledgeProblemCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Web\Notification;
Expand All @@ -22,8 +21,6 @@

class AcknowledgeProblemForm extends CommandForm
{
use Auth;

public function __construct()
{
$this->on(self::ON_SUCCESS, function () {
Expand Down
3 changes: 0 additions & 3 deletions application/forms/Command/Object/AddCommentForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use DateTime;
use Icinga\Application\Config;
use Icinga\Module\Icingadb\Command\Object\AddCommentCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Web\Notification;
Expand All @@ -22,8 +21,6 @@

class AddCommentForm extends CommandForm
{
use Auth;

public function __construct()
{
$this->on(self::ON_SUCCESS, function () {
Expand Down
3 changes: 0 additions & 3 deletions application/forms/Command/Object/CheckNowForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
namespace Icinga\Module\Icingadb\Forms\Command\Object;

use Icinga\Module\Icingadb\Command\Object\ScheduleCheckCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Web\Notification;
use ipl\Web\Widget\Icon;
use Traversable;

class CheckNowForm extends CommandForm
{
use Auth;

protected $defaultAttributes = ['class' => 'inline'];

public function __construct()
Expand Down
2 changes: 0 additions & 2 deletions application/forms/Command/Object/DeleteCommentForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Icinga\Module\Icingadb\Forms\Command\Object;

use Icinga\Module\Icingadb\Command\Object\DeleteCommentCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Web\Notification;
use ipl\Web\Common\RedirectOption;
Expand All @@ -14,7 +13,6 @@

class DeleteCommentForm extends CommandForm
{
use Auth;
use RedirectOption;

protected $defaultAttributes = ['class' => 'inline'];
Expand Down
2 changes: 0 additions & 2 deletions application/forms/Command/Object/DeleteDowntimeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Icinga\Module\Icingadb\Forms\Command\Object;

use Icinga\Module\Icingadb\Command\Object\DeleteDowntimeCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Web\Notification;
use ipl\Web\Common\RedirectOption;
Expand All @@ -14,7 +13,6 @@

class DeleteDowntimeForm extends CommandForm
{
use Auth;
use RedirectOption;

protected $defaultAttributes = ['class' => 'inline'];
Expand Down
3 changes: 0 additions & 3 deletions application/forms/Command/Object/ProcessCheckResultForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Icinga\Module\Icingadb\Forms\Command\Object;

use Icinga\Module\Icingadb\Command\Object\ProcessCheckResultCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Web\Notification;
Expand All @@ -19,8 +18,6 @@

class ProcessCheckResultForm extends CommandForm
{
use Auth;

public function __construct()
{
$this->on(self::ON_SUCCESS, function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Icinga\Module\Icingadb\Forms\Command\Object;

use Icinga\Module\Icingadb\Command\Object\RemoveAcknowledgementCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Web\Notification;
Expand All @@ -14,8 +13,6 @@

class RemoveAcknowledgementForm extends CommandForm
{
use Auth;

public function __construct()
{
$this->on(self::ON_SUCCESS, function () {
Expand Down
3 changes: 0 additions & 3 deletions application/forms/Command/Object/ScheduleCheckForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use DateInterval;
use DateTime;
use Icinga\Module\Icingadb\Command\Object\ScheduleCheckCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Web\Notification;
Expand All @@ -20,8 +19,6 @@

class ScheduleCheckForm extends CommandForm
{
use Auth;

public function __construct()
{
$this->on(self::ON_SUCCESS, function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use DateTime;
use Icinga\Application\Config;
use Icinga\Module\Icingadb\Command\Object\ScheduleServiceDowntimeCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Web\Notification;
use ipl\Html\Attributes;
Expand All @@ -21,8 +20,6 @@

class ScheduleServiceDowntimeForm extends CommandForm
{
use Auth;

/** @var DateTime downtime start */
protected $start;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Icinga\Application\Config;
use Icinga\Module\Icingadb\Command\Object\SendCustomNotificationCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Web\Notification;
Expand All @@ -19,8 +18,6 @@

class SendCustomNotificationForm extends CommandForm
{
use Auth;

public function __construct()
{
$this->on(self::ON_SUCCESS, function () {
Expand Down
3 changes: 0 additions & 3 deletions application/forms/Command/Object/ToggleObjectFeaturesForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Icinga\Module\Icingadb\Forms\Command\Object;

use Icinga\Module\Icingadb\Command\Object\ToggleObjectFeatureCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Web\Notification;
use ipl\Html\FormElement\CheckboxElement;
Expand All @@ -15,8 +14,6 @@

class ToggleObjectFeaturesForm extends CommandForm
{
use Auth;

const LEAVE_UNCHANGED = 'noop';

protected $features;
Expand Down

0 comments on commit a4a4f9e

Please sign in to comment.