diff --git a/app/config/actions.xml b/app/config/actions.xml index cdac373d..09911b03 100644 --- a/app/config/actions.xml +++ b/app/config/actions.xml @@ -656,16 +656,10 @@ userPreference/security - 760 - NOTICE + 76 + NOTIFICATION Notificaciones - notice/index - - - 761 - NOTICE_USER - Notificaciones Usuario - noticeUser/index + notification/index 1000 @@ -776,39 +770,39 @@ accountManager/restore - 7610 - NOTICE_USER_VIEW + 760 + NOTIFICATION_VIEW Ver Notificación - userNotice/view + notification/view - 7611 - NOTICE_USER_CREATE + 761 + NOTIFICATION_CREATE Crear Notificación - userNotice/create + notification/create - 7612 - NOTICE_USER_EDIT + 762 + NOTIFICATION_EDIT Editar Notificación - userNotice/edit + notification/edit - 7613 - NOTICE_USER_DELETE + 763 + NOTIFICATION_DELETE Eliminar Notificación - userNotice/delete + notification/delete - 7614 - NOTICE_USER_CHECK + 764 + NOTIFICATION_CHECK Marcar Notificación - userNotice/check + notification/check - 7615 - NOTICE_USER_SEARCH + 765 + NOTIFICATION_SEARCH Buscar Notificación - userNotice/search + notification/search \ No newline at end of file diff --git a/app/modules/web/Controllers/AccountController.php b/app/modules/web/Controllers/AccountController.php index cfe623b2..f7b58805 100644 --- a/app/modules/web/Controllers/AccountController.php +++ b/app/modules/web/Controllers/AccountController.php @@ -33,7 +33,6 @@ use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; -use SP\Core\SessionUtil; use SP\DataModel\AccountExtData; use SP\Forms\AccountForm; use SP\Http\JsonResponse; @@ -103,7 +102,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->eventDispatcher->notifyEvent('show.account.search', new Event($this)); $data = [ - 'sk' => SessionUtil::getSessionKey(), + 'sk' => $this->session->generateSecurityKey(), 'html' => $this->render() ]; @@ -359,7 +358,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function deleteAction($id) + public function deleteAction($id = null) { try { $accountDetailsResponse = $this->accountService->getById($id); @@ -739,7 +738,23 @@ class AccountController extends ControllerBase implements CrudControllerInterfac public function saveDeleteAction($id) { try { - if ($this->accountService->delete($id)) { + if ($id === null) { + $this->accountService->deleteByIdBatch($this->getItemsIdFromRequest()); + + $this->deleteCustomFieldsForItem(ActionsInterface::ACCOUNT, $id); + + $this->eventDispatcher->notifyEvent('delete.account.selection', + new Event($this, EventMessage::factory()->addDescription(__u('Cuentas eliminadas'))) + ); + + $this->returnJsonResponseData( + ['nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_SEARCH)], + JsonResponse::JSON_SUCCESS, + __u('Cuentas eliminadas') + ); + } else { + $this->accountService->delete($id); + $this->deleteCustomFieldsForItem(ActionsInterface::ACCOUNT, $id); $this->eventDispatcher->notifyEvent('delete.account', diff --git a/app/modules/web/Controllers/AccountFileController.php b/app/modules/web/Controllers/AccountFileController.php index 9b08f41f..6f4f6b3e 100644 --- a/app/modules/web/Controllers/AccountFileController.php +++ b/app/modules/web/Controllers/AccountFileController.php @@ -261,18 +261,29 @@ class AccountFileController extends ControllerBase implements CrudControllerInte * * @param $id */ - public function deleteAction($id) + public function deleteAction($id = null) { try { - $this->accountFileService->delete($id); + if ($id === null) { + $this->accountFileService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->eventDispatcher->notifyEvent('delete.accountFile', - new Event($this, EventMessage::factory() - ->addDescription(__u('Archivo eliminado')) - ->addDetail(__u('Archivo'), $id)) - ); + $this->eventDispatcher->notifyEvent('delete.accountFile.selection', + new Event($this, EventMessage::factory() + ->addDescription(__u('Archivos eliminados'))) + ); - $this->returnJsonResponse(0, __u('Archivo Eliminado')); + $this->returnJsonResponse(0, __u('Archivos Eliminados')); + } else { + $this->eventDispatcher->notifyEvent('delete.accountFile', + new Event($this, EventMessage::factory() + ->addDescription(__u('Archivo eliminado')) + ->addDetail(__u('Archivo'), $id)) + ); + + $this->accountFileService->delete($id); + + $this->returnJsonResponse(0, __u('Archivo Eliminado')); + } } catch (\Exception $e) { processException($e); diff --git a/app/modules/web/Controllers/ApiTokenController.php b/app/modules/web/Controllers/ApiTokenController.php index cc411d7e..0edc127f 100644 --- a/app/modules/web/Controllers/ApiTokenController.php +++ b/app/modules/web/Controllers/ApiTokenController.php @@ -176,25 +176,39 @@ class ApiTokenController extends ControllerBase implements CrudControllerInterfa * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function deleteAction($id) + public function deleteAction($id = null) { if (!$this->acl->checkUserAccess(ActionsInterface::APITOKEN_DELETE)) { return; } try { - $this->authTokenService->delete($id); + if ($id === null) { + $this->authTokenService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::APITOKEN, $id); + $this->deleteCustomFieldsForItem(ActionsInterface::APITOKEN, $id); - $this->eventDispatcher->notifyEvent('delete.authToken', - new Event($this, - EventMessage::factory() - ->addDescription(__u('Autorización eliminada')) - ->addDetail(__u('Autorización'), $id)) - ); + $this->eventDispatcher->notifyEvent('delete.authToken.selection', + new Event($this, + EventMessage::factory() + ->addDescription(__u('Autorizaciones eliminadas'))) + ); - $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Autorización eliminada')); + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Autorizaciones eliminadas')); + } else { + $this->authTokenService->delete($id); + + $this->deleteCustomFieldsForItem(ActionsInterface::APITOKEN, $id); + + $this->eventDispatcher->notifyEvent('delete.authToken', + new Event($this, + EventMessage::factory() + ->addDescription(__u('Autorización eliminada')) + ->addDetail(__u('Autorización'), $id)) + ); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Autorización eliminada')); + } } catch (\Exception $e) { processException($e); diff --git a/app/modules/web/Controllers/CategoryController.php b/app/modules/web/Controllers/CategoryController.php index 08493209..f04d73f9 100644 --- a/app/modules/web/Controllers/CategoryController.php +++ b/app/modules/web/Controllers/CategoryController.php @@ -170,25 +170,39 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function deleteAction($id) + public function deleteAction($id = null) { if (!$this->acl->checkUserAccess(ActionsInterface::CATEGORY_DELETE)) { return; } try { - $this->categoryService->delete($id); + if ($id === null) { + $this->categoryService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::CATEGORY, $id); + $this->deleteCustomFieldsForItem(ActionsInterface::CATEGORY, $id); - $this->eventDispatcher->notifyEvent('delete.category', - new Event($this, - EventMessage::factory() - ->addDescription(__u('Categoría eliminada')) - ->addDetail(__u('Categoría'), $id)) - ); + $this->eventDispatcher->notifyEvent('delete.category', + new Event($this, + EventMessage::factory() + ->addDescription(__u('Categorías eliminadas'))) + ); - $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Categoría eliminada')); + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Categorías eliminadas')); + } else { + $this->categoryService->delete($id); + + $this->deleteCustomFieldsForItem(ActionsInterface::CATEGORY, $id); + + $this->eventDispatcher->notifyEvent('delete.category', + new Event($this, + EventMessage::factory() + ->addDescription(__u('Categoría eliminada')) + ->addDetail(__u('Categoría'), $id)) + ); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Categoría eliminada')); + } } catch (\Exception $e) { processException($e); diff --git a/app/modules/web/Controllers/ClientController.php b/app/modules/web/Controllers/ClientController.php index ac7e6947..9af38bee 100644 --- a/app/modules/web/Controllers/ClientController.php +++ b/app/modules/web/Controllers/ClientController.php @@ -171,25 +171,39 @@ class ClientController extends ControllerBase implements CrudControllerInterface * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function deleteAction($id) + public function deleteAction($id = null) { if (!$this->acl->checkUserAccess(ActionsInterface::CLIENT_DELETE)) { return; } try { - $this->clientService->delete($id); + if ($id === null) { + $this->clientService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::CLIENT, $id); + $this->deleteCustomFieldsForItem(ActionsInterface::CLIENT, $id); - $this->eventDispatcher->notifyEvent('delete.client', - new Event($this, - EventMessage::factory() - ->addDescription(__u('Cliente eliminado')) - ->addDetail(__u('Cliente'), $id)) - ); + $this->eventDispatcher->notifyEvent('delete.client.selection', + new Event($this, + EventMessage::factory() + ->addDescription(__u('Clientes eliminados'))) + ); - $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Cliente eliminado')); + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Clientes eliminados')); + } else { + $this->clientService->delete($id); + + $this->deleteCustomFieldsForItem(ActionsInterface::CLIENT, $id); + + $this->eventDispatcher->notifyEvent('delete.client', + new Event($this, + EventMessage::factory() + ->addDescription(__u('Cliente eliminado')) + ->addDetail(__u('Cliente'), $id)) + ); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Cliente eliminado')); + } } catch (\Exception $e) { processException($e); diff --git a/app/modules/web/Controllers/ConfigManagerController.php b/app/modules/web/Controllers/ConfigManagerController.php index 6b14d03d..be491594 100644 --- a/app/modules/web/Controllers/ConfigManagerController.php +++ b/app/modules/web/Controllers/ConfigManagerController.php @@ -233,7 +233,7 @@ class ConfigManagerController extends ControllerBase $template->assign('mailSecurity', ['SSL', 'TLS']); $template->assign('configData', $this->configData); - $template->assign('numAccounts', $this->dic->get(AccountService::class)->getTotalNumAccounts()); + $template->assign('numAccounts', $this->dic->get(AccountService::class)->getTotalNumAccounts()->num); $template->assign('taskId', Task::genTaskId('masterpass')); $configService = $this->dic->get(ConfigService::class); diff --git a/app/modules/web/Controllers/ControllerBase.php b/app/modules/web/Controllers/ControllerBase.php index e9405e26..bb963b9a 100644 --- a/app/modules/web/Controllers/ControllerBase.php +++ b/app/modules/web/Controllers/ControllerBase.php @@ -191,7 +191,7 @@ abstract class ControllerBase } catch (FileNotFoundException $e) { processException($e); - echo $e->getMessage(); + echo __($e->getMessage()); } die(); diff --git a/app/modules/web/Controllers/CustomFieldController.php b/app/modules/web/Controllers/CustomFieldController.php index bf0e7075..7c71be23 100644 --- a/app/modules/web/Controllers/CustomFieldController.php +++ b/app/modules/web/Controllers/CustomFieldController.php @@ -28,6 +28,7 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; +use SP\Core\Events\EventMessage; use SP\Core\Exceptions\ValidationException; use SP\DataModel\CustomFieldDefinitionData; use SP\Forms\CustomFieldDefForm; @@ -175,20 +176,28 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function deleteAction($id) + public function deleteAction($id = null) { if (!$this->acl->checkUserAccess(ActionsInterface::CUSTOMFIELD_DELETE)) { return; } try { - $this->customFieldService->delete($id); + if ($id === null) { + $this->customFieldService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::CUSTOMFIELD, $id); + $this->eventDispatcher->notifyEvent('delete.customField.selection', + new Event($this, EventMessage::factory()->addDescription(__u('Campos eliminados'))) + ); - $this->eventDispatcher->notifyEvent('delete.customField', new Event($this)); + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Campos eliminados')); + } else { + $this->customFieldService->delete($id); - $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Campo eliminado')); + $this->eventDispatcher->notifyEvent('delete.customField', new Event($this)); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Campo eliminado')); + } } catch (\Exception $e) { processException($e); diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php index 0dccc68d..0c7e4e44 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php @@ -33,7 +33,6 @@ use SP\Core\Acl\UnauthorizedPageException; use SP\Core\Exceptions\SPException; use SP\DataModel\Dto\AccountAclDto; use SP\DataModel\Dto\AccountDetailsResponse; -use SP\Mgmt\Users\UserPass; use SP\Modules\Web\Controllers\Helpers\HelperBase; use SP\Modules\Web\Controllers\Traits\ItemTrait; use SP\Mvc\View\Components\SelectItemAdapter; @@ -41,6 +40,7 @@ use SP\Services\Account\AccountHistoryService; use SP\Services\Account\AccountService; use SP\Services\Category\CategoryService; use SP\Services\Client\ClientService; +use SP\Services\Crypt\MasterPassService; use SP\Services\PublicLink\PublicLinkService; use SP\Services\Tag\TagService; use SP\Services\User\UpdatedMasterPassException; @@ -160,6 +160,7 @@ class AccountHelper extends HelperBase /** * @throws UnauthorizedPageException * @throws UpdatedMasterPassException + * @throws \SP\Services\Config\ParameterNotFoundException */ public function checkActionAccess() { @@ -167,7 +168,7 @@ class AccountHelper extends HelperBase throw new UnauthorizedPageException(SPException::INFO); } - if (!UserPass::checkUserUpdateMPass($this->session->getUserData()->getId())) { + if (!$this->dic->get(MasterPassService::class)->checkUserUpdateMPass($this->session->getUserData()->getLastUpdateMPass())) { throw new UpdatedMasterPassException(SPException::INFO); } } @@ -253,6 +254,7 @@ class AccountHelper extends HelperBase * @throws \Psr\Container\NotFoundExceptionInterface * @throws \ReflectionException * @throws \SP\Core\Dic\ContainerException + * @throws \SP\Services\Config\ParameterNotFoundException */ public function setViewForBlank($actionId) { @@ -291,6 +293,7 @@ class AccountHelper extends HelperBase * @throws \Psr\Container\NotFoundExceptionInterface * @throws \ReflectionException * @throws \SP\Core\Dic\ContainerException + * @throws \SP\Services\Config\ParameterNotFoundException */ public function setViewForRequest(AccountDetailsResponse $accountDetailsResponse, $actionId) { diff --git a/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php index e7028d2d..20c2ae7e 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php @@ -29,9 +29,9 @@ use SP\Core\Acl\ActionsInterface; use SP\Core\Crypt\Crypt; use SP\Core\Crypt\Session as CryptSession; use SP\DataModel\AccountPassData; -use SP\Mgmt\Users\UserPass; use SP\Modules\Web\Controllers\Helpers\HelperBase; use SP\Modules\Web\Controllers\Helpers\HelperException; +use SP\Services\Crypt\MasterPassService; use SP\Util\ImageUtil; /** @@ -77,6 +77,7 @@ class AccountPasswordHelper extends HelperBase * @return string * @throws HelperException * @throws \Defuse\Crypto\Exception\CryptoException + * @throws \SP\Services\Config\ParameterNotFoundException */ protected function getPasswordClear(AccountPassData $accountData) { @@ -86,8 +87,7 @@ class AccountPasswordHelper extends HelperBase throw new HelperException(__u('No tiene permisos para acceder a esta cuenta')); } - // FIXME - if (!UserPass::checkUserUpdateMPass($this->session->getUserData()->getId())) { + if (!$this->dic->get(MasterPassService::class)->checkUserUpdateMPass($this->session->getUserData()->getLastUpdateMPass())) { throw new HelperException(__('Clave maestra actualizada') . '
' . __('Reinicie la sesión para cambiarla')); } diff --git a/app/modules/web/Controllers/Helpers/ItemsGridHelper.php b/app/modules/web/Controllers/Helpers/ItemsGridHelper.php index d677a881..a91af35f 100644 --- a/app/modules/web/Controllers/Helpers/ItemsGridHelper.php +++ b/app/modules/web/Controllers/Helpers/ItemsGridHelper.php @@ -42,6 +42,7 @@ use SP\Html\DataGrid\DataGridInterface; use SP\Html\DataGrid\DataGridPager; use SP\Html\DataGrid\DataGridTab; use SP\Repositories\CustomField\CustomFieldDefRepository; +use SP\Util\DateUtil; /** * Class Grids con las plantillas de tablas de datos @@ -1301,7 +1302,7 @@ class ItemsGridHelper extends HelperBase $GridActionClear->setIcon($this->icons->getIconClear()); $GridActionClear->setOnClickFunction('eventlog/clear'); $GridActionClear->addData('action-route', Acl::getActionRoute(ActionsInterface::EVENTLOG_CLEAR)); - $GridActionClear->addData('action-next', Acl::getActionRoute(ActionsInterface::EVENTLOG)); + $GridActionClear->addData('nextaction', Acl::getActionRoute(ActionsInterface::EVENTLOG)); $Grid->setDataActions($GridActionClear); @@ -1312,6 +1313,130 @@ class ItemsGridHelper extends HelperBase return $Grid; } + /** + * @param array $data + * @return DataGrid + * @throws \SP\Core\Dic\ContainerException + */ + public function getNoticesGrid(array $data) + { + $isAdminApp = $this->session->getUserData()->getIsAdminApp(); + + // Grid Header + $GridHeaders = new DataGridHeader(); + $GridHeaders->addHeader(__('Fecha')); + $GridHeaders->addHeader(__('Tipo')); + $GridHeaders->addHeader(__('Componente')); + $GridHeaders->addHeader(__('Descripción')); + $GridHeaders->addHeader(__('Estado')); + + // Grid Data + $GridData = new DataGridData(); + $GridData->setDataRowSourceId('id'); + $GridData->addDataRowSource('date', false, + function ($value) { + return DateUtil::getDateFromUnix($value); + }); + $GridData->addDataRowSource('type'); + $GridData->addDataRowSource('component'); + $GridData->addDataRowSource('description'); + $GridData->addDataRowSourceWithIcon('checked', $this->icons->getIconEnabled()->setTitle(__('Leída'))); + $GridData->addDataRowSourceWithIcon('onlyAdmin', $this->icons->getIconAppAdmin()->setTitle(__('Sólo Admins'))); + $GridData->addDataRowSourceWithIcon('sticky', $this->icons->getIconGroup()->setTitle(__('Global'))); + $GridData->setData($data); + + // Grid + $Grid = new DataGrid(); + $Grid->setId('tblNotifications'); + $Grid->setDataRowTemplate('datagrid-rows', 'grid'); + $Grid->setDataPagerTemplate('datagrid-nav-full', 'grid'); + $Grid->setHeader($GridHeaders); + $Grid->setData($GridData); + $Grid->setTitle(__('Notificaciones')); + $Grid->setTime(round(microtime() - $this->queryTimeStart, 5)); + + // Grid Actions + $GridActionSearch = new DataGridActionSearch(); + $GridActionSearch->setId(ActionsInterface::NOTIFICATION_SEARCH); + $GridActionSearch->setType(DataGridActionType::SEARCH_ITEM); + $GridActionSearch->setName('frmSearchNotification'); + $GridActionSearch->setTitle(__('Buscar Notificación')); + $GridActionSearch->setOnSubmitFunction('notification/search'); + $GridActionSearch->addData('action-route', Acl::getActionRoute(ActionsInterface::NOTIFICATION_SEARCH)); + + $Grid->setDataActions($GridActionSearch); + $Grid->setPager($this->getPager($GridActionSearch)); + + if ($isAdminApp) { + // Grid item's actions + $GridActionNew = new DataGridAction(); + $GridActionNew->setId(ActionsInterface::NOTIFICATION_CREATE); + $GridActionNew->setType(DataGridActionType::MENUBAR_ITEM); + $GridActionNew->setName(__('Nueva Notificación')); + $GridActionNew->setTitle(__('Nueva Notificación')); + $GridActionNew->setIcon($this->icons->getIconAdd()); + $GridActionNew->setSkip(true); + $GridActionNew->setOnClickFunction('notification/show'); + $GridActionNew->addData('action-route', Acl::getActionRoute(ActionsInterface::NOTIFICATION_CREATE)); + + $Grid->setDataActions($GridActionNew); + } + + $GridActionView = new DataGridAction(); + $GridActionView->setId(ActionsInterface::NOTIFICATION_VIEW); + $GridActionView->setType(DataGridActionType::VIEW_ITEM); + $GridActionView->setName(__('Ver Notificación')); + $GridActionView->setTitle(__('Ver Notificación')); + $GridActionView->setIcon($this->icons->getIconView()); + $GridActionView->setOnClickFunction('notification/show'); + $GridActionView->addData('action-route', Acl::getActionRoute(ActionsInterface::NOTIFICATION_VIEW)); + + $Grid->setDataActions($GridActionView); + + $GridActionCheck = new DataGridAction(); + $GridActionCheck->setId(ActionsInterface::NOTIFICATION_CHECK); + $GridActionCheck->setName(__('Marcar Notificación')); + $GridActionCheck->setTitle(__('Marcar Notificación')); + $GridActionCheck->setIcon($this->icons->getIconEnabled()); + $GridActionCheck->setOnClickFunction('notification/check'); + $GridActionCheck->setFilterRowSource('checked'); + $GridActionCheck->addData('action-route', Acl::getActionRoute(ActionsInterface::NOTIFICATION_CHECK)); + $GridActionCheck->addData('nextaction', Acl::getActionRoute(ActionsInterface::NOTIFICATION)); + + $Grid->setDataActions($GridActionCheck); + + $GridActionEdit = new DataGridAction(); + $GridActionEdit->setId(ActionsInterface::NOTIFICATION_EDIT); + $GridActionEdit->setName(__('Editar Notificación')); + $GridActionEdit->setTitle(__('Editar Notificación')); + $GridActionEdit->setIcon($this->icons->getIconEdit()); + $GridActionEdit->setOnClickFunction('notification/show'); + $GridActionEdit->addData('action-route', Acl::getActionRoute(ActionsInterface::NOTIFICATION_EDIT)); + + $Grid->setDataActions($GridActionEdit); + + $GridActionDel = new DataGridAction(); + $GridActionDel->setId(ActionsInterface::NOTIFICATION_DELETE); + $GridActionDel->setType(DataGridActionType::DELETE_ITEM); + $GridActionDel->setName(__('Eliminar Notificación')); + $GridActionDel->setTitle(__('Eliminar Notificación')); + $GridActionDel->setIcon($this->icons->getIconDelete()); + $GridActionDel->setOnClickFunction('notification/delete'); + $GridActionDel->addData('action-route', Acl::getActionRoute(ActionsInterface::NOTIFICATION_DELETE)); + $GridActionDel->addData('nextaction', Acl::getActionRoute(ActionsInterface::NOTIFICATION)); + + if (!$isAdminApp) { + $GridActionCheck->setFilterRowSource('sticky'); + $GridActionEdit->setFilterRowSource('sticky'); + $GridActionDel->setFilterRowSource('sticky'); + } + + $Grid->setDataActions($GridActionDel); + $Grid->setDataActions($GridActionDel, true); + + return $Grid; + } + /** * Actualizar los datos del paginador * diff --git a/app/modules/web/Controllers/Helpers/LayoutHelper.php b/app/modules/web/Controllers/Helpers/LayoutHelper.php index c6049ed7..aac03e22 100644 --- a/app/modules/web/Controllers/Helpers/LayoutHelper.php +++ b/app/modules/web/Controllers/Helpers/LayoutHelper.php @@ -35,7 +35,6 @@ use SP\Core\SessionUtil; use SP\Core\UI\Theme; use SP\Core\UI\ThemeInterface; use SP\Html\DataGrid\DataGridAction; -use SP\Mgmt\Notices\Notice; use SP\Util\Checks; use SP\Util\Util; @@ -228,7 +227,7 @@ class LayoutHelper extends HelperBase $this->view->assign('userName', $userData->getName() ?: mb_strtoupper($this->view->userLogin)); $this->view->assign('userGroup', $userData->getUserGroupId()); $this->view->assign('showPassIcon', !($this->configData->isLdapEnabled() && $userData->getIsLdap())); - $this->view->assign('userNotices', count(Notice::getItem()->getAllActiveForUser())); + $this->view->assign('notifications', 0); } /** diff --git a/app/modules/web/Controllers/ItemsController.php b/app/modules/web/Controllers/ItemsController.php index bfa0d73e..7cd740e1 100644 --- a/app/modules/web/Controllers/ItemsController.php +++ b/app/modules/web/Controllers/ItemsController.php @@ -24,13 +24,13 @@ namespace SP\Modules\Web\Controllers; -use SP\Core\SessionUtil; use SP\DataModel\DataModelInterface; use SP\Http\JsonResponse; use SP\Mvc\View\Components\SelectItemAdapter; use SP\Services\Account\AccountService; use SP\Services\Category\CategoryService; use SP\Services\Client\ClientService; +use SP\Services\Notification\NotificationService; use SP\Util\Json; /** @@ -40,19 +40,10 @@ use SP\Util\Json; */ class ItemsController extends SimpleControllerBase { - /** - * ItemsController constructor. - */ - protected function initialize() - { - $this->checks(); - } - /** * Devolver las cuentas visibles por el usuario * * @param int $accountId - * @throws \Psr\Container\ContainerExceptionInterface */ public function accountsUserAction($accountId = null) { @@ -69,14 +60,12 @@ class ItemsController extends SimpleControllerBase $jsonResponse = new JsonResponse(); $jsonResponse->setStatus(0); $jsonResponse->setData($outItems); - $jsonResponse->setCsrf(SessionUtil::getSessionKey()); + $jsonResponse->setCsrf($this->session->getSecurityKey()); Json::returnJson($jsonResponse); } /** - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Exceptions\SPException */ public function clientsAction() @@ -85,8 +74,6 @@ class ItemsController extends SimpleControllerBase } /** - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Exceptions\SPException */ public function categoriesAction() @@ -94,6 +81,22 @@ class ItemsController extends SimpleControllerBase Json::returnRawJson(SelectItemAdapter::factory($this->dic->get(CategoryService::class)->getAllBasic())->getJsonItemsFromModel()); } + /** + * @throws \SP\Core\Exceptions\SPException + */ + public function notificationsAction() + { + Json::returnRawJson(Json::getJson($this->dic->get(NotificationService::class)->getAllActiveForUserId($this->session->getUserData()->getId()))); + } + + /** + * ItemsController constructor. + */ + protected function initialize() + { + $this->checks(); + } + /** * Preparar los elementos para devolverlos * diff --git a/app/modules/web/Controllers/LoginController.php b/app/modules/web/Controllers/LoginController.php index 03abaf20..fe9cd034 100644 --- a/app/modules/web/Controllers/LoginController.php +++ b/app/modules/web/Controllers/LoginController.php @@ -24,6 +24,8 @@ namespace SP\Modules\Web\Controllers; +use SP\Core\Events\Event; +use SP\Core\Events\EventMessage; use SP\Core\SessionFactory; use SP\Core\SessionUtil; use SP\Html\Html; @@ -62,19 +64,20 @@ class LoginController extends ControllerBase public function logoutAction() { if ($this->session->isLoggedIn()) { -// $inactiveTime = abs(round((time() - SessionFactory::getLastActivity()) / 60, 2)); -// $totalTime = abs(round((time() - SessionFactory::getStartActivity()) / 60, 2)); + $inactiveTime = abs(round((time() - $this->session->getLastActivity()) / 60, 2)); + $totalTime = abs(round((time() - $this->session->getStartActivity()) / 60, 2)); -// $Log = new Log(); -// $LogMessage = $Log->getLogMessage(); -// $LogMessage->setAction(__u('Finalizar sesión')); -// $LogMessage->addDetails(__u('Usuario'), SessionFactory::getUserData()->getLogin()); -// $LogMessage->addDetails(__u('Tiempo inactivo'), $inactiveTime . ' min.'); -// $LogMessage->addDetails(__u('Tiempo total'), $totalTime . ' min.'); -// $Log->writeLog(); + $this->eventDispatcher->notifyEvent('logout', + new Event($this, EventMessage::factory() + ->addDescription(__u('Finalizar sesión')) + ->addDetail(__u('Usuario'), $this->session->getUserData()->getLogin()) + ->addDetail(__u('Tiempo inactivo'), $inactiveTime . ' min.') + ->addDetail(__u('Tiempo total'), $totalTime . ' min.')) + ); SessionUtil::cleanSession(); - SessionFactory::setLoggedOut(true); + + $this->session->setLoggedOut(true); $layoutHelper = $this->dic->get(LayoutHelper::class); $layoutHelper->getCustomLayout('logout', 'logout'); diff --git a/app/modules/web/Controllers/NotificationController.php b/app/modules/web/Controllers/NotificationController.php new file mode 100644 index 00000000..9fbebedf --- /dev/null +++ b/app/modules/web/Controllers/NotificationController.php @@ -0,0 +1,366 @@ +. + */ + +namespace SP\Modules\Web\Controllers; + +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; +use SP\Core\Acl\Acl; +use SP\Core\Acl\ActionsInterface; +use SP\Core\Events\Event; +use SP\Core\Events\EventMessage; +use SP\DataModel\NotificationData; +use SP\Forms\NotificationForm; +use SP\Http\JsonResponse; +use SP\Modules\Web\Controllers\Helpers\ItemsGridHelper; +use SP\Modules\Web\Controllers\Traits\ItemTrait; +use SP\Modules\Web\Controllers\Traits\JsonTrait; +use SP\Mvc\Controller\CrudControllerInterface; +use SP\Mvc\View\Components\SelectItemAdapter; +use SP\Services\Notification\NotificationService; +use SP\Services\User\UserService; + +/** + * Class NotificationController + * + * @package SP\Modules\Web\Controllers + */ +class NotificationController extends ControllerBase implements CrudControllerInterface +{ + use JsonTrait, ItemTrait; + + /** + * @var NotificationService + */ + protected $notificationService; + + /** + * @throws \SP\Core\Dic\ContainerException + */ + public function indexAction() + { + if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION)) { + return; + } + + $this->view->addTemplate('index'); + + $this->view->assign('data', $this->getSearchGrid()); + + $this->view(); + } + + /** + * @return $this + * @throws \SP\Core\Dic\ContainerException + */ + protected function getSearchGrid() + { + $itemsGridHelper = $this->dic->get(ItemsGridHelper::class); + $itemSearchData = $this->getSearchData($this->configData); + + return $itemsGridHelper->updatePager($itemsGridHelper->getNoticesGrid($this->notificationService->search($itemSearchData)), $itemSearchData); + } + + /** + * View action + * + * @param $id + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function viewAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION_CREATE)) { + return; + } + + $this->view->assign('header', __('Ver Notificación')); + $this->view->assign('isView', true); + + try { + $this->setViewData($id); + + $this->eventDispatcher->notifyEvent('show.notification', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); + } catch (\Exception $e) { + processException($e); + + $this->returnJsonResponseException($e); + } + } + + /** + * Sets view data for displaying user's data + * + * @param $notificationId + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + protected function setViewData($notificationId = null) + { + $this->view->addTemplate('notification'); + + $notification = $notificationId ? $this->notificationService->getById($notificationId) : new NotificationData(); + + $this->view->assign('notification', $notification); + + if ($this->userData->getIsAdminApp()) { + $this->view->assign('users', SelectItemAdapter::factory(UserService::getItemsBasic())->getItemsFromModelSelected([$notification->userId])); + } + + $this->view->assign('sk', $this->session->generateSecurityKey()); + $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::NOTIFICATION)); + + if ($this->view->isView === true) { + $this->view->assign('disabled', 'disabled'); + $this->view->assign('readonly', 'readonly'); + } else { + $this->view->assign('disabled'); + $this->view->assign('readonly'); + } + } + + /** + * Search action + * + * @throws \SP\Core\Dic\ContainerException + */ + public function searchAction() + { + if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION_SEARCH)) { + return; + } + + $this->view->addTemplate('datagrid-table', 'grid'); + $this->view->assign('data', $this->getSearchGrid()); + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Create action + * + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function createAction() + { + if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION_CREATE)) { + return; + } + + $this->view->assign(__FUNCTION__, 1); + $this->view->assign('header', __('Nueva Notificación')); + $this->view->assign('isView', false); + $this->view->assign('route', 'notification/saveCreate'); + + try { + $this->setViewData(); + + $this->eventDispatcher->notifyEvent('show.notification.create', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); + } catch (\Exception $e) { + processException($e); + + $this->returnJsonResponseException($e); + } + } + + /** + * Edit action + * + * @param $id + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function editAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION_EDIT)) { + return; + } + + $this->view->assign(__FUNCTION__, 1); + $this->view->assign('header', __('Editar Notificación')); + $this->view->assign('isView', false); + $this->view->assign('route', 'notification/saveEdit/' . $id); + + try { + $this->setViewData($id); + + $this->eventDispatcher->notifyEvent('show.notification.edit', new Event($this)); + + $this->returnJsonResponseData(['html' => $this->render()]); + } catch (\Exception $e) { + processException($e); + + $this->returnJsonResponseException($e); + } + } + + /** + * Delete action + * + * @param $id + */ + public function deleteAction($id = null) + { + if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION_DELETE)) { + return; + } + + try { + if ($id === null) { + if ($this->userData->getIsAdminApp()) { + $this->notificationService->deleteAdminBatch($this->getItemsIdFromRequest()); + } else { + $this->notificationService->deleteByIdBatch($this->getItemsIdFromRequest()); + } + + $this->eventDispatcher->notifyEvent('delete.notification.selection', + new Event($this, + EventMessage::factory() + ->addDescription(__u('Notificaciones eliminadas'))) + ); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Notificaciones eliminadas')); + } else { + if ($this->userData->getIsAdminApp()) { + $this->notificationService->deleteAdmin($id); + } else { + $this->notificationService->delete($id); + } + + $this->eventDispatcher->notifyEvent('delete.notification', + new Event($this, + EventMessage::factory() + ->addDescription(__u('Notificación eliminada')) + ->addDetail(__u('Notificación'), $id)) + ); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Notificación eliminada')); + } + } catch (\Exception $e) { + processException($e); + + $this->returnJsonResponseException($e); + } + } + + /** + * Check action + * + * @param $id + */ + public function checkAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION_CHECK)) { + return; + } + + try { + $this->notificationService->setCheckedById($id); + + $this->eventDispatcher->notifyEvent('check.notification', + new Event($this, + EventMessage::factory() + ->addDescription(__u('Notificación leída')) + ->addDetail(__u('Notificación'), $id)) + ); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Notificación leída')); + } catch (\Exception $e) { + processException($e); + + $this->returnJsonResponseException($e); + } + } + + /** + * Saves create action + */ + public function saveCreateAction() + { + if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION_CREATE)) { + return; + } + + try { + $form = new NotificationForm(); + $form->validate(ActionsInterface::NOTIFICATION_CREATE); + + $this->notificationService->create($form->getItemData()); + + $this->eventDispatcher->notifyEvent('create.notification', + new Event($this, + EventMessage::factory() + ->addDescription(__u('Notificación creada'))) + ); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Notificación creada')); + } catch (\Exception $e) { + processException($e); + + $this->returnJsonResponseException($e); + } + } + + /** + * Saves edit action + * + * @param $id + */ + public function saveEditAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION_EDIT)) { + return; + } + + try { + $form = new NotificationForm($id); + $form->validate(ActionsInterface::NOTIFICATION_EDIT); + + $this->notificationService->update($form->getItemData()); + + $this->eventDispatcher->notifyEvent('edit.notification', + new Event($this, + EventMessage::factory() + ->addDescription(__u('Notificación actualizada'))) + ); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Notificación actualizada')); + } catch (\Exception $e) { + processException($e); + + $this->returnJsonResponseException($e); + } + } + + protected function initialize() + { + $this->notificationService = $this->dic->get(NotificationService::class); + } +} \ No newline at end of file diff --git a/app/modules/web/Controllers/PublicLinkController.php b/app/modules/web/Controllers/PublicLinkController.php index 417b09c7..48220fc8 100644 --- a/app/modules/web/Controllers/PublicLinkController.php +++ b/app/modules/web/Controllers/PublicLinkController.php @@ -27,6 +27,7 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; +use SP\Core\Events\EventMessage; use SP\Core\Exceptions\SPException; use SP\Core\Exceptions\ValidationException; use SP\DataModel\PublicLinkListData; @@ -200,21 +201,37 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function deleteAction($id) + public function deleteAction($id = null) { if (!$this->acl->checkUserAccess(ActionsInterface::PUBLICLINK_DELETE)) { return; } try { -// $this->publicLinkService->logAction($id, ActionsInterface::PROFILE_DELETE); - $this->publicLinkService->delete($id); + if ($id === null) { + $this->publicLinkService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::PUBLICLINK, $id); + $this->deleteCustomFieldsForItem(ActionsInterface::PUBLICLINK, $id); - $this->eventDispatcher->notifyEvent('delete.publicLink', new Event($this)); + $this->eventDispatcher->notifyEvent('delete.publicLink.selection', + new Event($this, EventMessage::factory() + ->addDescription(__u('Enlaces eliminados'))) + ); - $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Enlace eliminado')); + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Enlaces eliminados')); + } else { + $this->publicLinkService->delete($id); + + $this->deleteCustomFieldsForItem(ActionsInterface::PUBLICLINK, $id); + + $this->eventDispatcher->notifyEvent('delete.publicLink', + new Event($this, EventMessage::factory() + ->addDescription(__u('Enlace eliminado')) + ->addDetail(__u('Enlace'), $id)) + ); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Enlace eliminado')); + } } catch (\Exception $e) { processException($e); diff --git a/app/modules/web/Controllers/TagController.php b/app/modules/web/Controllers/TagController.php index c9ba6f9a..afa0adb3 100644 --- a/app/modules/web/Controllers/TagController.php +++ b/app/modules/web/Controllers/TagController.php @@ -168,20 +168,30 @@ class TagController extends ControllerBase implements CrudControllerInterface * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function deleteAction($id) + public function deleteAction($id = null) { if (!$this->acl->checkUserAccess(ActionsInterface::TAG_DELETE)) { return; } try { - $this->tagService->delete($id); + if ($id === null) { + $this->tagService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::TAG, $id); + $this->deleteCustomFieldsForItem(ActionsInterface::TAG, $id); - $this->eventDispatcher->notifyEvent('delete.tag', new Event($this)); + $this->eventDispatcher->notifyEvent('delete.tag.selection', new Event($this)); - $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Etiqueta eliminada')); + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Etiquetas eliminadas')); + } else { + $this->tagService->delete($id); + + $this->deleteCustomFieldsForItem(ActionsInterface::TAG, $id); + + $this->eventDispatcher->notifyEvent('delete.tag', new Event($this)); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Etiqueta eliminada')); + } } catch (\Exception $e) { processException($e); @@ -286,5 +296,4 @@ class TagController extends ControllerBase implements CrudControllerInterface $this->tagService = $this->dic->get(TagService::class); } - } \ No newline at end of file diff --git a/app/modules/web/Controllers/Traits/ItemTrait.php b/app/modules/web/Controllers/Traits/ItemTrait.php index 221a2ce3..a4ec9606 100644 --- a/app/modules/web/Controllers/Traits/ItemTrait.php +++ b/app/modules/web/Controllers/Traits/ItemTrait.php @@ -135,7 +135,13 @@ trait ItemTrait */ protected function deleteCustomFieldsForItem($moduleId, $itemId) { - Bootstrap::getContainer()->get(CustomFieldService::class)->deleteCustomFieldData($itemId, $moduleId); + $customFieldService = Bootstrap::getContainer()->get(CustomFieldService::class); + + if (is_array($itemId)) { + $customFieldService->deleteCustomFieldDataBatch($itemId, $moduleId); + } else { + $customFieldService->deleteCustomFieldData($itemId, $moduleId); + } } /** @@ -189,4 +195,12 @@ trait ItemTrait return $itemSearchData; } + + /** + * @return mixed + */ + protected function getItemsIdFromRequest() + { + return Request::analyze('items', 0); + } } \ No newline at end of file diff --git a/app/modules/web/Controllers/UserController.php b/app/modules/web/Controllers/UserController.php index f79cda34..88164741 100644 --- a/app/modules/web/Controllers/UserController.php +++ b/app/modules/web/Controllers/UserController.php @@ -27,6 +27,7 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; +use SP\Core\Events\EventMessage; use SP\Core\Exceptions\ValidationException; use SP\Core\SessionUtil; use SP\DataModel\UserData; @@ -214,7 +215,7 @@ class UserController extends ControllerBase implements CrudControllerInterface * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function deleteAction($id) + public function deleteAction($id = null) { if (!$this->acl->checkUserAccess(ActionsInterface::USER_DELETE)) { return; @@ -223,14 +224,29 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->view->assign(__FUNCTION__, 1); try { -// $this->userService->logAction($id, ActionsInterface::USER_DELETE); - $this->userService->delete($id); + if ($id === null) { + $this->userService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::USER, $id); + $this->deleteCustomFieldsForItem(ActionsInterface::USER, $id); - $this->eventDispatcher->notifyEvent('delete.user', new Event($this)); + $this->eventDispatcher->notifyEvent('delete.user.selection', + new Event($this, EventMessage::factory()->addDescription(__u('Usuarios eliminados'))) + ); - $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Usuario eliminado')); + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Usuarios eliminados')); + } else { + $this->userService->delete($id); + + $this->deleteCustomFieldsForItem(ActionsInterface::USER, $id); + + $this->eventDispatcher->notifyEvent('delete.user', + new Event($this, EventMessage::factory() + ->addDescription(__u('Usuario eliminado')) + ->addDetail(__u('Usuario'), $id)) + ); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Usuario eliminado')); + } } catch (\Exception $e) { processException($e); diff --git a/app/modules/web/Controllers/UserGroupController.php b/app/modules/web/Controllers/UserGroupController.php index ab0a4276..9b200b19 100644 --- a/app/modules/web/Controllers/UserGroupController.php +++ b/app/modules/web/Controllers/UserGroupController.php @@ -27,6 +27,7 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; +use SP\Core\Events\EventMessage; use SP\Core\Exceptions\ValidationException; use SP\DataModel\UserGroupData; use SP\Forms\UserGroupForm; @@ -178,21 +179,36 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function deleteAction($id) + public function deleteAction($id = null) { if (!$this->acl->checkUserAccess(ActionsInterface::GROUP_DELETE)) { return; } try { -// $this->userGroupService->logAction($id, ActionsInterface::GROUP_DELETE); - $this->userGroupService->delete($id); + if ($id === null) { + $this->userGroupService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::GROUP, $id); + $this->deleteCustomFieldsForItem(ActionsInterface::GROUP, $id); - $this->eventDispatcher->notifyEvent('delete.userGroup', new Event($this)); + $this->eventDispatcher->notifyEvent('delete.userGroup.selection', + new Event($this, EventMessage::factory()->addDescription(__u('Grupos eliminados'))) + ); - $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Grupo eliminado')); + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Grupos eliminados')); + } else { + $this->userGroupService->delete($id); + + $this->deleteCustomFieldsForItem(ActionsInterface::GROUP, $id); + + $this->eventDispatcher->notifyEvent('delete.userGroup', + new Event($this, EventMessage::factory() + ->addDescription(__u('Grupo eliminado')) + ->addDetail(__u('Grupo'), $id)) + ); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Grupo eliminado')); + } } catch (\Exception $e) { processException($e); @@ -215,13 +231,15 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf $groupData = $form->getItemData(); - $id = $this->userGroupService->create($groupData); -// $this->userGroupService->logAction($id, ActionsInterface::GROUP_CREATE); - $this->userToUserGroupService->add($id, $groupData->getUsers()); + $id = $this->userGroupService->create($groupData, $groupData->getUsers()); $this->addCustomFieldsForItem(ActionsInterface::GROUP, $id); - $this->eventDispatcher->notifyEvent('create.userGroup', new Event($this)); + $this->eventDispatcher->notifyEvent('create.userGroup', + new Event($this, EventMessage::factory() + ->addDescription(__u('Grupo creado')) + ->addDetail(__u('Nombre'), $groupData->getName())) + ); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Grupo creado')); } catch (ValidationException $e) { @@ -253,12 +271,14 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf $groupData = $form->getItemData(); $this->userGroupService->update($groupData); -// $this->userGroupService->logAction($id, ActionsInterface::GROUP_EDIT); - $this->userToUserGroupService->update($groupData->getId(), $groupData->getUsers()); $this->updateCustomFieldsForItem(ActionsInterface::GROUP, $id); - $this->eventDispatcher->notifyEvent('edit.useGroup', new Event($this)); + $this->eventDispatcher->notifyEvent('edit.userGroup', + new Event($this, EventMessage::factory() + ->addDescription(__u('Grupo actualizado')) + ->addDetail(__u('Nombre'), $groupData->getName())) + ); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Grupo actualizado')); } catch (ValidationException $e) { @@ -310,6 +330,6 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf $this->checkLoggedIn(); $this->userGroupService = $this->dic->get(UserGroupService::class); - $this->userToUserGroupService = $this->dic->get(UserToUserGroupService::class); + $this->userToUserGroupService = $this->dic->get(UserToUserGroupService::class); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/UserProfileController.php b/app/modules/web/Controllers/UserProfileController.php index 884cdd8a..34e067c3 100644 --- a/app/modules/web/Controllers/UserProfileController.php +++ b/app/modules/web/Controllers/UserProfileController.php @@ -27,8 +27,10 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; +use SP\Core\Events\EventMessage; use SP\Core\Exceptions\ValidationException; use SP\DataModel\ProfileData; +use SP\DataModel\UserProfileData; use SP\Forms\UserProfileForm; use SP\Http\JsonResponse; use SP\Http\Request; @@ -115,9 +117,10 @@ class UserProfileController extends ControllerBase implements CrudControllerInte { $this->view->addTemplate('userprofile', 'itemshow'); - $profile = $profileId ? $this->userProfileService->getById($profileId) : new ProfileData(); + $profile = $profileId ? $this->userProfileService->getById($profileId) : new UserProfileData(); $this->view->assign('profile', $profile); + $this->view->assign('profileData', $profile->getProfile() ?: new ProfileData()); $this->view->assign('sk', $this->session->generateSecurityKey()); $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ACCESS_MANAGE)); @@ -171,21 +174,36 @@ class UserProfileController extends ControllerBase implements CrudControllerInte * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function deleteAction($id) + public function deleteAction($id = null) { if (!$this->acl->checkUserAccess(ActionsInterface::PROFILE_DELETE)) { return; } try { -// $this->userProfileService->logAction($id, ActionsInterface::PROFILE_DELETE); - $this->userProfileService->delete($id); + if ($id === null) { + $this->userProfileService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::PROFILE, $id); + $this->deleteCustomFieldsForItem(ActionsInterface::PROFILE, $id); - $this->eventDispatcher->notifyEvent('delete.userProfile', new Event($this)); + $this->eventDispatcher->notifyEvent('delete.userProfile.selection', + new Event($this, EventMessage::factory()->addDescription(__u('Perfiles eliminados'))) + ); - $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Perfil eliminado')); + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Perfiles eliminados')); + } else { + $this->userProfileService->delete($id); + + $this->deleteCustomFieldsForItem(ActionsInterface::PROFILE, $id); + + $this->eventDispatcher->notifyEvent('delete.userProfile', + new Event($this, EventMessage::factory() + ->addDescription(__u('Perfil eliminado')) + ->addDetail(__u('Perfil'), $id)) + ); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Perfil eliminado')); + } } catch (\Exception $e) { processException($e); @@ -209,7 +227,6 @@ class UserProfileController extends ControllerBase implements CrudControllerInte $profileData = $form->getItemData(); $id = $this->userProfileService->create($profileData); -// $this->userProfileService->logAction($id, ActionsInterface::PROFILE_CREATE); $this->addCustomFieldsForItem(ActionsInterface::PROFILE, $id); diff --git a/app/modules/web/themes/material-blue/views/_partials/fixed-header.inc b/app/modules/web/themes/material-blue/views/_partials/fixed-header.inc index 9cfd2b6c..33e3ce79 100644 --- a/app/modules/web/themes/material-blue/views/_partials/fixed-header.inc +++ b/app/modules/web/themes/material-blue/views/_partials/fixed-header.inc @@ -27,28 +27,21 @@ class="mdl-tooltip mdl-tooltip--bottom">getTitle(); ?> - 0): ?> - - notifications - + + notifications + - - - - notifications - - - + + 0): ?> + + + + + @@ -101,24 +94,22 @@ - 0): ?> - - notifications - - - - - notifications - - - + + notifications + + + + 0): ?> + + + + + + - -
- -
- - - ' . __('No se encontraron registros') . ''); ?> - - -
- - - - - - - - - - - - - - - log_description) : preg_replace("/\d+\.\d+\.\d+\.\d+/", "*.*.*.*", utf8_decode($log->log_description)); ?> - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- log_id; ?> - - log_date; ?> - - log_level; ?> - - log_action); ?> - - log_login); ?> - - log_ipAddress) : $log->log_ipAddress; ?> - - ', $text); - $text = preg_replace('/(UPDATE|DELETE|TRUNCATE|INSERT|SELECT|WHERE|LEFT|ORDER|LIMIT|FROM)/', '
\\1', $text); - } - - if (strlen($text) >= 150) { - echo wordwrap($text, 150, '
', true); - } else { - echo $text . '
'; - } - } - ?> -
-
-
-
- getTotalRows(); ?> @ s -
-
- getLimitStart() > 1): ?> - getIconFirst()->getIcon(); ?> - getIconPrev()->getIcon(); ?> - -   - getFirstPage(), '/', $Pager->getLastPage(); ?> -   - getLimitStart() < $Pager->getTotalRows() && $Pager->getFirstPage() != $Pager->getLastPage()): ?> - getIconNext()->getIcon(); ?> - getIconLast()->getIcon(); ?> - -
-
- -
- -
\ No newline at end of file diff --git a/app/modules/web/themes/material-blue/views/grid/datagrid-grid.inc b/app/modules/web/themes/material-blue/views/grid/datagrid-grid.inc index 36608d98..841fa983 100644 --- a/app/modules/web/themes/material-blue/views/grid/datagrid-grid.inc +++ b/app/modules/web/themes/material-blue/views/grid/datagrid-grid.inc @@ -19,7 +19,7 @@ if (!isset($index)): $index = 0; endif; id="btn-add-getId(); ?>" type="button" class="btn-action mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-button--colored mdl-color--indigo-A200 mdl-js-ripple-effect" - data-nextaction-id="getOnCloseAction(); ?>" + data-nextaction="getOnCloseAction(); ?>" data-onclick="getOnClick(); ?>" getData() as $dataName => $dataValue): echo 'data-', $dataName, '=', '"', $dataValue, '"'; endforeach; ?>> getIcon()->getIcon(); ?> @@ -78,20 +78,21 @@ if (!isset($index)): $index = 0; endif; getIconBack()->getTitle(); ?> + getDataActionsMenu()) > 0): ?>
  • -