diff --git a/app/modules/web/Controllers/Eventlog/ClearController.php b/app/modules/web/Controllers/Eventlog/ClearController.php new file mode 100644 index 00000000..20ad9666 --- /dev/null +++ b/app/modules/web/Controllers/Eventlog/ClearController.php @@ -0,0 +1,86 @@ +. + */ + +namespace SP\Modules\Web\Controllers\Eventlog; + + +use Exception; +use SP\Core\Application; +use SP\Core\Events\Event; +use SP\Core\Events\EventMessage; +use SP\Domain\Security\EventlogServiceInterface; +use SP\Http\JsonResponse; +use SP\Modules\Web\Controllers\ControllerBase; +use SP\Modules\Web\Controllers\Traits\JsonTrait; +use SP\Mvc\Controller\WebControllerHelper; + +/** + * Class ClearController + */ +final class ClearController extends ControllerBase +{ + use JsonTrait; + + private EventlogServiceInterface $eventlogService; + + /** + * @throws \SP\Core\Exceptions\SessionTimeout + * @throws \SP\Domain\Auth\Services\AuthException + * @throws \JsonException + */ + public function __construct( + Application $application, + WebControllerHelper $webControllerHelper, + EventlogServiceInterface $eventlogService + ) { + parent::__construct($application, $webControllerHelper); + + $this->checkLoggedIn(); + + $this->eventlogService = $eventlogService; + } + + + /** + * @return bool + * @throws \JsonException + */ + public function clearAction(): bool + { + try { + $this->eventlogService->clear(); + + $this->eventDispatcher->notifyEvent( + 'clear.eventlog', + new Event($this, EventMessage::factory()->addDescription(__u('Event log cleared'))) + ); + + return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Event log cleared')); + } catch (Exception $e) { + processException($e); + + return $this->returnJsonResponseException($e); + } + } +} \ No newline at end of file diff --git a/app/modules/web/Controllers/Eventlog/IndexController.php b/app/modules/web/Controllers/Eventlog/IndexController.php new file mode 100644 index 00000000..c18f6fa5 --- /dev/null +++ b/app/modules/web/Controllers/Eventlog/IndexController.php @@ -0,0 +1,65 @@ +. + */ + +namespace SP\Modules\Web\Controllers\Eventlog; + +use DI\DependencyException; +use DI\NotFoundException; +use SP\Core\Acl\ActionsInterface; +use SP\Core\Exceptions\ConstraintException; +use SP\Core\Exceptions\QueryException; +use SP\Core\Exceptions\SPException; +use SP\Modules\Web\Controllers\ControllerBase; + +/** + * Class IndexController + * + * @package SP\Modules\Web\Controllers + */ +final class IndexController extends ControllerBase +{ + /** + * indexAction + * + * @throws DependencyException + * @throws NotFoundException + * @throws ConstraintException + * @throws QueryException + * @throws SPException + * + * TODO: Remove? + */ + public function indexAction(): void + { + if (!$this->acl->checkUserAccess(ActionsInterface::EVENTLOG)) { + return; + } + + $this->view->addTemplate('index'); + + $this->view->assign('data', $this->getSearchGrid()); + + $this->view(); + } +} \ No newline at end of file diff --git a/app/modules/web/Controllers/Eventlog/SearchController.php b/app/modules/web/Controllers/Eventlog/SearchController.php new file mode 100644 index 00000000..ea1e85c0 --- /dev/null +++ b/app/modules/web/Controllers/Eventlog/SearchController.php @@ -0,0 +1,106 @@ +. + */ + +namespace SP\Modules\Web\Controllers\Eventlog; + + +use SP\Core\Acl\ActionsInterface; +use SP\Core\Application; +use SP\Domain\Security\EventlogServiceInterface; +use SP\Html\DataGrid\DataGridInterface; +use SP\Http\JsonResponse; +use SP\Modules\Web\Controllers\ControllerBase; +use SP\Modules\Web\Controllers\Helpers\Grid\EventlogGrid; +use SP\Modules\Web\Controllers\Traits\JsonTrait; +use SP\Mvc\Controller\ItemTrait; +use SP\Mvc\Controller\WebControllerHelper; + +/** + * Class SearchController + */ +final class SearchController extends ControllerBase +{ + use JsonTrait, ItemTrait; + + private EventlogGrid $eventlogGrid; + private EventlogServiceInterface $eventlogService; + + public function __construct( + Application $application, + WebControllerHelper $webControllerHelper, + EventlogServiceInterface $eventlogService, + EventlogGrid $eventlogGrid + ) { + parent::__construct($application, $webControllerHelper); + + $this->checkLoggedIn(); + + $this->eventlogService = $eventlogService; + $this->eventlogGrid = $eventlogGrid; + } + + /** + * searchAction + * + * @return bool + * @throws \JsonException + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function searchAction(): bool + { + if (!$this->acl->checkUserAccess(ActionsInterface::EVENTLOG_SEARCH)) { + return $this->returnJsonResponse( + JsonResponse::JSON_ERROR, + __u('You don\'t have permission to do this operation') + ); + } + + $this->view->addTemplate('datagrid-table-simple', 'grid'); + $this->view->assign('data', $this->getSearchGrid()); + + return $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * getSearchGrid + * + * @return \SP\Html\DataGrid\DataGridInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + protected function getSearchGrid(): DataGridInterface + { + $itemSearchData = $this->getSearchData( + $this->configData->getAccountCount(), + $this->request + ); + + + return $this->eventlogGrid->updatePager( + $this->eventlogGrid->getGrid($this->eventlogService->search($itemSearchData)), + $itemSearchData + ); + } +} \ No newline at end of file diff --git a/app/modules/web/Controllers/EventlogController.php b/app/modules/web/Controllers/EventlogController.php deleted file mode 100644 index 69869ddb..00000000 --- a/app/modules/web/Controllers/EventlogController.php +++ /dev/null @@ -1,168 +0,0 @@ -. - */ - -namespace SP\Modules\Web\Controllers; - -use DI\DependencyException; -use DI\NotFoundException; -use Exception; -use SP\Core\Acl\ActionsInterface; -use SP\Core\Events\Event; -use SP\Core\Events\EventMessage; -use SP\Core\Exceptions\ConstraintException; -use SP\Core\Exceptions\QueryException; -use SP\Core\Exceptions\SessionTimeout; -use SP\Core\Exceptions\SPException; -use SP\Domain\Auth\Services\AuthException; -use SP\Domain\Security\Services\EventlogService; -use SP\Http\JsonResponse; -use SP\Modules\Web\Controllers\Helpers\Grid\EventlogGrid; -use SP\Modules\Web\Controllers\Traits\JsonTrait; -use SP\Mvc\Controller\ItemTrait; - -/** - * Class EventlogController - * - * @package SP\Modules\Web\Controllers - */ -final class EventlogController extends ControllerBase -{ - use JsonTrait, ItemTrait; - - protected ?EventlogService $eventLogService = null; - - /** - * indexAction - * - * @throws DependencyException - * @throws NotFoundException - * @throws ConstraintException - * @throws QueryException - * @throws SPException - */ - public function indexAction(): void - { - if (!$this->acl->checkUserAccess(ActionsInterface::EVENTLOG)) { - return; - } - - $this->view->addTemplate('index'); - - $this->view->assign('data', $this->getSearchGrid()); - - $this->view(); - } - - /** - * getSearchGrid - * - * @return $this - * @throws DependencyException - * @throws NotFoundException - * @throws ConstraintException - * @throws QueryException - */ - protected function getSearchGrid(): EventlogController - { - $itemSearchData = $this->getSearchData( - $this->configData->getAccountCount(), - $this->request - ); - - $eventlogGrid = $this->dic->get(EventlogGrid::class); - - return $eventlogGrid->updatePager( - $eventlogGrid->getGrid($this->eventLogService->search($itemSearchData)), - $itemSearchData - ); - } - - /** - * searchAction - * - * @return bool - * @throws \DI\DependencyException - * @throws \DI\NotFoundException - * @throws \JsonException - * @throws \SP\Core\Exceptions\ConstraintException - * @throws \SP\Core\Exceptions\QueryException - */ - public function searchAction(): bool - { - if (!$this->acl->checkUserAccess(ActionsInterface::EVENTLOG_SEARCH)) { - return $this->returnJsonResponse( - JsonResponse::JSON_ERROR, - __u('You don\'t have permission to do this operation') - ); - } - - $this->view->addTemplate('datagrid-table-simple', 'grid'); - $this->view->assign('data', $this->getSearchGrid()); - - return $this->returnJsonResponseData(['html' => $this->render()]); - } - - /** - * @return bool - * @throws DependencyException - * @throws NotFoundException|\JsonException - */ - public function clearAction(): bool - { - try { - $this->eventLogService->clear(); - - $this->eventDispatcher->notifyEvent( - 'clear.eventlog', - new Event( - $this, - EventMessage::factory() - ->addDescription(__u('Event log cleared')) - ) - ); - - return $this->returnJsonResponse( - JsonResponse::JSON_SUCCESS, - __u('Event log cleared') - ); - } catch (Exception $e) { - processException($e); - - return $this->returnJsonResponseException($e); - } - } - - /** - * @throws AuthException - * @throws DependencyException - * @throws NotFoundException - * @throws SessionTimeout - */ - protected function initialize(): void - { - $this->checkLoggedIn(); - - $this->eventLogService = $this->dic->get(EventlogService::class); - } -} \ No newline at end of file