diff --git a/app/modules/web/Controllers/AccessManagerController.php b/app/modules/web/Controllers/AccessManagerController.php index 6234f9e2..08e646d4 100644 --- a/app/modules/web/Controllers/AccessManagerController.php +++ b/app/modules/web/Controllers/AccessManagerController.php @@ -2,8 +2,8 @@ /** * sysPass * - * @author nuxsmin - * @link https://syspass.org + * @author nuxsmin + * @link https://syspass.org * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. @@ -25,7 +25,6 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; -use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; use SP\DataModel\ItemSearchData; use SP\Http\Request; @@ -58,8 +57,8 @@ class AccessManagerController extends ControllerBase protected $tabsGridHelper; /** - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ public function indexAction() { @@ -69,8 +68,8 @@ class AccessManagerController extends ControllerBase /** * Returns a tabbed grid with items * - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ protected function getGridTabs() { @@ -80,29 +79,29 @@ class AccessManagerController extends ControllerBase $this->itemsGridHelper = $this->dic->get(ItemsGridHelper::class); $this->tabsGridHelper = $this->dic->get(TabsGridHelper::class); - if ($this->checkAccess(ActionsInterface::USER)) { + if ($this->checkAccess(Acl::USER)) { $this->tabsGridHelper->addTab($this->getUsersList()); } - if ($this->checkAccess(ActionsInterface::GROUP)) { + if ($this->checkAccess(Acl::GROUP)) { $this->tabsGridHelper->addTab($this->getUsersGroupList()); } - if ($this->checkAccess(ActionsInterface::PROFILE)) { + if ($this->checkAccess(Acl::PROFILE)) { $this->tabsGridHelper->addTab($this->getUsersProfileList()); } - if ($this->checkAccess(ActionsInterface::AUTHTOKEN)) { + if ($this->checkAccess(Acl::AUTHTOKEN)) { $this->tabsGridHelper->addTab($this->getApiTokensList()); } - if ($this->configData->isPublinksEnabled() && $this->checkAccess(ActionsInterface::PUBLICLINK)) { + if ($this->configData->isPublinksEnabled() && $this->checkAccess(Acl::PUBLICLINK)) { $this->tabsGridHelper->addTab($this->getPublicLinksList()); } $this->eventDispatcher->notifyEvent('show.itemlist.accesses', new Event($this)); - $this->tabsGridHelper->renderTabs(Acl::getActionRoute(ActionsInterface::ACCESS_MANAGE), Request::analyzeInt('tabIndex', 0)); + $this->tabsGridHelper->renderTabs(Acl::getActionRoute(Acl::ACCESS_MANAGE), Request::analyzeInt('tabIndex', 0)); $this->view(); } @@ -111,8 +110,8 @@ class AccessManagerController extends ControllerBase * Returns users' data tab * * @return \SP\Html\DataGrid\DataGridTab - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ protected function getUsersList() { @@ -124,8 +123,8 @@ class AccessManagerController extends ControllerBase * Returns users group data tab * * @return \SP\Html\DataGrid\DataGridTab - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ protected function getUsersGroupList() { @@ -136,8 +135,8 @@ class AccessManagerController extends ControllerBase * Returns users profile data tab * * @return \SP\Html\DataGrid\DataGridTab - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ protected function getUsersProfileList() { @@ -160,8 +159,8 @@ class AccessManagerController extends ControllerBase * Returns public links data tab * * @return \SP\Html\DataGrid\DataGridTab - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ protected function getPublicLinksList() { @@ -175,6 +174,7 @@ class AccessManagerController extends ControllerBase { return $this->tabsGridHelper; } + /** * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface diff --git a/app/modules/web/Controllers/AccountController.php b/app/modules/web/Controllers/AccountController.php index b72f8a44..7104dd14 100644 --- a/app/modules/web/Controllers/AccountController.php +++ b/app/modules/web/Controllers/AccountController.php @@ -27,7 +27,6 @@ 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\Context\SessionContext; use SP\Core\Crypt\Vault; use SP\Core\Events\Event; @@ -126,6 +125,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * View action * * @param int $id Account's ID + * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ @@ -140,7 +140,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $accountHelper = $this->dic->get(AccountHelper::class); $accountHelper->setIsView(true); - $accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_VIEW); + $accountHelper->setViewForAccount($accountDetailsResponse, Acl::ACCOUNT_VIEW); $this->view->addTemplate('account'); $this->view->assign('title', @@ -171,6 +171,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * View public link action * * @param string $hash Link's hash + * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ @@ -211,7 +212,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac if ($this->view->useImage) { $this->view->assign('accountPassImage', ImageUtil::convertText($accountData->getPass())); } else { - $this->view->assign('copyPassRoute', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW_PASS)); + $this->view->assign('copyPassRoute', Acl::getActionRoute(Acl::ACCOUNT_VIEW_PASS)); } $this->view->assign('accountData', $accountData); @@ -245,7 +246,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac { try { $accountHelper = $this->dic->get(AccountHelper::class); - $accountHelper->setViewForBlank(ActionsInterface::ACCOUNT_CREATE); + $accountHelper->setViewForBlank(Acl::ACCOUNT_CREATE); $this->view->addTemplate('account'); $this->view->assign('title', @@ -275,6 +276,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Copy action * * @param int $id Account's ID + * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ @@ -288,7 +290,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac ->withTagsById($accountDetailsResponse); $accountHelper = $this->dic->get(AccountHelper::class); - $accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_COPY); + $accountHelper->setViewForAccount($accountDetailsResponse, Acl::ACCOUNT_COPY); $this->view->addTemplate('account'); $this->view->assign('title', @@ -318,6 +320,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Edit action * * @param int $id Account's ID + * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ @@ -331,7 +334,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac ->withTagsById($accountDetailsResponse); $accountHelper = $this->dic->get(AccountHelper::class); - $accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_EDIT); + $accountHelper->setViewForAccount($accountDetailsResponse, Acl::ACCOUNT_EDIT); $this->view->addTemplate('account'); $this->view->assign('title', @@ -363,6 +366,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Delete action * * @param int $id Account's ID + * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ @@ -375,7 +379,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac ->withUserGroupsById($accountDetailsResponse); $accountHelper = $this->dic->get(AccountHelper::class); - $accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_DELETE); + $accountHelper->setViewForAccount($accountDetailsResponse, Acl::ACCOUNT_DELETE); $this->view->addTemplate('account'); $this->view->assign('title', @@ -405,6 +409,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Obtener los datos para mostrar el interface para modificar la clave de cuenta * * @param int $id Account's ID + * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ @@ -417,7 +422,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac ->withUserGroupsById($accountDetailsResponse); $accountHelper = $this->dic->get(AccountHelper::class); - $accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_EDIT_PASS); + $accountHelper->setViewForAccount($accountDetailsResponse, Acl::ACCOUNT_EDIT_PASS); $this->view->addTemplate('account-editpass'); $this->view->assign('title', @@ -449,6 +454,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Obtener los datos para mostrar el interface para ver cuenta en fecha concreta * * @param int $id Account's ID + * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ @@ -459,7 +465,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $accountHistoryData = $accountHistoryService->getById($id); $accountHistoryHelper = $this->dic->get(AccountHistoryHelper::class); - $accountHistoryHelper->setView($accountHistoryData, ActionsInterface::ACCOUNT_HISTORY_VIEW); + $accountHistoryHelper->setView($accountHistoryData, Acl::ACCOUNT_HISTORY_VIEW); $this->view->addTemplate('account-history'); @@ -491,6 +497,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Obtener los datos para mostrar el interface de solicitud de cambios en una cuenta * * @param int $id Account's ID + * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ @@ -499,7 +506,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac try { $accountHelper = $this->dic->get(AccountHelper::class); $accountHelper->setIsView(true); - $accountHelper->setViewForRequest($this->accountService->getById($id), ActionsInterface::ACCOUNT_REQUEST); + $accountHelper->setViewForRequest($this->accountService->getById($id), Acl::ACCOUNT_REQUEST); $this->view->addTemplate('account-request'); $this->view->assign('formRoute', 'account/saveRequest'); @@ -521,7 +528,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac /** * Display account's password * - * @param int $id Account's ID + * @param int $id Account's ID * @param int $parentId */ public function viewPassAction($id, $parentId) @@ -594,7 +601,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac /** * Copy account's password * - * @param int $id Account's ID + * @param int $id Account's ID + * * @throws Helpers\HelperException * @throws SPException * @throws \Defuse\Crypto\Exception\CryptoException @@ -623,7 +631,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac /** * Copy account's password * - * @param int $id Account's ID + * @param int $id Account's ID + * * @throws Helpers\HelperException * @throws SPException * @throws \Defuse\Crypto\Exception\CryptoException @@ -664,14 +673,14 @@ class AccountController extends ControllerBase implements CrudControllerInterfac { try { $form = new AccountForm(); - $form->validate(ActionsInterface::ACCOUNT_CREATE); + $form->validate(Acl::ACCOUNT_CREATE); $itemData = $form->getItemData(); $itemData->userId = $this->userData->getId(); $accountId = $this->accountService->create($itemData); - $this->addCustomFieldsForItem(ActionsInterface::ACCOUNT, $accountId); + $this->addCustomFieldsForItem(Acl::ACCOUNT, $accountId); $accountDetails = $this->accountService->getById($accountId)->getAccountVData(); @@ -685,7 +694,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->returnJsonResponseData( [ 'itemId' => $accountId, - 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT) + 'nextAction' => Acl::getActionRoute(Acl::ACCOUNT_EDIT) ], JsonResponse::JSON_SUCCESS, __u('Cuenta creada') @@ -703,6 +712,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Saves edit action * * @param $id Account's ID + * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ @@ -710,13 +720,13 @@ class AccountController extends ControllerBase implements CrudControllerInterfac { try { $form = new AccountForm($id); - $form->validate(ActionsInterface::ACCOUNT_EDIT); + $form->validate(Acl::ACCOUNT_EDIT); $itemData = $form->getItemData(); $this->accountService->update($itemData); - $this->updateCustomFieldsForItem(ActionsInterface::ACCOUNT, $id); + $this->updateCustomFieldsForItem(Acl::ACCOUNT, $id); $accountDetails = $this->accountService->getById($id)->getAccountVData(); @@ -730,7 +740,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->returnJsonResponseData( [ 'itemId' => $id, - 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW) + 'nextAction' => Acl::getActionRoute(Acl::ACCOUNT_VIEW) ], JsonResponse::JSON_SUCCESS, __u('Cuenta actualizada') @@ -748,6 +758,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Saves edit action * * @param $id Account's ID + * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ @@ -755,7 +766,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac { try { $form = new AccountForm($id); - $form->validate(ActionsInterface::ACCOUNT_EDIT_PASS); + $form->validate(Acl::ACCOUNT_EDIT_PASS); $this->accountService->editPassword($form->getItemData()); @@ -771,7 +782,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->returnJsonResponseData( [ 'itemId' => $id, - 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW) + 'nextAction' => Acl::getActionRoute(Acl::ACCOUNT_VIEW) ], JsonResponse::JSON_SUCCESS, __u('Clave actualizada') @@ -790,6 +801,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * * @param int $historyId Account's history ID * @param int $id Account's ID + * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ @@ -810,7 +822,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->returnJsonResponseData( [ 'itemId' => $id, - 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW) + 'nextAction' => Acl::getActionRoute(Acl::ACCOUNT_VIEW) ], JsonResponse::JSON_SUCCESS, __u('Cuenta restaurada') @@ -826,6 +838,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Saves delete action * * @param int $id Account's ID + * * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ @@ -835,7 +848,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac if ($id === null) { $this->accountService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::ACCOUNT, $id); + $this->deleteCustomFieldsForItem(Acl::ACCOUNT, $id); $this->eventDispatcher->notifyEvent('delete.account.selection', new Event($this, EventMessage::factory()->addDescription(__u('Cuentas eliminadas'))) @@ -847,7 +860,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->accountService->delete($id); - $this->deleteCustomFieldsForItem(ActionsInterface::ACCOUNT, $id); + $this->deleteCustomFieldsForItem(Acl::ACCOUNT, $id); $this->eventDispatcher->notifyEvent('delete.account', new Event($this, EventMessage::factory() @@ -869,6 +882,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac * Saves a request action * * @param $id Account's ID + * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ @@ -899,7 +913,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac $this->returnJsonResponseData( [ 'itemId' => $id, - 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT) + 'nextAction' => Acl::getActionRoute(Acl::ACCOUNT) ], JsonResponse::JSON_SUCCESS, __u('Solicitud realizada') diff --git a/app/modules/web/Controllers/AccountFileController.php b/app/modules/web/Controllers/AccountFileController.php index b94a044a..ecec49c6 100644 --- a/app/modules/web/Controllers/AccountFileController.php +++ b/app/modules/web/Controllers/AccountFileController.php @@ -25,7 +25,6 @@ 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; @@ -156,7 +155,7 @@ class AccountFileController extends ControllerBase implements CrudControllerInte $allowedExts = $this->configData->getFilesAllowedExts(); - if (count($allowedExts) === 0) { + if (empty($allowedExts)) { throw new SPException(__u('No hay extensiones permitidas'), SPException::ERROR); } @@ -171,27 +170,44 @@ class AccountFileController extends ControllerBase implements CrudControllerInte $fileData->setExtension(mb_strtoupper(pathinfo($fileData->getName(), PATHINFO_EXTENSION))); if (!in_array($fileData->getExtension(), $allowedExts, true)) { - throw new SPException(__u('Tipo de archivo no soportado'), SPException::ERROR, sprintf(__('Extensión: %s'), $fileData->getExtension())); + throw new SPException( + __u('Tipo de archivo no soportado'), + SPException::ERROR, + sprintf(__('Extensión: %s'), $fileData->getExtension()) + ); } } else { - throw new SPException(__u('Archivo inválido'), SPException::ERROR, sprintf(__u('Archivo: %s'), $fileData->getName())); + throw new SPException( + __u('Archivo inválido'), + SPException::ERROR, + sprintf(__u('Archivo: %s'), $fileData->getName()) + ); } if (!file_exists($file['tmp_name'])) { - throw new SPException(__u('Error interno al leer el archivo'), SPException::ERROR, sprintf(__u('Máximo tamaño: %s'), Util::getMaxUpload())); + throw new SPException( + __u('Error interno al leer el archivo'), + SPException::ERROR, + sprintf(__u('Máximo tamaño: %s'), Util::getMaxUpload()) + ); } $allowedSize = $this->configData->getFilesAllowedSize(); if ($fileData->getSize() > ($allowedSize * 1000)) { - throw new SPException(__u('Tamaño de archivo superado'), SPException::ERROR, sprintf(__u('Máximo tamaño: %d KB'), $fileData->getRoundSize())); + throw new SPException( + __u('Tamaño de archivo superado'), + SPException::ERROR, + sprintf(__u('Máximo tamaño: %d KB'), + $fileData->getRoundSize()) + ); } // Leemos el archivo a una variable $fileData->setContent(file_get_contents($file['tmp_name'])); if ($fileData->getContent() === false) { - throw new SPException(__u('Error interno al leer el archivo'), SPException::ERROR); + throw new SPException(__u('Error interno al leer el archivo')); } $this->accountFileService->create($fileData); @@ -232,7 +248,7 @@ class AccountFileController extends ControllerBase implements CrudControllerInte */ public function searchAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::ACCOUNT_FILE_SEARCH)) { + if (!$this->acl->checkUserAccess(Acl::ACCOUNT_FILE_SEARCH)) { return; } @@ -333,6 +349,7 @@ class AccountFileController extends ControllerBase implements CrudControllerInte * Obtener los datos para la vista de archivos de una cuenta * * @param int $accountId Account's ID + * * @throws \Psr\Container\ContainerExceptionInterface */ public function listAction($accountId) @@ -347,9 +364,9 @@ class AccountFileController extends ControllerBase implements CrudControllerInte $this->view->assign('deleteEnabled', Request::analyzeInt('del', false)); $this->view->assign('files', $this->dic->get(AccountFileService::class)->getByAccountId($accountId)); $this->view->assign('sk', $this->session->getSecurityKey()); - $this->view->assign('fileViewRoute', Acl::getActionRoute(ActionsInterface::ACCOUNT_FILE_VIEW)); - $this->view->assign('fileDownloadRoute', Acl::getActionRoute(ActionsInterface::ACCOUNT_FILE_DOWNLOAD)); - $this->view->assign('fileDeleteRoute', Acl::getActionRoute(ActionsInterface::ACCOUNT_FILE_DELETE)); + $this->view->assign('fileViewRoute', Acl::getActionRoute(Acl::ACCOUNT_FILE_VIEW)); + $this->view->assign('fileDownloadRoute', Acl::getActionRoute(Acl::ACCOUNT_FILE_DOWNLOAD)); + $this->view->assign('fileDeleteRoute', Acl::getActionRoute(Acl::ACCOUNT_FILE_DELETE)); if (!is_array($this->view->files) || count($this->view->files) === 0) { return; diff --git a/app/modules/web/Controllers/AccountHistoryManagerController.php b/app/modules/web/Controllers/AccountHistoryManagerController.php index 1c0de71e..d63e2dc6 100644 --- a/app/modules/web/Controllers/AccountHistoryManagerController.php +++ b/app/modules/web/Controllers/AccountHistoryManagerController.php @@ -24,7 +24,7 @@ namespace SP\Modules\Web\Controllers; -use SP\Core\Acl\ActionsInterface; +use SP\Core\Acl\Acl; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Http\JsonResponse; @@ -48,11 +48,12 @@ class AccountHistoryManagerController extends ControllerBase protected $accountHistoryService; /** - * Search action + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ public function searchAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::ACCOUNTMGR_SEARCH_HISTORY)) { + if (!$this->acl->checkUserAccess(Acl::ACCOUNTMGR_SEARCH_HISTORY)) { return; } diff --git a/app/modules/web/Controllers/AccountManagerController.php b/app/modules/web/Controllers/AccountManagerController.php index df6ae91f..e283d92f 100644 --- a/app/modules/web/Controllers/AccountManagerController.php +++ b/app/modules/web/Controllers/AccountManagerController.php @@ -2,8 +2,8 @@ /** * sysPass * - * @author nuxsmin - * @link https://syspass.org + * @author nuxsmin + * @link https://syspass.org * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. @@ -24,7 +24,7 @@ namespace SP\Modules\Web\Controllers; -use SP\Core\Acl\ActionsInterface; +use SP\Core\Acl\Acl; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Http\JsonResponse; @@ -36,6 +36,7 @@ use SP\Services\Account\AccountService; /** * Class AccountManagerController + * * @package SP\Modules\Web\Controllers */ class AccountManagerController extends ControllerBase @@ -48,11 +49,12 @@ class AccountManagerController extends ControllerBase protected $accountService; /** - * Search action + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ public function searchAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::ACCOUNTMGR_SEARCH)) { + if (!$this->acl->checkUserAccess(Acl::ACCOUNTMGR_SEARCH)) { return; } @@ -89,7 +91,7 @@ class AccountManagerController extends ControllerBase if ($id === null) { $this->accountService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::ACCOUNT, $id); + $this->deleteCustomFieldsForItem(Acl::ACCOUNT, $id); $this->eventDispatcher->notifyEvent('delete.account.selection', new Event($this, EventMessage::factory()->addDescription(__u('Cuentas eliminadas'))) @@ -101,7 +103,7 @@ class AccountManagerController extends ControllerBase $this->accountService->delete($id); - $this->deleteCustomFieldsForItem(ActionsInterface::ACCOUNT, $id); + $this->deleteCustomFieldsForItem(Acl::ACCOUNT, $id); $this->eventDispatcher->notifyEvent('delete.account', new Event($this, EventMessage::factory() diff --git a/app/modules/web/Controllers/AuthTokenController.php b/app/modules/web/Controllers/AuthTokenController.php index c08f5e7f..8321c924 100644 --- a/app/modules/web/Controllers/AuthTokenController.php +++ b/app/modules/web/Controllers/AuthTokenController.php @@ -25,7 +25,6 @@ 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; @@ -63,7 +62,7 @@ class AuthTokenController extends ControllerBase implements CrudControllerInterf */ public function searchAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::AUTHTOKEN_SEARCH)) { + if (!$this->acl->checkUserAccess(Acl::AUTHTOKEN_SEARCH)) { return; } @@ -96,7 +95,7 @@ class AuthTokenController extends ControllerBase implements CrudControllerInterf */ public function createAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::AUTHTOKEN_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::AUTHTOKEN_CREATE)) { return; } @@ -138,7 +137,7 @@ class AuthTokenController extends ControllerBase implements CrudControllerInterf $this->view->assign('actions', SelectItemAdapter::factory(AuthTokenService::getTokenActions())->getItemsFromArraySelected([$authToken->getActionId()])); $this->view->assign('sk', $this->session->generateSecurityKey()); - $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ACCESS_MANAGE)); + $this->view->assign('nextAction', Acl::getActionRoute(Acl::ACCESS_MANAGE)); if ($this->view->isView === true) { $this->view->assign('disabled', 'disabled'); @@ -148,7 +147,7 @@ class AuthTokenController extends ControllerBase implements CrudControllerInterf $this->view->assign('readonly'); } - $this->view->assign('customFields', $this->getCustomFieldsForItem(ActionsInterface::AUTHTOKEN, $authTokenId, $this->session)); + $this->view->assign('customFields', $this->getCustomFieldsForItem(Acl::AUTHTOKEN, $authTokenId, $this->session)); } /** @@ -160,7 +159,7 @@ class AuthTokenController extends ControllerBase implements CrudControllerInterf */ public function editAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::AUTHTOKEN_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::AUTHTOKEN_EDIT)) { return; } @@ -191,7 +190,7 @@ class AuthTokenController extends ControllerBase implements CrudControllerInterf */ public function deleteAction($id = null) { - if (!$this->acl->checkUserAccess(ActionsInterface::AUTHTOKEN_DELETE)) { + if (!$this->acl->checkUserAccess(Acl::AUTHTOKEN_DELETE)) { return; } @@ -199,7 +198,7 @@ class AuthTokenController extends ControllerBase implements CrudControllerInterf if ($id === null) { $this->authTokenService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::AUTHTOKEN, $id); + $this->deleteCustomFieldsForItem(Acl::AUTHTOKEN, $id); $this->eventDispatcher->notifyEvent('delete.authToken.selection', new Event($this, @@ -211,7 +210,7 @@ class AuthTokenController extends ControllerBase implements CrudControllerInterf } else { $this->authTokenService->delete($id); - $this->deleteCustomFieldsForItem(ActionsInterface::AUTHTOKEN, $id); + $this->deleteCustomFieldsForItem(Acl::AUTHTOKEN, $id); $this->eventDispatcher->notifyEvent('delete.authToken', new Event($this, @@ -234,19 +233,19 @@ class AuthTokenController extends ControllerBase implements CrudControllerInterf */ public function saveCreateAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::AUTHTOKEN_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::AUTHTOKEN_CREATE)) { return; } try { $form = new AuthTokenForm(); - $form->validate(ActionsInterface::AUTHTOKEN_CREATE); + $form->validate(Acl::AUTHTOKEN_CREATE); $apiTokenData = $form->getItemData(); $id = $this->authTokenService->create($apiTokenData); - $this->addCustomFieldsForItem(ActionsInterface::AUTHTOKEN, $id); + $this->addCustomFieldsForItem(Acl::AUTHTOKEN, $id); $this->eventDispatcher->notifyEvent('create.authToken', new Event($this)); @@ -270,13 +269,13 @@ class AuthTokenController extends ControllerBase implements CrudControllerInterf */ public function saveEditAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::AUTHTOKEN_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::AUTHTOKEN_EDIT)) { return; } try { $form = new AuthTokenForm($id); - $form->validate(ActionsInterface::AUTHTOKEN_EDIT); + $form->validate(Acl::AUTHTOKEN_EDIT); if ($form->isRefresh()) { $this->authTokenService->refreshAndUpdate($form->getItemData()); @@ -298,7 +297,7 @@ class AuthTokenController extends ControllerBase implements CrudControllerInterf ); } - $this->updateCustomFieldsForItem(ActionsInterface::AUTHTOKEN, $id); + $this->updateCustomFieldsForItem(Acl::AUTHTOKEN, $id); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Autorización actualizada')); } catch (ValidationException $e) { @@ -319,7 +318,7 @@ class AuthTokenController extends ControllerBase implements CrudControllerInterf */ public function viewAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::AUTHTOKEN_VIEW)) { + if (!$this->acl->checkUserAccess(Acl::AUTHTOKEN_VIEW)) { return; } diff --git a/app/modules/web/Controllers/CategoryController.php b/app/modules/web/Controllers/CategoryController.php index 557e985d..e962b9b8 100644 --- a/app/modules/web/Controllers/CategoryController.php +++ b/app/modules/web/Controllers/CategoryController.php @@ -25,7 +25,6 @@ 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; @@ -61,7 +60,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa */ public function searchAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::CATEGORY_SEARCH)) { + if (!$this->acl->checkUserAccess(Acl::CATEGORY_SEARCH)) { return; } @@ -94,7 +93,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa */ public function createAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::CATEGORY_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::CATEGORY_CREATE)) { return; } @@ -133,7 +132,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa $this->view->assign('category', $category); $this->view->assign('sk', $this->session->generateSecurityKey()); - $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE)); + $this->view->assign('nextAction', Acl::getActionRoute(Acl::ITEMS_MANAGE)); if ($this->view->isView === true) { $this->view->assign('disabled', 'disabled'); @@ -143,9 +142,8 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa $this->view->assign('readonly'); } - // FIXME - $this->view->assign('showViewCustomPass', $this->userProfileData->isAccViewPass()); - $this->view->assign('customFields', $this->getCustomFieldsForItem(ActionsInterface::CATEGORY, $categoryId, $this->session)); + $this->view->assign('showViewCustomPass', $this->acl->checkUserAccess(Acl::CUSTOMFIELD_VIEW_PASS)); + $this->view->assign('customFields', $this->getCustomFieldsForItem(Acl::CATEGORY, $categoryId, $this->session)); } /** @@ -157,7 +155,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa */ public function editAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::CATEGORY_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::CATEGORY_EDIT)) { return; } @@ -188,7 +186,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa */ public function deleteAction($id = null) { - if (!$this->acl->checkUserAccess(ActionsInterface::CATEGORY_DELETE)) { + if (!$this->acl->checkUserAccess(Acl::CATEGORY_DELETE)) { return; } @@ -196,7 +194,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa if ($id === null) { $this->categoryService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::CATEGORY, $id); + $this->deleteCustomFieldsForItem(Acl::CATEGORY, $id); $this->eventDispatcher->notifyEvent('delete.category', new Event($this, @@ -208,7 +206,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa } else { $this->categoryService->delete($id); - $this->deleteCustomFieldsForItem(ActionsInterface::CATEGORY, $id); + $this->deleteCustomFieldsForItem(Acl::CATEGORY, $id); $this->eventDispatcher->notifyEvent('delete.category', new Event($this, @@ -234,19 +232,19 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa */ public function saveCreateAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::CATEGORY_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::CATEGORY_CREATE)) { return; } try { $form = new CategoryForm(); - $form->validate(ActionsInterface::CATEGORY_CREATE); + $form->validate(Acl::CATEGORY_CREATE); $itemData = $form->getItemData(); $id = $this->categoryService->create($itemData); - $this->addCustomFieldsForItem(ActionsInterface::CATEGORY, $id); + $this->addCustomFieldsForItem(Acl::CATEGORY, $id); $this->eventDispatcher->notifyEvent('create.category', new Event($this, @@ -276,19 +274,19 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa */ public function saveEditAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::CATEGORY_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::CATEGORY_EDIT)) { return; } try { $form = new CategoryForm($id); - $form->validate(ActionsInterface::CATEGORY_EDIT); + $form->validate(Acl::CATEGORY_EDIT); $itemData = $form->getItemData(); $this->categoryService->update($itemData); - $this->updateCustomFieldsForItem(ActionsInterface::CATEGORY, $id); + $this->updateCustomFieldsForItem(Acl::CATEGORY, $id); $this->eventDispatcher->notifyEvent('edit.category', new Event($this, @@ -316,7 +314,7 @@ class CategoryController extends ControllerBase implements CrudControllerInterfa */ public function viewAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::CATEGORY_VIEW)) { + if (!$this->acl->checkUserAccess(Acl::CATEGORY_VIEW)) { return; } diff --git a/app/modules/web/Controllers/ClientController.php b/app/modules/web/Controllers/ClientController.php index 72586b78..e353f47e 100644 --- a/app/modules/web/Controllers/ClientController.php +++ b/app/modules/web/Controllers/ClientController.php @@ -26,7 +26,6 @@ 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; @@ -62,7 +61,7 @@ class ClientController extends ControllerBase implements CrudControllerInterface */ public function searchAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::CLIENT_SEARCH)) { + if (!$this->acl->checkUserAccess(Acl::CLIENT_SEARCH)) { return; } @@ -95,7 +94,7 @@ class ClientController extends ControllerBase implements CrudControllerInterface */ public function createAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::CLIENT_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::CLIENT_CREATE)) { return; } @@ -134,7 +133,7 @@ class ClientController extends ControllerBase implements CrudControllerInterface $this->view->assign('client', $client); $this->view->assign('sk', $this->session->generateSecurityKey()); - $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE)); + $this->view->assign('nextAction', Acl::getActionRoute(Acl::ITEMS_MANAGE)); if ($this->view->isView === true) { $this->view->assign('disabled', 'disabled'); @@ -144,9 +143,8 @@ class ClientController extends ControllerBase implements CrudControllerInterface $this->view->assign('readonly'); } - // FIXME - $this->view->assign('showViewCustomPass', $this->userProfileData->isAccViewPass()); - $this->view->assign('customFields', $this->getCustomFieldsForItem(ActionsInterface::CLIENT, $clientId, $this->session)); + $this->view->assign('showViewCustomPass', $this->acl->checkUserAccess(Acl::CUSTOMFIELD_VIEW_PASS)); + $this->view->assign('customFields', $this->getCustomFieldsForItem(Acl::CLIENT, $clientId, $this->session)); } /** @@ -158,7 +156,7 @@ class ClientController extends ControllerBase implements CrudControllerInterface */ public function editAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::CLIENT_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::CLIENT_EDIT)) { return; } @@ -189,7 +187,7 @@ class ClientController extends ControllerBase implements CrudControllerInterface */ public function deleteAction($id = null) { - if (!$this->acl->checkUserAccess(ActionsInterface::CLIENT_DELETE)) { + if (!$this->acl->checkUserAccess(Acl::CLIENT_DELETE)) { return; } @@ -197,7 +195,7 @@ class ClientController extends ControllerBase implements CrudControllerInterface if ($id === null) { $this->clientService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::CLIENT, $id); + $this->deleteCustomFieldsForItem(Acl::CLIENT, $id); $this->eventDispatcher->notifyEvent('delete.client.selection', new Event($this, EventMessage::factory() @@ -208,7 +206,7 @@ class ClientController extends ControllerBase implements CrudControllerInterface } else { $this->clientService->delete($id); - $this->deleteCustomFieldsForItem(ActionsInterface::CLIENT, $id); + $this->deleteCustomFieldsForItem(Acl::CLIENT, $id); $this->eventDispatcher->notifyEvent('delete.client', new Event($this, EventMessage::factory() @@ -230,13 +228,13 @@ class ClientController extends ControllerBase implements CrudControllerInterface */ public function saveCreateAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::CLIENT_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::CLIENT_CREATE)) { return; } try { $form = new ClientForm(); - $form->validate(ActionsInterface::CLIENT_CREATE); + $form->validate(Acl::CLIENT_CREATE); $itemData = $form->getItemData(); @@ -266,13 +264,13 @@ class ClientController extends ControllerBase implements CrudControllerInterface */ public function saveEditAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::CLIENT_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::CLIENT_EDIT)) { return; } try { $form = new ClientForm($id); - $form->validate(ActionsInterface::CLIENT_EDIT); + $form->validate(Acl::CLIENT_EDIT); $this->clientService->update($form->getItemData()); @@ -302,7 +300,7 @@ class ClientController extends ControllerBase implements CrudControllerInterface */ public function viewAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::CLIENT_VIEW)) { + if (!$this->acl->checkUserAccess(Acl::CLIENT_VIEW)) { return; } diff --git a/app/modules/web/Controllers/ConfigBackupController.php b/app/modules/web/Controllers/ConfigBackupController.php index 9b59bdef..f64f97d5 100644 --- a/app/modules/web/Controllers/ConfigBackupController.php +++ b/app/modules/web/Controllers/ConfigBackupController.php @@ -24,7 +24,7 @@ namespace SP\Modules\Web\Controllers; -use SP\Core\Acl\ActionsInterface; +use SP\Core\Acl\Acl; use SP\Core\Acl\UnauthorizedPageException; use SP\Core\Context\SessionContext; use SP\Core\Events\Event; @@ -118,7 +118,7 @@ class ConfigBackupController extends SimpleControllerBase { try { $this->checks(); - $this->checkAccess(ActionsInterface::BACKUP_CONFIG); + $this->checkAccess(Acl::BACKUP_CONFIG); } catch (UnauthorizedPageException $e) { $this->eventDispatcher->notifyEvent('exception', new Event($e)); diff --git a/app/modules/web/Controllers/ConfigEncryptionController.php b/app/modules/web/Controllers/ConfigEncryptionController.php index cdc375dc..9accbdc6 100644 --- a/app/modules/web/Controllers/ConfigEncryptionController.php +++ b/app/modules/web/Controllers/ConfigEncryptionController.php @@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; -use SP\Core\Acl\ActionsInterface; +use SP\Core\Acl\Acl; use SP\Core\Acl\UnauthorizedPageException; use SP\Core\Crypt\Hash; use SP\Core\Crypt\Session as CryptSession; @@ -232,7 +232,7 @@ class ConfigEncryptionController extends SimpleControllerBase { try { $this->checks(); - $this->checkAccess(ActionsInterface::ENCRYPTION_CONFIG); + $this->checkAccess(Acl::ENCRYPTION_CONFIG); } catch (UnauthorizedPageException $e) { $this->eventDispatcher->notifyEvent('exception', new Event($e)); diff --git a/app/modules/web/Controllers/ConfigGeneralController.php b/app/modules/web/Controllers/ConfigGeneralController.php index 89b35c13..abbf1ee7 100644 --- a/app/modules/web/Controllers/ConfigGeneralController.php +++ b/app/modules/web/Controllers/ConfigGeneralController.php @@ -25,7 +25,7 @@ namespace SP\Modules\Web\Controllers; use SP\Config\ConfigUtil; -use SP\Core\Acl\ActionsInterface; +use SP\Core\Acl\Acl; use SP\Core\Acl\UnauthorizedPageException; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; @@ -169,7 +169,7 @@ class ConfigGeneralController extends SimpleControllerBase { try { $this->checks(); - $this->checkAccess(ActionsInterface::CONFIG_GENERAL); + $this->checkAccess(Acl::CONFIG_GENERAL); } catch (UnauthorizedPageException $e) { $this->eventDispatcher->notifyEvent('exception', new Event($e)); diff --git a/app/modules/web/Controllers/ConfigImportController.php b/app/modules/web/Controllers/ConfigImportController.php index 645f5a85..24da4a19 100644 --- a/app/modules/web/Controllers/ConfigImportController.php +++ b/app/modules/web/Controllers/ConfigImportController.php @@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; -use SP\Core\Acl\ActionsInterface; +use SP\Core\Acl\Acl; use SP\Core\Acl\UnauthorizedPageException; use SP\Core\Context\SessionContext; use SP\Core\Events\Event; @@ -98,7 +98,7 @@ class ConfigImportController extends SimpleControllerBase { try { $this->checks(); - $this->checkAccess(ActionsInterface::IMPORT_CONFIG); + $this->checkAccess(Acl::IMPORT_CONFIG); } catch (UnauthorizedPageException $e) { $this->eventDispatcher->notifyEvent('exception', new Event($e)); diff --git a/app/modules/web/Controllers/ConfigLdapController.php b/app/modules/web/Controllers/ConfigLdapController.php index bb5bd19e..e48cc085 100644 --- a/app/modules/web/Controllers/ConfigLdapController.php +++ b/app/modules/web/Controllers/ConfigLdapController.php @@ -24,7 +24,7 @@ namespace SP\Modules\Web\Controllers; -use SP\Core\Acl\ActionsInterface; +use SP\Core\Acl\Acl; use SP\Core\Acl\UnauthorizedPageException; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; @@ -280,7 +280,7 @@ class ConfigLdapController extends SimpleControllerBase { try { $this->checks(); - $this->checkAccess(ActionsInterface::LDAP_CONFIG); + $this->checkAccess(Acl::LDAP_CONFIG); } catch (UnauthorizedPageException $e) { $this->eventDispatcher->notifyEvent('exception', new Event($e)); diff --git a/app/modules/web/Controllers/ConfigMailController.php b/app/modules/web/Controllers/ConfigMailController.php index 32dea181..6e51e74f 100644 --- a/app/modules/web/Controllers/ConfigMailController.php +++ b/app/modules/web/Controllers/ConfigMailController.php @@ -25,7 +25,7 @@ namespace SP\Modules\Web\Controllers; use SP\Config\ConfigUtil; -use SP\Core\Acl\ActionsInterface; +use SP\Core\Acl\Acl; use SP\Core\Acl\UnauthorizedPageException; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; @@ -158,7 +158,7 @@ class ConfigMailController extends SimpleControllerBase { try { $this->checks(); - $this->checkAccess(ActionsInterface::MAIL_CONFIG); + $this->checkAccess(Acl::MAIL_CONFIG); } catch (UnauthorizedPageException $e) { $this->eventDispatcher->notifyEvent('exception', new Event($e)); diff --git a/app/modules/web/Controllers/ConfigManagerController.php b/app/modules/web/Controllers/ConfigManagerController.php index 51f617ee..bde940aa 100644 --- a/app/modules/web/Controllers/ConfigManagerController.php +++ b/app/modules/web/Controllers/ConfigManagerController.php @@ -26,9 +26,7 @@ namespace SP\Modules\Web\Controllers; use SP\Bootstrap; use SP\Core\Acl\Acl; -use SP\Core\Acl\ActionsInterface; use SP\Core\Crypt\CryptSessionHandler; -use SP\Core\CryptMasterPass; use SP\Core\Events\Event; use SP\Core\Language; use SP\Core\Plugin\PluginUtil; @@ -85,46 +83,46 @@ class ConfigManagerController extends ControllerBase { $this->tabsHelper = $this->dic->get(TabsHelper::class); - if ($this->checkAccess(ActionsInterface::CONFIG_GENERAL)) { + if ($this->checkAccess(Acl::CONFIG_GENERAL)) { $this->tabsHelper->addTab($this->getConfigGeneral()); } - if ($this->checkAccess(ActionsInterface::ACCOUNT_CONFIG)) { + if ($this->checkAccess(Acl::ACCOUNT_CONFIG)) { $this->tabsHelper->addTab($this->getAccountConfig()); } - if ($this->checkAccess(ActionsInterface::WIKI_CONFIG)) { + if ($this->checkAccess(Acl::WIKI_CONFIG)) { $this->tabsHelper->addTab($this->getWikiConfig()); } - if ($this->checkAccess(ActionsInterface::LDAP_CONFIG)) { + if ($this->checkAccess(Acl::LDAP_CONFIG)) { $this->tabsHelper->addTab($this->getLdapConfig()); } - if ($this->checkAccess(ActionsInterface::MAIL_CONFIG)) { + if ($this->checkAccess(Acl::MAIL_CONFIG)) { $this->tabsHelper->addTab($this->getMailConfig()); } - if ($this->checkAccess(ActionsInterface::ENCRYPTION_CONFIG)) { + if ($this->checkAccess(Acl::ENCRYPTION_CONFIG)) { $this->tabsHelper->addTab($this->getEncryptionConfig()); } - if ($this->checkAccess(ActionsInterface::BACKUP_CONFIG)) { + if ($this->checkAccess(Acl::BACKUP_CONFIG)) { $this->tabsHelper->addTab($this->getBackupConfig()); } - if ($this->checkAccess(ActionsInterface::IMPORT_CONFIG)) { + if ($this->checkAccess(Acl::IMPORT_CONFIG)) { $this->tabsHelper->addTab($this->getImportConfig()); } - if ($this->checkAccess(ActionsInterface::CONFIG_GENERAL)) { + if ($this->checkAccess(Acl::CONFIG_GENERAL)) { $this->tabsHelper->addTab($this->getInfo()); } $this->eventDispatcher->notifyEvent('show.config', new Event($this)); - $this->tabsHelper->renderTabs(Acl::getActionRoute(ActionsInterface::CONFIG), Request::analyzeInt('tabIndex', 0)); + $this->tabsHelper->renderTabs(Acl::getActionRoute(Acl::CONFIG), Request::analyzeInt('tabIndex', 0)); $this->view(); } @@ -221,8 +219,8 @@ class ConfigManagerController extends ControllerBase /** * @return DataTab - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException * @throws \SP\Services\Config\ParameterNotFoundException */ protected function getEncryptionConfig() diff --git a/app/modules/web/Controllers/ConfigWikiController.php b/app/modules/web/Controllers/ConfigWikiController.php index 5a8f532b..408b80b6 100644 --- a/app/modules/web/Controllers/ConfigWikiController.php +++ b/app/modules/web/Controllers/ConfigWikiController.php @@ -24,7 +24,7 @@ namespace SP\Modules\Web\Controllers; -use SP\Core\Acl\ActionsInterface; +use SP\Core\Acl\Acl; use SP\Core\Acl\UnauthorizedPageException; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; @@ -114,7 +114,7 @@ class ConfigWikiController extends SimpleControllerBase { try { $this->checks(); - $this->checkAccess(ActionsInterface::WIKI_CONFIG); + $this->checkAccess(Acl::WIKI_CONFIG); } catch (UnauthorizedPageException $e) { $this->eventDispatcher->notifyEvent('exception', new Event($e)); diff --git a/app/modules/web/Controllers/CustomFieldController.php b/app/modules/web/Controllers/CustomFieldController.php index 302b74e0..a2b23ccd 100644 --- a/app/modules/web/Controllers/CustomFieldController.php +++ b/app/modules/web/Controllers/CustomFieldController.php @@ -25,7 +25,6 @@ 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; @@ -63,7 +62,7 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte */ public function searchAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::CUSTOMFIELD_SEARCH)) { + if (!$this->acl->checkUserAccess(Acl::CUSTOMFIELD_SEARCH)) { return; } @@ -96,7 +95,7 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte */ public function createAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::CUSTOMFIELD_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::CUSTOMFIELD_CREATE)) { return; } @@ -137,7 +136,7 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte $this->view->assign('modules', SelectItemAdapter::factory(CustomFieldDefService::getFieldModules())->getItemsFromArraySelected([$customField->getModuleId()])); $this->view->assign('sk', $this->session->generateSecurityKey()); - $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE)); + $this->view->assign('nextAction', Acl::getActionRoute(Acl::ITEMS_MANAGE)); if ($this->view->isView === true) { $this->view->assign('disabled', 'disabled'); @@ -157,7 +156,7 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte */ public function editAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::CUSTOMFIELD_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::CUSTOMFIELD_EDIT)) { return; } @@ -188,7 +187,7 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte */ public function deleteAction($id = null) { - if (!$this->acl->checkUserAccess(ActionsInterface::CUSTOMFIELD_DELETE)) { + if (!$this->acl->checkUserAccess(Acl::CUSTOMFIELD_DELETE)) { return; } @@ -220,13 +219,13 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte */ public function saveCreateAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::CUSTOMFIELD_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::CUSTOMFIELD_CREATE)) { return; } try { $form = new CustomFieldDefForm(); - $form->validate(ActionsInterface::CUSTOMFIELD_CREATE); + $form->validate(Acl::CUSTOMFIELD_CREATE); $itemData = $form->getItemData(); @@ -255,13 +254,13 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte */ public function saveEditAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::CUSTOMFIELD_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::CUSTOMFIELD_EDIT)) { return; } try { $form = new CustomFieldDefForm($id); - $form->validate(ActionsInterface::CUSTOMFIELD_EDIT); + $form->validate(Acl::CUSTOMFIELD_EDIT); $itemData = $form->getItemData(); @@ -292,7 +291,7 @@ class CustomFieldController extends ControllerBase implements CrudControllerInte */ public function viewAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::CUSTOMFIELD_VIEW)) { + if (!$this->acl->checkUserAccess(Acl::CUSTOMFIELD_VIEW)) { return; } diff --git a/app/modules/web/Controllers/EventlogController.php b/app/modules/web/Controllers/EventlogController.php index 7ebf1795..1951f337 100644 --- a/app/modules/web/Controllers/EventlogController.php +++ b/app/modules/web/Controllers/EventlogController.php @@ -24,7 +24,7 @@ namespace SP\Modules\Web\Controllers; -use SP\Core\Acl\ActionsInterface; +use SP\Core\Acl\Acl; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Http\JsonResponse; @@ -55,7 +55,7 @@ class EventlogController extends ControllerBase */ public function indexAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::EVENTLOG)) { + if (!$this->acl->checkUserAccess(Acl::EVENTLOG)) { return; } @@ -89,7 +89,7 @@ class EventlogController extends ControllerBase */ public function searchAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::EVENTLOG_SEARCH)) { + if (!$this->acl->checkUserAccess(Acl::EVENTLOG_SEARCH)) { return; } diff --git a/app/modules/web/Controllers/ItemManagerController.php b/app/modules/web/Controllers/ItemManagerController.php index 0a7f4844..5ae7f0c3 100644 --- a/app/modules/web/Controllers/ItemManagerController.php +++ b/app/modules/web/Controllers/ItemManagerController.php @@ -2,8 +2,8 @@ /** * sysPass * - * @author nuxsmin - * @link https://syspass.org + * @author nuxsmin + * @link https://syspass.org * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. @@ -25,7 +25,6 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; -use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; use SP\DataModel\ItemSearchData; use SP\Http\Request; @@ -83,41 +82,41 @@ class ItemManagerController extends ControllerBase $this->itemsGridHelper = $this->dic->get(ItemsGridHelper::class); $this->tabsGridHelper = $this->dic->get(TabsGridHelper::class); - if ($this->checkAccess(ActionsInterface::CATEGORY)) { + if ($this->checkAccess(Acl::CATEGORY)) { $this->tabsGridHelper->addTab($this->getCategoriesList()); } - if ($this->checkAccess(ActionsInterface::TAG)) { + if ($this->checkAccess(Acl::TAG)) { $this->tabsGridHelper->addTab($this->getTagsList()); } - if ($this->checkAccess(ActionsInterface::CLIENT)) { + if ($this->checkAccess(Acl::CLIENT)) { $this->tabsGridHelper->addTab($this->getClientsList()); } - if ($this->checkAccess(ActionsInterface::CUSTOMFIELD)) { + if ($this->checkAccess(Acl::CUSTOMFIELD)) { $this->tabsGridHelper->addTab($this->getCustomFieldsList()); } - if ($this->configData->isFilesEnabled() && $this->checkAccess(ActionsInterface::FILE)) { + if ($this->configData->isFilesEnabled() && $this->checkAccess(Acl::FILE)) { $this->tabsGridHelper->addTab($this->getAccountFilesList()); } - if ($this->checkAccess(ActionsInterface::ACCOUNTMGR)) { + if ($this->checkAccess(Acl::ACCOUNTMGR)) { $this->tabsGridHelper->addTab($this->getAccountsList()); } - if ($this->checkAccess(ActionsInterface::ACCOUNTMGR_HISTORY)) { + if ($this->checkAccess(Acl::ACCOUNTMGR_HISTORY)) { $this->tabsGridHelper->addTab($this->getAccountsHistoryList()); } - if ($this->checkAccess(ActionsInterface::PLUGIN)) { + if ($this->checkAccess(Acl::PLUGIN)) { $this->tabsGridHelper->addTab($this->getPluginsList()); } $this->eventDispatcher->notifyEvent('show.itemlist.items', new Event($this)); - $this->tabsGridHelper->renderTabs(Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE), Request::analyzeInt('tabIndex', 0)); + $this->tabsGridHelper->renderTabs(Acl::getActionRoute(Acl::ITEMS_MANAGE), Request::analyzeInt('tabIndex', 0)); $this->view(); } @@ -126,8 +125,8 @@ class ItemManagerController extends ControllerBase * Returns categories' data tab * * @return \SP\Html\DataGrid\DataGridTab - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ protected function getCategoriesList() { @@ -138,8 +137,8 @@ class ItemManagerController extends ControllerBase * Returns tags' data tab * * @return \SP\Html\DataGrid\DataGridTab - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ protected function getTagsList() { @@ -150,8 +149,8 @@ class ItemManagerController extends ControllerBase * Returns clients' data tab * * @return \SP\Html\DataGrid\DataGridTab - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ protected function getClientsList() { @@ -162,8 +161,8 @@ class ItemManagerController extends ControllerBase * Returns custom fields' data tab * * @return \SP\Html\DataGrid\DataGridTab - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ protected function getCustomFieldsList() { @@ -174,8 +173,8 @@ class ItemManagerController extends ControllerBase * Returns account files' data tab * * @return \SP\Html\DataGrid\DataGridTab - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ protected function getAccountFilesList() { @@ -186,8 +185,8 @@ class ItemManagerController extends ControllerBase * Returns accounts' data tab * * @return \SP\Html\DataGrid\DataGridTab - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ protected function getAccountsList() { @@ -198,8 +197,8 @@ class ItemManagerController extends ControllerBase * Returns accounts' history data tab * * @return \SP\Html\DataGrid\DataGridTab - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ protected function getAccountsHistoryList() { @@ -210,8 +209,8 @@ class ItemManagerController extends ControllerBase * Returns plugins' data tab * * @return \SP\Html\DataGrid\DataGridTab - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ protected function getPluginsList() { diff --git a/app/modules/web/Controllers/ItemsController.php b/app/modules/web/Controllers/ItemsController.php index d81279c9..a3a1e33b 100644 --- a/app/modules/web/Controllers/ItemsController.php +++ b/app/modules/web/Controllers/ItemsController.php @@ -2,8 +2,8 @@ /** * sysPass * - * @author nuxsmin - * @link https://syspass.org + * @author nuxsmin + * @link https://syspass.org * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. @@ -44,6 +44,9 @@ class ItemsController extends SimpleControllerBase * Devolver las cuentas visibles por el usuario * * @param int $accountId + * + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException */ public function accountsUserAction($accountId = null) { @@ -101,6 +104,7 @@ class ItemsController extends SimpleControllerBase * Preparar los elementos para devolverlos * * @param array $items + * * @return array */ protected function prepareItems(array $items) diff --git a/app/modules/web/Controllers/NotificationController.php b/app/modules/web/Controllers/NotificationController.php index 8e35faf3..0924e837 100644 --- a/app/modules/web/Controllers/NotificationController.php +++ b/app/modules/web/Controllers/NotificationController.php @@ -2,8 +2,8 @@ /** * sysPass * - * @author nuxsmin - * @link https://syspass.org + * @author nuxsmin + * @link https://syspass.org * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. @@ -27,7 +27,6 @@ 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; @@ -63,7 +62,7 @@ class NotificationController extends ControllerBase implements CrudControllerInt */ public function indexAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION)) { + if (!$this->acl->checkUserAccess(Acl::NOTIFICATION)) { return; } @@ -93,12 +92,13 @@ class NotificationController extends ControllerBase implements CrudControllerInt * View action * * @param $id + * * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function viewAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION_VIEW)) { + if (!$this->acl->checkUserAccess(Acl::NOTIFICATION_VIEW)) { return; } @@ -139,7 +139,7 @@ class NotificationController extends ControllerBase implements CrudControllerInt } $this->view->assign('sk', $this->session->generateSecurityKey()); - $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::NOTIFICATION)); + $this->view->assign('nextAction', Acl::getActionRoute(Acl::NOTIFICATION)); if ($this->view->isView === true) { $this->view->assign('disabled', 'disabled'); @@ -155,7 +155,7 @@ class NotificationController extends ControllerBase implements CrudControllerInt */ public function searchAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION_SEARCH)) { + if (!$this->acl->checkUserAccess(Acl::NOTIFICATION_SEARCH)) { return; } @@ -173,7 +173,7 @@ class NotificationController extends ControllerBase implements CrudControllerInt */ public function createAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::NOTIFICATION_CREATE)) { return; } @@ -199,12 +199,13 @@ class NotificationController extends ControllerBase implements CrudControllerInt * Edit action * * @param $id + * * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function editAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::NOTIFICATION_EDIT)) { return; } @@ -233,7 +234,7 @@ class NotificationController extends ControllerBase implements CrudControllerInt */ public function deleteAction($id = null) { - if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION_DELETE)) { + if (!$this->acl->checkUserAccess(Acl::NOTIFICATION_DELETE)) { return; } @@ -282,7 +283,7 @@ class NotificationController extends ControllerBase implements CrudControllerInt */ public function checkAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION_CHECK)) { + if (!$this->acl->checkUserAccess(Acl::NOTIFICATION_CHECK)) { return; } @@ -309,13 +310,13 @@ class NotificationController extends ControllerBase implements CrudControllerInt */ public function saveCreateAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::NOTIFICATION_CREATE)) { return; } try { $form = new NotificationForm(); - $form->validate(ActionsInterface::NOTIFICATION_CREATE); + $form->validate(Acl::NOTIFICATION_CREATE); $this->notificationService->create($form->getItemData()); @@ -340,13 +341,13 @@ class NotificationController extends ControllerBase implements CrudControllerInt */ public function saveEditAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::NOTIFICATION_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::NOTIFICATION_EDIT)) { return; } try { $form = new NotificationForm($id); - $form->validate(ActionsInterface::NOTIFICATION_EDIT); + $form->validate(Acl::NOTIFICATION_EDIT); $this->notificationService->update($form->getItemData()); diff --git a/app/modules/web/Controllers/PluginController.php b/app/modules/web/Controllers/PluginController.php index 80f0051a..7df5e548 100644 --- a/app/modules/web/Controllers/PluginController.php +++ b/app/modules/web/Controllers/PluginController.php @@ -27,7 +27,6 @@ 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\PluginData; @@ -60,7 +59,7 @@ class PluginController extends ControllerBase */ public function indexAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::PLUGIN)) { + if (!$this->acl->checkUserAccess(Acl::PLUGIN)) { return; } @@ -94,7 +93,7 @@ class PluginController extends ControllerBase */ public function searchAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::PLUGIN_SEARCH)) { + if (!$this->acl->checkUserAccess(Acl::PLUGIN_SEARCH)) { return; } @@ -115,7 +114,7 @@ class PluginController extends ControllerBase */ public function viewAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::PLUGIN_VIEW)) { + if (!$this->acl->checkUserAccess(Acl::PLUGIN_VIEW)) { return; } @@ -152,7 +151,7 @@ class PluginController extends ControllerBase $this->view->assign('plugin', $pluginData); $this->view->assign('sk', $this->session->generateSecurityKey()); - $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE)); + $this->view->assign('nextAction', Acl::getActionRoute(Acl::ITEMS_MANAGE)); if ($this->view->isView === true) { $this->view->assign('disabled', 'disabled'); diff --git a/app/modules/web/Controllers/PublicLinkController.php b/app/modules/web/Controllers/PublicLinkController.php index df6719dc..c7905d95 100644 --- a/app/modules/web/Controllers/PublicLinkController.php +++ b/app/modules/web/Controllers/PublicLinkController.php @@ -25,7 +25,6 @@ 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; @@ -66,7 +65,7 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter */ public function searchAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::PUBLICLINK_SEARCH)) { + if (!$this->acl->checkUserAccess(Acl::PUBLICLINK_SEARCH)) { return; } @@ -99,7 +98,7 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter */ public function createAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::PUBLICLINK_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::PUBLICLINK_CREATE)) { return; } @@ -140,7 +139,7 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter $this->view->assign('accounts', SelectItemAdapter::factory($this->dic->get(AccountService::class)->getForUser())->getItemsFromModelSelected([$publicLink->getItemId()])); $this->view->assign('sk', $this->session->generateSecurityKey()); - $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ACCESS_MANAGE)); + $this->view->assign('nextAction', Acl::getActionRoute(Acl::ACCESS_MANAGE)); if ($this->view->isView === true) { $this->view->assign('publicLinkURL', PublicLinkService::getLinkForHash($publicLink->getHash())); @@ -162,7 +161,7 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter */ public function refreshAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::PUBLICLINK_REFRESH)) { + if (!$this->acl->checkUserAccess(Acl::PUBLICLINK_REFRESH)) { return; } @@ -188,7 +187,7 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter */ public function editAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::PUBLICLINK_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::PUBLICLINK_EDIT)) { return; } @@ -219,7 +218,7 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter */ public function deleteAction($id = null) { - if (!$this->acl->checkUserAccess(ActionsInterface::PUBLICLINK_DELETE)) { + if (!$this->acl->checkUserAccess(Acl::PUBLICLINK_DELETE)) { return; } @@ -227,7 +226,7 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter if ($id === null) { $this->publicLinkService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::PUBLICLINK, $id); + $this->deleteCustomFieldsForItem(Acl::PUBLICLINK, $id); $this->eventDispatcher->notifyEvent('delete.publicLink.selection', new Event($this, EventMessage::factory() @@ -238,7 +237,7 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter } else { $this->publicLinkService->delete($id); - $this->deleteCustomFieldsForItem(ActionsInterface::PUBLICLINK, $id); + $this->deleteCustomFieldsForItem(Acl::PUBLICLINK, $id); $this->eventDispatcher->notifyEvent('delete.publicLink', new Event($this, EventMessage::factory() @@ -263,13 +262,13 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter */ public function saveCreateAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::PUBLICLINK_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::PUBLICLINK_CREATE)) { return; } try { $form = new PublicLinkForm(); - $form->validate(ActionsInterface::PUBLICLINK_CREATE); + $form->validate(Acl::PUBLICLINK_CREATE); $this->publicLinkService->create($form->getItemData()); @@ -296,7 +295,7 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter */ public function saveCreateFromAccountAction($accountId, $notify) { - if (!$this->acl->checkUserAccess(ActionsInterface::PUBLICLINK_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::PUBLICLINK_CREATE)) { return; } @@ -338,7 +337,7 @@ class PublicLinkController extends ControllerBase implements CrudControllerInter */ public function viewAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::PUBLICLINK_VIEW)) { + if (!$this->acl->checkUserAccess(Acl::PUBLICLINK_VIEW)) { return; } diff --git a/app/modules/web/Controllers/ResourceController.php b/app/modules/web/Controllers/ResourceController.php index 1cb0e01c..430a1c96 100644 --- a/app/modules/web/Controllers/ResourceController.php +++ b/app/modules/web/Controllers/ResourceController.php @@ -2,8 +2,8 @@ /** * sysPass * - * @author nuxsmin - * @link https://syspass.org + * @author nuxsmin + * @link https://syspass.org * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. diff --git a/app/modules/web/Controllers/SimpleControllerBase.php b/app/modules/web/Controllers/SimpleControllerBase.php index 6e61af62..abe8c1f0 100644 --- a/app/modules/web/Controllers/SimpleControllerBase.php +++ b/app/modules/web/Controllers/SimpleControllerBase.php @@ -2,8 +2,8 @@ /** * sysPass * - * @author nuxsmin - * @link https://syspass.org + * @author nuxsmin + * @link https://syspass.org * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. @@ -92,6 +92,7 @@ abstract class SimpleControllerBase * * @param Container $container * @param $actionName + * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ @@ -128,6 +129,7 @@ abstract class SimpleControllerBase * Comprobar si está permitido el acceso al módulo/página. * * @param null $action La acción a comprobar + * * @throws UnauthorizedPageException */ protected function checkAccess($action) diff --git a/app/modules/web/Controllers/StatusController.php b/app/modules/web/Controllers/StatusController.php index 0ecc79aa..ae9c5f4f 100644 --- a/app/modules/web/Controllers/StatusController.php +++ b/app/modules/web/Controllers/StatusController.php @@ -40,6 +40,8 @@ class StatusController extends SimpleControllerBase /** * checkReleaseAction + * + * @throws \GuzzleHttp\Exception\GuzzleException */ public function checkReleaseAction() { @@ -85,6 +87,8 @@ class StatusController extends SimpleControllerBase /** * checkNoticesAction + * + * @throws \GuzzleHttp\Exception\GuzzleException */ public function checkNoticesAction() { diff --git a/app/modules/web/Controllers/TagController.php b/app/modules/web/Controllers/TagController.php index f62c129c..ed7a47cd 100644 --- a/app/modules/web/Controllers/TagController.php +++ b/app/modules/web/Controllers/TagController.php @@ -25,7 +25,6 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; -use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; use SP\Core\Exceptions\ValidationException; use SP\DataModel\TagData; @@ -60,7 +59,7 @@ class TagController extends ControllerBase implements CrudControllerInterface */ public function searchAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::TAG_SEARCH)) { + if (!$this->acl->checkUserAccess(Acl::TAG_SEARCH)) { return; } @@ -93,7 +92,7 @@ class TagController extends ControllerBase implements CrudControllerInterface */ public function createAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::TAG_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::TAG_CREATE)) { return; } @@ -132,7 +131,7 @@ class TagController extends ControllerBase implements CrudControllerInterface $this->view->assign('tag', $tag); $this->view->assign('sk', $this->session->generateSecurityKey()); - $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE)); + $this->view->assign('nextAction', Acl::getActionRoute(Acl::ITEMS_MANAGE)); if ($this->view->isView === true) { $this->view->assign('disabled', 'disabled'); @@ -151,7 +150,7 @@ class TagController extends ControllerBase implements CrudControllerInterface */ public function editAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::TAG_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::TAG_EDIT)) { return; } @@ -181,7 +180,7 @@ class TagController extends ControllerBase implements CrudControllerInterface */ public function deleteAction($id = null) { - if (!$this->acl->checkUserAccess(ActionsInterface::TAG_DELETE)) { + if (!$this->acl->checkUserAccess(Acl::TAG_DELETE)) { return; } @@ -189,7 +188,7 @@ class TagController extends ControllerBase implements CrudControllerInterface if ($id === null) { $this->tagService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::TAG, $id); + $this->deleteCustomFieldsForItem(Acl::TAG, $id); $this->eventDispatcher->notifyEvent('delete.tag.selection', new Event($this)); @@ -197,7 +196,7 @@ class TagController extends ControllerBase implements CrudControllerInterface } else { $this->tagService->delete($id); - $this->deleteCustomFieldsForItem(ActionsInterface::TAG, $id); + $this->deleteCustomFieldsForItem(Acl::TAG, $id); $this->eventDispatcher->notifyEvent('delete.tag', new Event($this)); @@ -215,13 +214,13 @@ class TagController extends ControllerBase implements CrudControllerInterface */ public function saveCreateAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::TAG_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::TAG_CREATE)) { return; } try { $form = new TagForm(); - $form->validate(ActionsInterface::TAG_CREATE); + $form->validate(Acl::TAG_CREATE); $this->tagService->create($form->getItemData()); @@ -244,13 +243,13 @@ class TagController extends ControllerBase implements CrudControllerInterface */ public function saveEditAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::TAG_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::TAG_EDIT)) { return; } try { $form = new TagForm($id); - $form->validate(ActionsInterface::TAG_EDIT); + $form->validate(Acl::TAG_EDIT); $this->tagService->update($form->getItemData()); @@ -274,7 +273,7 @@ class TagController extends ControllerBase implements CrudControllerInterface */ public function viewAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::TAG_VIEW)) { + if (!$this->acl->checkUserAccess(Acl::TAG_VIEW)) { return; } diff --git a/app/modules/web/Controllers/TaskController.php b/app/modules/web/Controllers/TaskController.php index e1f514ce..2d902572 100644 --- a/app/modules/web/Controllers/TaskController.php +++ b/app/modules/web/Controllers/TaskController.php @@ -48,6 +48,7 @@ class TaskController * TaskController constructor. * * @param Container $container + * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ @@ -58,6 +59,7 @@ class TaskController /** * @param string $taskId + * * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ diff --git a/app/modules/web/Controllers/UserController.php b/app/modules/web/Controllers/UserController.php index 39e2b995..35e63100 100644 --- a/app/modules/web/Controllers/UserController.php +++ b/app/modules/web/Controllers/UserController.php @@ -25,7 +25,6 @@ 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; @@ -67,7 +66,7 @@ class UserController extends ControllerBase implements CrudControllerInterface */ public function searchAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::USER_SEARCH)) { + if (!$this->acl->checkUserAccess(Acl::USER_SEARCH)) { return; } @@ -100,7 +99,7 @@ class UserController extends ControllerBase implements CrudControllerInterface */ public function createAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::USER_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::USER_CREATE)) { return; } @@ -141,7 +140,7 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->view->assign('profiles', SelectItemAdapter::factory(UserProfileService::getItemsBasic())->getItemsFromModel()); $this->view->assign('isUseSSO', $this->configData->isAuthBasicAutoLoginEnabled()); $this->view->assign('sk', $this->session->generateSecurityKey()); - $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ACCESS_MANAGE)); + $this->view->assign('nextAction', Acl::getActionRoute(Acl::ACCESS_MANAGE)); if ($this->view->isView === true || ($this->configData->isDemoEnabled() && $user->getLogin() === 'demo') @@ -171,9 +170,8 @@ class UserController extends ControllerBase implements CrudControllerInterface $this->view->assign('readonly'); } - // FIXME - $this->view->assign('showViewCustomPass', $this->userProfileData->isAccViewPass()); - $this->view->assign('customFields', $this->getCustomFieldsForItem(ActionsInterface::USER, $userId, $this->session)); + $this->view->assign('showViewCustomPass', $this->acl->checkUserAccess(Acl::CUSTOMFIELD_VIEW_PASS)); + $this->view->assign('customFields', $this->getCustomFieldsForItem(Acl::USER, $userId, $this->session)); } /** @@ -185,7 +183,7 @@ class UserController extends ControllerBase implements CrudControllerInterface */ public function editAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::USER_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::USER_EDIT)) { return; } @@ -217,7 +215,7 @@ class UserController extends ControllerBase implements CrudControllerInterface public function editPassAction($id) { // Comprobar si el usuario a modificar es distinto al de la sesión - if (!$this->acl->checkUserAccess(ActionsInterface::USER_EDIT_PASS, $this->userData->getId())) { + if (!$this->acl->checkUserAccess(Acl::USER_EDIT_PASS, $this->userData->getId())) { return; } @@ -254,7 +252,7 @@ class UserController extends ControllerBase implements CrudControllerInterface */ public function deleteAction($id = null) { - if (!$this->acl->checkUserAccess(ActionsInterface::USER_DELETE)) { + if (!$this->acl->checkUserAccess(Acl::USER_DELETE)) { return; } @@ -264,7 +262,7 @@ class UserController extends ControllerBase implements CrudControllerInterface if ($id === null) { $this->userService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::USER, $id); + $this->deleteCustomFieldsForItem(Acl::USER, $id); $this->eventDispatcher->notifyEvent('delete.user.selection', new Event($this, EventMessage::factory()->addDescription(__u('Usuarios eliminados'))) @@ -274,7 +272,7 @@ class UserController extends ControllerBase implements CrudControllerInterface } else { $this->userService->delete($id); - $this->deleteCustomFieldsForItem(ActionsInterface::USER, $id); + $this->deleteCustomFieldsForItem(Acl::USER, $id); $this->eventDispatcher->notifyEvent('delete.user', new Event($this, EventMessage::factory() @@ -296,19 +294,19 @@ class UserController extends ControllerBase implements CrudControllerInterface */ public function saveCreateAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::USER_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::USER_CREATE)) { return; } try { $form = new UserForm(); - $form->validate(ActionsInterface::USER_CREATE); + $form->validate(Acl::USER_CREATE); $itemData = $form->getItemData(); $id = $this->userService->create($itemData); - $this->addCustomFieldsForItem(ActionsInterface::USER, $id); + $this->addCustomFieldsForItem(Acl::USER, $id); $this->eventDispatcher->notifyEvent('create.user', new Event($this, EventMessage::factory() @@ -360,19 +358,19 @@ class UserController extends ControllerBase implements CrudControllerInterface */ public function saveEditAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::USER_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::USER_EDIT)) { return; } try { $form = new UserForm($id); - $form->validate(ActionsInterface::USER_EDIT); + $form->validate(Acl::USER_EDIT); $itemData = $form->getItemData(); $this->userService->update($itemData); - $this->updateCustomFieldsForItem(ActionsInterface::USER, $id); + $this->updateCustomFieldsForItem(Acl::USER, $id); $this->eventDispatcher->notifyEvent('edit.user', new Event($this, EventMessage::factory() @@ -399,13 +397,13 @@ class UserController extends ControllerBase implements CrudControllerInterface */ public function saveEditPassAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::USER_EDIT_PASS)) { + if (!$this->acl->checkUserAccess(Acl::USER_EDIT_PASS)) { return; } try { $form = new UserForm($id); - $form->validate(ActionsInterface::USER_EDIT_PASS); + $form->validate(Acl::USER_EDIT_PASS); $itemData = $form->getItemData(); @@ -436,7 +434,7 @@ class UserController extends ControllerBase implements CrudControllerInterface */ public function viewAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::USER_VIEW)) { + if (!$this->acl->checkUserAccess(Acl::USER_VIEW)) { return; } diff --git a/app/modules/web/Controllers/UserGroupController.php b/app/modules/web/Controllers/UserGroupController.php index 5bf76731..fea0b0f9 100644 --- a/app/modules/web/Controllers/UserGroupController.php +++ b/app/modules/web/Controllers/UserGroupController.php @@ -25,7 +25,6 @@ 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; @@ -68,7 +67,7 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf */ public function searchAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::GROUP_SEARCH)) { + if (!$this->acl->checkUserAccess(Acl::GROUP_SEARCH)) { return; } @@ -101,7 +100,7 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf */ public function createAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::GROUP_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::GROUP_CREATE)) { return; } @@ -142,7 +141,7 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf $this->view->assign('usedBy', $this->userGroupService->getUsageByUsers($userGroupId)); $this->view->assign('sk', $this->session->generateSecurityKey()); - $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ACCESS_MANAGE)); + $this->view->assign('nextAction', Acl::getActionRoute(Acl::ACCESS_MANAGE)); if ($this->view->isView === true) { $this->view->assign('disabled', 'disabled'); @@ -152,9 +151,8 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf $this->view->assign('readonly'); } - // FIXME - $this->view->assign('showViewCustomPass', $this->userProfileData->isAccViewPass()); - $this->view->assign('customFields', $this->getCustomFieldsForItem(ActionsInterface::GROUP, $userGroupId, $this->session)); + $this->view->assign('showViewCustomPass', $this->acl->checkUserAccess(Acl::CUSTOMFIELD_VIEW_PASS)); + $this->view->assign('customFields', $this->getCustomFieldsForItem(Acl::GROUP, $userGroupId, $this->session)); } /** @@ -166,7 +164,7 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf */ public function editAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::GROUP_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::GROUP_EDIT)) { return; } @@ -197,7 +195,7 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf */ public function deleteAction($id = null) { - if (!$this->acl->checkUserAccess(ActionsInterface::GROUP_DELETE)) { + if (!$this->acl->checkUserAccess(Acl::GROUP_DELETE)) { return; } @@ -205,7 +203,7 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf if ($id === null) { $this->userGroupService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::GROUP, $id); + $this->deleteCustomFieldsForItem(Acl::GROUP, $id); $this->eventDispatcher->notifyEvent('delete.userGroup.selection', new Event($this, EventMessage::factory()->addDescription(__u('Grupos eliminados'))) @@ -215,7 +213,7 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf } else { $this->userGroupService->delete($id); - $this->deleteCustomFieldsForItem(ActionsInterface::GROUP, $id); + $this->deleteCustomFieldsForItem(Acl::GROUP, $id); $this->eventDispatcher->notifyEvent('delete.userGroup', new Event($this, EventMessage::factory() @@ -237,19 +235,19 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf */ public function saveCreateAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::GROUP_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::GROUP_CREATE)) { return; } try { $form = new UserGroupForm(); - $form->validate(ActionsInterface::GROUP_CREATE); + $form->validate(Acl::GROUP_CREATE); $groupData = $form->getItemData(); $id = $this->userGroupService->create($groupData, $groupData->getUsers()); - $this->addCustomFieldsForItem(ActionsInterface::GROUP, $id); + $this->addCustomFieldsForItem(Acl::GROUP, $id); $this->eventDispatcher->notifyEvent('create.userGroup', new Event($this, EventMessage::factory() @@ -277,19 +275,19 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf */ public function saveEditAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::GROUP_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::GROUP_EDIT)) { return; } try { $form = new UserGroupForm($id); - $form->validate(ActionsInterface::GROUP_EDIT); + $form->validate(Acl::GROUP_EDIT); $groupData = $form->getItemData(); $this->userGroupService->update($groupData); - $this->updateCustomFieldsForItem(ActionsInterface::GROUP, $id); + $this->updateCustomFieldsForItem(Acl::GROUP, $id); $this->eventDispatcher->notifyEvent('edit.userGroup', new Event($this, EventMessage::factory() @@ -316,7 +314,7 @@ class UserGroupController extends ControllerBase implements CrudControllerInterf */ public function viewAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::GROUP_VIEW)) { + if (!$this->acl->checkUserAccess(Acl::GROUP_VIEW)) { return; } diff --git a/app/modules/web/Controllers/UserProfileController.php b/app/modules/web/Controllers/UserProfileController.php index c92f7369..d4e72b14 100644 --- a/app/modules/web/Controllers/UserProfileController.php +++ b/app/modules/web/Controllers/UserProfileController.php @@ -25,7 +25,6 @@ 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; @@ -62,7 +61,7 @@ class UserProfileController extends ControllerBase implements CrudControllerInte */ public function searchAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::PROFILE_SEARCH)) { + if (!$this->acl->checkUserAccess(Acl::PROFILE_SEARCH)) { return; } @@ -95,7 +94,7 @@ class UserProfileController extends ControllerBase implements CrudControllerInte */ public function createAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::PROFILE_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::PROFILE_CREATE)) { return; } @@ -135,7 +134,7 @@ class UserProfileController extends ControllerBase implements CrudControllerInte $this->view->assign('profileData', $profile->getProfile() ?: new ProfileData()); $this->view->assign('sk', $this->session->generateSecurityKey()); - $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ACCESS_MANAGE)); + $this->view->assign('nextAction', Acl::getActionRoute(Acl::ACCESS_MANAGE)); if ($this->view->isView === true) { $this->view->assign('usedBy', $this->userProfileService->getUsersForProfile($profileId)); @@ -147,7 +146,8 @@ class UserProfileController extends ControllerBase implements CrudControllerInte $this->view->assign('readonly'); } - $this->view->assign('customFields', $this->getCustomFieldsForItem(ActionsInterface::PROFILE, $profileId, $this->session)); + $this->view->assign('showViewCustomPass', $this->acl->checkUserAccess(Acl::CUSTOMFIELD_VIEW_PASS)); + $this->view->assign('customFields', $this->getCustomFieldsForItem(Acl::PROFILE, $profileId, $this->session)); } /** @@ -159,7 +159,7 @@ class UserProfileController extends ControllerBase implements CrudControllerInte */ public function editAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::PROFILE_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::PROFILE_EDIT)) { return; } @@ -190,7 +190,7 @@ class UserProfileController extends ControllerBase implements CrudControllerInte */ public function deleteAction($id = null) { - if (!$this->acl->checkUserAccess(ActionsInterface::PROFILE_DELETE)) { + if (!$this->acl->checkUserAccess(Acl::PROFILE_DELETE)) { return; } @@ -198,7 +198,7 @@ class UserProfileController extends ControllerBase implements CrudControllerInte if ($id === null) { $this->userProfileService->deleteByIdBatch($this->getItemsIdFromRequest()); - $this->deleteCustomFieldsForItem(ActionsInterface::PROFILE, $id); + $this->deleteCustomFieldsForItem(Acl::PROFILE, $id); $this->eventDispatcher->notifyEvent('delete.userProfile.selection', new Event($this, EventMessage::factory()->addDescription(__u('Perfiles eliminados'))) @@ -208,7 +208,7 @@ class UserProfileController extends ControllerBase implements CrudControllerInte } else { $this->userProfileService->delete($id); - $this->deleteCustomFieldsForItem(ActionsInterface::PROFILE, $id); + $this->deleteCustomFieldsForItem(Acl::PROFILE, $id); $this->eventDispatcher->notifyEvent('delete.userProfile', new Event($this, EventMessage::factory() @@ -230,19 +230,19 @@ class UserProfileController extends ControllerBase implements CrudControllerInte */ public function saveCreateAction() { - if (!$this->acl->checkUserAccess(ActionsInterface::PROFILE_CREATE)) { + if (!$this->acl->checkUserAccess(Acl::PROFILE_CREATE)) { return; } try { $form = new UserProfileForm(); - $form->validate(ActionsInterface::PROFILE_CREATE); + $form->validate(Acl::PROFILE_CREATE); $profileData = $form->getItemData(); $id = $this->userProfileService->create($profileData); - $this->addCustomFieldsForItem(ActionsInterface::PROFILE, $id); + $this->addCustomFieldsForItem(Acl::PROFILE, $id); $this->eventDispatcher->notifyEvent('create.userProfile', new Event($this)); @@ -266,20 +266,20 @@ class UserProfileController extends ControllerBase implements CrudControllerInte */ public function saveEditAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::PROFILE_EDIT)) { + if (!$this->acl->checkUserAccess(Acl::PROFILE_EDIT)) { return; } try { $form = new UserProfileForm($id); - $form->validate(ActionsInterface::PROFILE_EDIT); + $form->validate(Acl::PROFILE_EDIT); $profileData = $form->getItemData(); $this->userProfileService->update($profileData); -// $this->userProfileService->logAction($id, ActionsInterface::PROFILE_EDIT); +// $this->userProfileService->logAction($id, Acl::PROFILE_EDIT); - $this->updateCustomFieldsForItem(ActionsInterface::PROFILE, $id); + $this->updateCustomFieldsForItem(Acl::PROFILE, $id); $this->eventDispatcher->notifyEvent('edit.userProfile', new Event($this)); @@ -302,7 +302,7 @@ class UserProfileController extends ControllerBase implements CrudControllerInte */ public function viewAction($id) { - if (!$this->acl->checkUserAccess(ActionsInterface::PROFILE_VIEW)) { + if (!$this->acl->checkUserAccess(Acl::PROFILE_VIEW)) { return; } diff --git a/app/modules/web/Controllers/UserSettingsManagerController.php b/app/modules/web/Controllers/UserSettingsManagerController.php index 1101bda5..e8be566f 100644 --- a/app/modules/web/Controllers/UserSettingsManagerController.php +++ b/app/modules/web/Controllers/UserSettingsManagerController.php @@ -2,8 +2,8 @@ /** * sysPass * - * @author nuxsmin - * @link https://syspass.org + * @author nuxsmin + * @link https://syspass.org * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. @@ -25,7 +25,6 @@ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\Acl; -use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; use SP\Core\Language; use SP\Http\Request; @@ -35,6 +34,7 @@ use SP\Mvc\View\Components\SelectItemAdapter; /** * Class UserSettingsManagerController + * * @package web\Controllers */ class UserSettingsManagerController extends ControllerBase @@ -60,7 +60,7 @@ class UserSettingsManagerController extends ControllerBase $this->eventDispatcher->notifyEvent('show.userSettings', new Event($this)); - $this->tabsHelper->renderTabs(Acl::getActionRoute(ActionsInterface::USERSETTINGS), Request::analyzeInt('tabIndex', 0)); + $this->tabsHelper->renderTabs(Acl::getActionRoute(Acl::USERSETTINGS), Request::analyzeInt('tabIndex', 0)); $this->view(); } diff --git a/app/modules/web/themes/material-blue/views/common/aux-customfields.inc b/app/modules/web/themes/material-blue/views/common/aux-customfields.inc index 9bfa84dc..1ee07e42 100644 --- a/app/modules/web/themes/material-blue/views/common/aux-customfields.inc +++ b/app/modules/web/themes/material-blue/views/common/aux-customfields.inc @@ -48,7 +48,7 @@ foreach ($customFields as $index => $field):?> class="mdl-textfield__input mdl-color-text--indigo-400 passwordfield__no-pki " data-clipboard="1" maxlength="500" - value="value !== '') ? '***' : htmlspecialchars($field->value, ENT_QUOTES); ?>" required ? 'required' : ''; ?> > + value="value) ? '***' : htmlspecialchars($field->value, ENT_QUOTES); ?>" required ? 'required' : ''; ?> > diff --git a/lib/SP/Core/Acl/Acl.php b/lib/SP/Core/Acl/Acl.php index 8302f0c2..989223d3 100644 --- a/lib/SP/Core/Acl/Acl.php +++ b/lib/SP/Core/Acl/Acl.php @@ -70,6 +70,7 @@ class Acl implements ActionsInterface * Returns action route * * @param $actionId + * * @return string */ public static function getActionRoute($actionId) @@ -88,6 +89,7 @@ class Acl implements ActionsInterface * * @param int $actionId El id de la acción * @param bool $translate + * * @return string * @internal param bool $shortName Si se devuelve el nombre corto de la acción */ @@ -111,6 +113,7 @@ class Acl implements ActionsInterface * * @param string $action con el nombre de la acción * @param int $userId opcional, con el Id del usuario + * * @return bool */ public function checkUserAccess($action, $userId = 0) @@ -246,6 +249,8 @@ class Acl implements ActionsInterface case self::EVENTLOG_SEARCH: case self::EVENTLOG_CLEAR: return $userProfile->isEvl(); + case self::CUSTOMFIELD_VIEW_PASS: + return ($userData->getIsAdminApp() || $userProfile->isAccViewPass()); case self::ACCOUNT_REQUEST: case self::NOTIFICATION: case self::NOTIFICATION_VIEW: diff --git a/lib/SP/Core/Acl/ActionsInterface.php b/lib/SP/Core/Acl/ActionsInterface.php index 362751ed..72b4cb56 100644 --- a/lib/SP/Core/Acl/ActionsInterface.php +++ b/lib/SP/Core/Acl/ActionsInterface.php @@ -86,6 +86,7 @@ interface ActionsInterface const CUSTOMFIELD_VIEW = 641; const CUSTOMFIELD_EDIT = 642; const CUSTOMFIELD_DELETE = 643; + const CUSTOMFIELD_VIEW_PASS = 644; const CUSTOMFIELD_SEARCH = 645; const PUBLICLINK = 65; const PUBLICLINK_CREATE = 650; diff --git a/lib/SP/Repositories/CustomField/CustomFieldRepository.php b/lib/SP/Repositories/CustomField/CustomFieldRepository.php index 5264265f..8265f6b7 100644 --- a/lib/SP/Repositories/CustomField/CustomFieldRepository.php +++ b/lib/SP/Repositories/CustomField/CustomFieldRepository.php @@ -120,7 +120,7 @@ class CustomFieldRepository extends Repository implements RepositoryItemInterfac * * @param CustomFieldData $itemData * - * @return bool + * @return int * @throws QueryException * @throws ConstraintException */ @@ -290,7 +290,7 @@ class CustomFieldRepository extends Repository implements RepositoryItemInterfac } /** - * Returns all the items + * Returns all the items that were encryptes * * @return CustomFieldData[] * @throws QueryException diff --git a/lib/SP/Repositories/CustomField/CustomFieldTypeRepository.php b/lib/SP/Repositories/CustomField/CustomFieldTypeRepository.php index 76e5db78..b8d8020c 100644 --- a/lib/SP/Repositories/CustomField/CustomFieldTypeRepository.php +++ b/lib/SP/Repositories/CustomField/CustomFieldTypeRepository.php @@ -29,6 +29,7 @@ use SP\Core\Exceptions\QueryException; use SP\Core\Exceptions\SPException; use SP\DataModel\CustomFieldTypeData; use SP\DataModel\ItemSearchData; +use SP\Repositories\NoSuchItemException; use SP\Repositories\Repository; use SP\Repositories\RepositoryItemInterface; use SP\Repositories\RepositoryItemTrait; @@ -118,6 +119,7 @@ class CustomFieldTypeRepository extends Repository implements RepositoryItemInte * * @return CustomFieldTypeData * @throws ConstraintException + * @throws NoSuchItemException * @throws QueryException */ public function getById($id) @@ -127,7 +129,13 @@ class CustomFieldTypeRepository extends Repository implements RepositoryItemInte $queryData->setQuery('SELECT id, `name`, `text` FROM CustomFieldType WHERE id = ? LIMIT 1'); $queryData->addParam($id); - return $this->db->doSelect($queryData)->getData(); + $result = $this->db->doSelect($queryData); + + if ($result->getNumRows() === 0) { + throw new NoSuchItemException(__u('Tipo de campo no encontrado')); + } + + return $result->getData(); } /** @@ -163,15 +171,22 @@ class CustomFieldTypeRepository extends Repository implements RepositoryItemInte * * @param array $ids * - * @return void + * @return int * @throws ConstraintException * @throws QueryException */ public function deleteByIdBatch(array $ids) { - foreach ($ids as $id) { - $this->delete($id); + if (empty($ids)) { + return 0; } + + $queryData = new QueryData(); + $queryData->setQuery('DELETE FROM CustomFieldType WHERE id IN (' . $this->getParamsFromArray($ids) . ')'); + $queryData->setParams($ids); + $queryData->setOnErrorMessage(__u('Error al eliminar el tipo de campo')); + + return $this->db->doQuery($queryData)->getAffectedNumRows(); } /** diff --git a/lib/SP/Services/CustomField/CustomFieldService.php b/lib/SP/Services/CustomField/CustomFieldService.php index 4f9fec9d..8ed21dba 100644 --- a/lib/SP/Services/CustomField/CustomFieldService.php +++ b/lib/SP/Services/CustomField/CustomFieldService.php @@ -160,11 +160,13 @@ class CustomFieldService extends Service * Creates an item * * @param CustomFieldData $customFieldData + * * @return bool * @throws CryptoException * @throws QueryException * @throws ServiceException * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Repositories\NoSuchItemException */ public function create(CustomFieldData $customFieldData) { diff --git a/lib/SP/Services/Install/Installer.php b/lib/SP/Services/Install/Installer.php index 30f5bc5c..b4979c62 100644 --- a/lib/SP/Services/Install/Installer.php +++ b/lib/SP/Services/Install/Installer.php @@ -56,7 +56,7 @@ class Installer extends Service */ const VERSION = [3, 0, 0]; const VERSION_TEXT = '3.0-beta'; - const BUILD = 18061301; + const BUILD = 18061401; /** * @var ConfigService diff --git a/tests/Repositories/CustomFieldDefRepositoryTest.php b/tests/Repositories/CustomFieldDefRepositoryTest.php index b6711525..035295f8 100644 --- a/tests/Repositories/CustomFieldDefRepositoryTest.php +++ b/tests/Repositories/CustomFieldDefRepositoryTest.php @@ -99,9 +99,13 @@ class CustomFieldDefRepositoryTest extends DatabaseTestCase */ public function testDeleteByIdBatch() { - $this->assertEquals(2, self::$customFieldDefRepository->deleteByIdBatch([1, 2, 3])); - $this->assertEquals(0, $this->conn->getRowCount('CustomFieldDefinition')); + $this->assertEquals(1, self::$customFieldDefRepository->deleteByIdBatch([3, 4])); + $this->assertEquals(2, $this->conn->getRowCount('CustomFieldDefinition')); $this->assertEquals(0, self::$customFieldDefRepository->deleteByIdBatch([])); + + $this->expectException(ConstraintException::class); + + self::$customFieldDefRepository->deleteByIdBatch([1, 2]); } /** @@ -176,7 +180,7 @@ class CustomFieldDefRepositoryTest extends DatabaseTestCase public function testCreate() { $data = new CustomFieldDefinitionData(); - $data->setId(3); + $data->setId(4); $data->setName('Phone'); $data->setIsEncrypted(0); $data->setHelp('Telefono'); @@ -185,9 +189,9 @@ class CustomFieldDefRepositoryTest extends DatabaseTestCase $data->setTypeId(6); $data->setShowInList(0); - $this->assertEquals(3, self::$customFieldDefRepository->create($data)); + $this->assertEquals(4, self::$customFieldDefRepository->create($data)); - $this->assertEquals($data, self::$customFieldDefRepository->getById(3)); + $this->assertEquals($data, self::$customFieldDefRepository->getById(4)); } /** @@ -200,7 +204,7 @@ class CustomFieldDefRepositoryTest extends DatabaseTestCase $data = self::$customFieldDefRepository->getAll(); - $this->assertCount(2, $data); + $this->assertCount(3, $data); $expected = new CustomFieldDefinitionData(); $expected->setId(1); @@ -239,9 +243,9 @@ class CustomFieldDefRepositoryTest extends DatabaseTestCase $result = self::$customFieldDefRepository->search($itemSearchData); $data = $result->getDataAsArray(); - $this->assertEquals(1, $result->getNumRows()); - $this->assertEquals(1, $result->getTotalNumRows()); - $this->assertCount(1, $data); + $this->assertEquals(2, $result->getNumRows()); + $this->assertEquals(2, $result->getTotalNumRows()); + $this->assertCount(2, $data); $this->assertInstanceOf(CustomFieldDefinitionData::class, $data[0]); $this->assertEquals(2, $data[0]->id); $this->assertEquals('password', $data[0]->typeName); @@ -260,9 +264,13 @@ class CustomFieldDefRepositoryTest extends DatabaseTestCase */ public function testDelete() { - $this->assertEquals(1, self::$customFieldDefRepository->delete(1)); + $this->assertEquals(1, self::$customFieldDefRepository->delete(3)); $this->assertEquals(0, self::$customFieldDefRepository->delete(10)); - $this->assertEquals(1, $this->conn->getRowCount('CustomFieldDefinition')); + $this->assertEquals(2, $this->conn->getRowCount('CustomFieldDefinition')); + + $this->expectException(ConstraintException::class); + + self::$customFieldDefRepository->delete(1); } /** diff --git a/tests/Repositories/CustomFieldRepositoryTest.php b/tests/Repositories/CustomFieldRepositoryTest.php new file mode 100644 index 00000000..0c8af9f4 --- /dev/null +++ b/tests/Repositories/CustomFieldRepositoryTest.php @@ -0,0 +1,390 @@ +. + */ + +namespace SP\Tests\Repositories; + +use SP\Core\Acl\ActionsInterface; +use SP\Core\Exceptions\ConstraintException; +use SP\DataModel\CustomFieldData; +use SP\Repositories\CustomField\CustomFieldRepository; +use SP\Storage\Database\DatabaseConnectionData; +use SP\Tests\DatabaseTestCase; +use function SP\Tests\setupContext; + +/** + * Class CustomFieldRepositoryTest + * + * @package SP\Tests\Repositories + */ +class CustomFieldRepositoryTest extends DatabaseTestCase +{ + /** + * @var CustomFieldRepository + */ + private static $customFieldRepository; + + /** + * @throws \DI\NotFoundException + * @throws \SP\Core\Context\ContextException + * @throws \DI\DependencyException + */ + public static function setUpBeforeClass() + { + $dic = setupContext(); + + // Datos de conexión a la BBDD + self::$databaseConnectionData = $dic->get(DatabaseConnectionData::class); + + // Inicializar el repositorio + self::$customFieldRepository = $dic->get(CustomFieldRepository::class); + } + + /** + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function testDeleteCustomFieldDataBatch() + { + $this->assertEquals(1, self::$customFieldRepository->deleteCustomFieldDataBatch([1, 2, 3], ActionsInterface::ACCOUNT)); + + $this->assertEquals(1, self::$customFieldRepository->deleteCustomFieldDataBatch([1, 2, 3], ActionsInterface::CATEGORY)); + + $this->assertEquals(0, $this->conn->getRowCount('CustomFieldData')); + + $this->assertEquals(0, self::$customFieldRepository->deleteCustomFieldDataBatch([], ActionsInterface::CATEGORY)); + + $this->assertEquals(0, self::$customFieldRepository->deleteCustomFieldDataBatch([], ActionsInterface::USER)); + + } + + /** + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function testDeleteCustomFieldDataForDefinition() + { + $this->assertEquals(1, self::$customFieldRepository->deleteCustomFieldDataForDefinition(1, ActionsInterface::ACCOUNT, 1)); + $this->assertEquals(0, self::$customFieldRepository->deleteCustomFieldDataForDefinition(1, ActionsInterface::ACCOUNT, 2)); + $this->assertEquals(0, self::$customFieldRepository->deleteCustomFieldDataForDefinition(10, ActionsInterface::ACCOUNT, 3)); + + $this->assertEquals(1, self::$customFieldRepository->deleteCustomFieldDataForDefinition(1, ActionsInterface::CATEGORY, 2)); + $this->assertEquals(0, self::$customFieldRepository->deleteCustomFieldDataForDefinition(1, ActionsInterface::CATEGORY, 1)); + $this->assertEquals(0, self::$customFieldRepository->deleteCustomFieldDataForDefinition(10, ActionsInterface::CATEGORY, 3)); + + $this->assertEquals(0, self::$customFieldRepository->deleteCustomFieldDataForDefinition(1, ActionsInterface::USER, 1)); + $this->assertEquals(0, self::$customFieldRepository->deleteCustomFieldDataForDefinition(1, ActionsInterface::USER, 2)); + } + + /** + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function testCheckExists() + { + $data = new CustomFieldData(); + $data->setModuleId(ActionsInterface::ACCOUNT); + $data->setDefinitionId(1); + $data->setId(1); + + $this->assertTrue(self::$customFieldRepository->checkExists($data)); + + $data->setModuleId(ActionsInterface::CATEGORY); + $data->setDefinitionId(1); + $data->setId(1); + + $this->assertFalse(self::$customFieldRepository->checkExists($data)); + + $data->setModuleId(ActionsInterface::USER); + $data->setDefinitionId(1); + $data->setId(1); + + $this->assertFalse(self::$customFieldRepository->checkExists($data)); + } + + /** + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function testGetAllEncrypted() + { + $result = self::$customFieldRepository->getAllEncrypted(); + + $this->assertCount(1, $result); + $this->assertInstanceOf(CustomFieldData::class, $result[0]); + $this->assertEquals(1, $result[0]->getItemId()); + $this->assertEquals(ActionsInterface::ACCOUNT, $result[0]->getModuleId()); + $this->assertEquals(1, $result[0]->getItemId()); + } + + /** + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function testDeleteCustomFieldDefinitionDataBatch() + { + $this->assertEquals(2, self::$customFieldRepository->deleteCustomFieldDefinitionDataBatch([1, 2, 3])); + + $this->assertEquals(0, $this->conn->getRowCount('CustomFieldData')); + + $this->assertEquals(0, self::$customFieldRepository->deleteCustomFieldDefinitionDataBatch([])); + } + + /** + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function testGetAll() + { + $result = self::$customFieldRepository->getAll(); + + $this->assertCount(2, $result); + $this->assertInstanceOf(CustomFieldData::class, $result[0]); + $this->assertInstanceOf(CustomFieldData::class, $result[1]); + } + + /** + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function testDeleteCustomFieldData() + { + $this->assertEquals(1, self::$customFieldRepository->deleteCustomFieldData(1, ActionsInterface::ACCOUNT)); + $this->assertEquals(1, self::$customFieldRepository->deleteCustomFieldData(1, ActionsInterface::CATEGORY)); + + $this->assertEquals(0, $this->conn->getRowCount('CustomFieldData')); + + $this->assertEquals(0, self::$customFieldRepository->deleteCustomFieldData(2, ActionsInterface::ACCOUNT)); + + $this->assertEquals(0, self::$customFieldRepository->deleteCustomFieldData(2, ActionsInterface::CATEGORY)); + + $this->assertEquals(0, self::$customFieldRepository->deleteCustomFieldData(2, ActionsInterface::USER)); + } + + /** + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function testGetForModuleById() + { + $result = self::$customFieldRepository->getForModuleById(ActionsInterface::ACCOUNT, 1); + + $this->assertCount(1, $result); + $this->assertEquals('Prueba', $result[0]->definitionName); + $this->assertEquals(1, $result[0]->definitionId); + $this->assertEquals(ActionsInterface::ACCOUNT, $result[0]->moduleId); + $this->assertEquals(1, $result[0]->required); + $this->assertEquals(0, $result[0]->showInList); + $this->assertEquals('Ayuda', $result[0]->help); + $this->assertEquals(1, $result[0]->isEncrypted); + $this->assertEquals(1, $result[0]->typeId); + $this->assertEquals('text', $result[0]->typeName); + $this->assertEquals('Texto', $result[0]->typeText); + $this->assertNotEmpty($result[0]->data); + $this->assertNotEmpty($result[0]->key); + + $result = self::$customFieldRepository->getForModuleById(ActionsInterface::ACCOUNT, 2); + + $this->assertCount(1, $result); + $this->assertEquals('Prueba', $result[0]->definitionName); + $this->assertEquals(1, $result[0]->definitionId); + $this->assertEquals(ActionsInterface::ACCOUNT, $result[0]->moduleId); + $this->assertEquals(1, $result[0]->required); + $this->assertEquals(0, $result[0]->showInList); + $this->assertEquals('Ayuda', $result[0]->help); + $this->assertEquals(1, $result[0]->isEncrypted); + $this->assertEquals(1, $result[0]->typeId); + $this->assertEquals('text', $result[0]->typeName); + $this->assertEquals('Texto', $result[0]->typeText); + $this->assertEmpty($result[0]->data); + $this->assertEmpty($result[0]->key); + + $result = self::$customFieldRepository->getForModuleById(ActionsInterface::ACCOUNT, 3); + + $this->assertCount(1, $result); + + $result = self::$customFieldRepository->getForModuleById(ActionsInterface::CATEGORY, 1); + + $this->assertCount(2, $result); + $this->assertEquals('RSA', $result[0]->definitionName); + $this->assertEquals(2, $result[0]->definitionId); + $this->assertEquals(ActionsInterface::CATEGORY, $result[0]->moduleId); + $this->assertEquals(0, $result[0]->required); + $this->assertEquals(0, $result[0]->showInList); + $this->assertEquals(null, $result[0]->help); + $this->assertEquals(0, $result[0]->isEncrypted); + $this->assertEquals(2, $result[0]->typeId); + $this->assertEquals('password', $result[0]->typeName); + $this->assertEquals('Clave', $result[0]->typeText); + $this->assertNotEmpty($result[0]->data); + $this->assertNull($result[0]->key); + + $result = self::$customFieldRepository->getForModuleById(ActionsInterface::CATEGORY, 2); + + $this->assertCount(2, $result); + $this->assertEquals('RSA', $result[0]->definitionName); + $this->assertEquals(2, $result[0]->definitionId); + $this->assertEquals(ActionsInterface::CATEGORY, $result[0]->moduleId); + $this->assertEquals(0, $result[0]->required); + $this->assertEquals(0, $result[0]->showInList); + $this->assertEquals(null, $result[0]->help); + $this->assertEquals(0, $result[0]->isEncrypted); + $this->assertEquals(2, $result[0]->typeId); + $this->assertEquals('password', $result[0]->typeName); + $this->assertEquals('Clave', $result[0]->typeText); + $this->assertNull($result[0]->data); + $this->assertNull($result[0]->key); + + $result = self::$customFieldRepository->getForModuleById(ActionsInterface::CATEGORY, 3); + + $this->assertCount(2, $result); + + $result = self::$customFieldRepository->getForModuleById(ActionsInterface::USER, 1); + + $this->assertCount(0, $result); + } + + /** + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function testCreate() + { + $data = new CustomFieldData(); + $data->setId(2); + $data->setModuleId(ActionsInterface::ACCOUNT); + $data->setDefinitionId(1); + $data->setData('cuenta'); + $data->setKey('nan'); + + $this->assertEquals(3, self::$customFieldRepository->create($data)); + + $data = new CustomFieldData(); + $data->setId(2); + $data->setModuleId(ActionsInterface::CATEGORY); + $data->setDefinitionId(2); + $data->setData('categoria'); + $data->setKey('nan'); + + $this->assertEquals(4, self::$customFieldRepository->create($data)); + + $this->expectException(ConstraintException::class); + + $data = new CustomFieldData(); + $data->setId(2); + $data->setModuleId(ActionsInterface::ACCOUNT); + $data->setDefinitionId(1); + $data->setData('cuenta'); + $data->setKey('nan'); + + self::$customFieldRepository->create($data); + + $data->setDefinitionId(3); + + self::$customFieldRepository->create($data); + + $data = new CustomFieldData(); + $data->setId(2); + $data->setModuleId(ActionsInterface::CATEGORY); + $data->setDefinitionId(2); + $data->setData('categoria'); + $data->setKey('nan'); + + self::$customFieldRepository->create($data); + + $data->setDefinitionId(4); + + self::$customFieldRepository->create($data); + + $this->assertEquals(4, $this->conn->getRowCount('CustomFieldData')); + } + + /** + * @throws ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function testDeleteCustomFieldDefinitionData() + { + $this->assertEquals(1, self::$customFieldRepository->deleteCustomFieldDefinitionData(1)); + $this->assertEquals(1, self::$customFieldRepository->deleteCustomFieldDefinitionData(2)); + + $this->assertEquals(0, $this->conn->getRowCount('CustomFieldData')); + } + + /** + * @throws ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function testUpdate() + { + $data = new CustomFieldData(); + $data->setId(1); + $data->setModuleId(ActionsInterface::ACCOUNT); + $data->setDefinitionId(1); + $data->setData('cuenta'); + $data->setKey('nan'); + + $this->assertEquals(1, self::$customFieldRepository->update($data)); + + $data = new CustomFieldData(); + $data->setId(1); + $data->setModuleId(ActionsInterface::CATEGORY); + $data->setDefinitionId(2); + $data->setData('categoria'); + $data->setKey('nan'); + + $this->assertEquals(1, self::$customFieldRepository->update($data)); + + + $data = new CustomFieldData(); + $data->setId(2); + $data->setModuleId(ActionsInterface::ACCOUNT); + $data->setDefinitionId(1); + $data->setData('cuenta'); + $data->setKey('nan'); + + $this->assertEquals(0, self::$customFieldRepository->update($data)); + + $data = new CustomFieldData(); + $data->setId(2); + $data->setModuleId(ActionsInterface::CATEGORY); + $data->setDefinitionId(2); + $data->setData('categoria'); + $data->setKey('nan'); + + $this->assertEquals(0, self::$customFieldRepository->update($data)); + + $this->assertEquals(0, self::$customFieldRepository->update(new CustomFieldData())); + + $data = new CustomFieldData(); + $data->setId(2); + $data->setModuleId(ActionsInterface::USER); + $data->setDefinitionId(3); + $data->setData('nan'); + $data->setKey('nan'); + + $this->assertEquals(0, self::$customFieldRepository->update($data)); + + $this->assertEquals(2, $this->conn->getRowCount('CustomFieldData')); + } +} diff --git a/tests/Repositories/CustomFieldTypeRepositoryTest.php b/tests/Repositories/CustomFieldTypeRepositoryTest.php new file mode 100644 index 00000000..48f26243 --- /dev/null +++ b/tests/Repositories/CustomFieldTypeRepositoryTest.php @@ -0,0 +1,163 @@ +. + */ + +namespace SP\Tests\Repositories; + +use SP\Core\Exceptions\ConstraintException; +use SP\DataModel\CustomFieldTypeData; +use SP\Repositories\CustomField\CustomFieldTypeRepository; +use SP\Repositories\NoSuchItemException; +use SP\Storage\Database\DatabaseConnectionData; +use SP\Tests\DatabaseTestCase; +use function SP\Tests\setupContext; + +/** + * Class CustomFieldTypeRepositoryTest + * + * @package SP\Tests\Repositories + */ +class CustomFieldTypeRepositoryTest extends DatabaseTestCase +{ + /** + * @var CustomFieldTypeRepository + */ + private static $customFieldTypeRepository; + + /** + * @throws \DI\NotFoundException + * @throws \SP\Core\Context\ContextException + * @throws \DI\DependencyException + */ + public static function setUpBeforeClass() + { + $dic = setupContext(); + + // Datos de conexión a la BBDD + self::$databaseConnectionData = $dic->get(DatabaseConnectionData::class); + + // Inicializar el repositorio + self::$customFieldTypeRepository = $dic->get(CustomFieldTypeRepository::class); + } + + /** + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function testDeleteByIdBatch() + { + $countBefore = $this->conn->getRowCount('CustomFieldType'); + + $this->assertEquals(2, self::$customFieldTypeRepository->deleteByIdBatch([3, 4, 100])); + $this->assertEquals(0, self::$customFieldTypeRepository->deleteByIdBatch([])); + $this->assertEquals($countBefore - 2, $this->conn->getRowCount('CustomFieldType')); + + $this->expectException(ConstraintException::class); + + self::$customFieldTypeRepository->deleteByIdBatch([1, 2]); + } + + /** + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function testDelete() + { + $countBefore = $this->conn->getRowCount('CustomFieldType'); + + $this->assertEquals(1, self::$customFieldTypeRepository->delete(3)); + $this->assertEquals(0, self::$customFieldTypeRepository->delete(100)); + $this->assertEquals($countBefore - 1, $this->conn->getRowCount('CustomFieldType')); + + $this->expectException(ConstraintException::class); + + self::$customFieldTypeRepository->delete(1); + self::$customFieldTypeRepository->delete(2); + } + + /** + * @throws ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function testGetAll() + { + $result = self::$customFieldTypeRepository->getAll(); + + $this->assertCount(10, $result); + $this->assertInstanceOf(CustomFieldTypeData::class, $result[0]); + $this->assertEquals(1, $result[0]->getId()); + $this->assertEquals('text', $result[0]->getName()); + $this->assertEquals('Texto', $result[0]->getText()); + } + + /** + * @throws ConstraintException + * @throws \SP\Core\Exceptions\QueryException + * @throws \SP\Core\Exceptions\SPException + */ + public function testCreate() + { + $data = new CustomFieldTypeData(); + $data->setId(11); + $data->setName('prueba'); + $data->setText('Prueba'); + + $this->assertEquals(11, self::$customFieldTypeRepository->create($data)); + $this->assertEquals($data, self::$customFieldTypeRepository->getById(11)); + } + + /** + * @throws ConstraintException + * @throws \SP\Core\Exceptions\QueryException + * @throws \SP\Core\Exceptions\SPException + */ + public function testUpdate() + { + $data = new CustomFieldTypeData(); + $data->setId(10); + $data->setName('prueba'); + $data->setText('Prueba'); + + $this->assertEquals(1, self::$customFieldTypeRepository->update($data)); + $this->assertEquals($data, self::$customFieldTypeRepository->getById(10)); + } + + /** + * @throws ConstraintException + * @throws \SP\Core\Exceptions\QueryException + * @throws \SP\Repositories\NoSuchItemException + */ + public function testGetById() + { + $data = new CustomFieldTypeData(); + $data->setId(10); + $data->setName('textarea'); + $data->setText('Área de Texto'); + + $this->assertEquals($data, self::$customFieldTypeRepository->getById(10)); + + $this->expectException(NoSuchItemException::class); + + $this->assertEquals(0, self::$customFieldTypeRepository->getById(11)); + } +} diff --git a/tests/res/datasets/syspass.xml b/tests/res/datasets/syspass.xml index bf1ea809..edd23c37 100644 --- a/tests/res/datasets/syspass.xml +++ b/tests/res/datasets/syspass.xml @@ -386,6 +386,35 @@ 2 0 + + 3 + RSA Priv + 61 + + 0 + + 0 + 2 + 0 + + + + + 1 + 10 + 1 + 1 + 6465663530323030633262353536613539613465333330646461323833363730363462623861326463336630643963386565333935366134326631326135326261323035633036663063313933313263626465353630396562303133356364613461353738636534616263323436343235613739343338663461393231353433623437633062386134363566336466663131373061613162663532356466646434383165613664333763303537396132 + 6465663130303030646566353032303061356237393366343238663337393936356539393836656663363632396332613462336662323431666131343731326332333138323465376632366639313863383663653164636330393838333735343463326237316232383361663135633731363438326630303863313135326563623238383939313939346139376165613836623432613534333166383261343734343565636336376137643462633266396263343065653162333236343030373163333334386338626331613632323165613534346433396630636537343538356561653432376266373131633864366237336166316561613237623630643863626631643531666636366133366562636364353232643538633734653664626363613534646334366662303739626631653537626530646231643363316464313264303139633665663437633366353431303231633233376639303066333633323838613864346464393463323637306365313239393864626237396235333262623266383330323164663062656631326138363664646132343132653338333535636137646465613364336663366535303532346634653961313435366466313034626238376433633532353837643036613162383066613361613064643330633866356239373338663930336535653432653362363333333739333863 + + + 2 + 61 + 1 + 2 + 4C6F72656D20697073756D20646F6C6F722073697420616D65742C20636F6E73656374657475722061646970697363696E6720656C69742E205365642075742074696E636964756E74206C6F72656D2E205072616573656E74207665686963756C6120766F6C7574706174206C696265726F2073697420616D65742066617563696275732E2041656E65616E20766974616520617263752071756973206C616375732070756C76696E617220737573636970697420617420656765742074656C6C75732E204E616D2066656C6973207475727069732C207363656C657269737175652075742066656C69732061632C2074696E636964756E74206D6178696D7573206D692E205365642076756C7075746174652076697461652073656D20616320736F6C6C696369747564696E2E20446F6E6563206672696E67696C6C61206C6F626F7274697320657820657520706F72747469746F722E20457469616D2073656D70657220736F6C6C696369747564696E207665686963756C612E20467573636520766172697573206E756C6C61206D657475732C206E65632076697665727261206E696268206469676E697373696D2069642E + +