From 7cad0e4a07274e179d72e6550d3765916e5df55a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D?= Date: Tue, 20 Aug 2024 15:12:51 +0200 Subject: [PATCH] test(IT): Test account file use cases (WIP) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rubén D --- .../Account/SaveEditRestoreController.php | 5 +- .../Account/SaveRequestController.php | 4 +- .../Account/ViewHistoryController.php | 6 +- .../Account/ViewLinkController.php | 6 +- .../AccountFavorite/AccountFavoriteBase.php | 6 +- .../AccountFavorite/MarkController.php | 2 +- .../AccountFavorite/UnmarkController.php | 2 +- .../AccountFile/AccountFileBase.php | 19 +- .../AccountFile/DeleteController.php | 15 +- .../AccountFile/DownloadController.php | 26 +- .../AccountFile/ListController.php | 24 +- .../AccountFile/SearchController.php | 26 +- .../SearchController.php | 7 +- .../ConfigManager/IndexController.php | 12 +- .../web/Controllers/ControllerBase.php | 20 +- .../Helpers/Account/AccountHelper.php | 24 +- .../Helpers/Account/AccountHelperBase.php | 2 +- .../Helpers/Account/AccountHistoryHelper.php | 38 +-- .../Helpers/Account/AccountPasswordHelper.php | 2 +- .../Helpers/Account/AccountSearchData.php | 4 +- .../Helpers/Account/AccountSearchHelper.php | 8 +- .../web/Controllers/Helpers/Grid/FileGrid.php | 13 +- .../web/Controllers/Helpers/LayoutHelper.php | 16 +- .../Notification/DeleteController.php | 4 +- .../Notification/NotificationViewBase.php | 2 +- .../UserSettingsGeneral/SaveController.php | 6 +- app/modules/web/Forms/AccountForm.php | 163 ++++------ .../views/account/account-history.inc | 17 +- .../material-blue/views/account/details.inc | 24 +- .../views/grid/datagrid-rows.inc | 92 ++++-- lib/SP/Core/Acl/Acl.php | 30 +- lib/SP/Core/Context/Session.php | 12 +- lib/SP/Core/Context/Stateless.php | 12 +- lib/SP/Core/Language.php | 6 +- lib/SP/Core/UI/Theme.php | 2 +- lib/SP/Domain/Account/Dtos/AccountDto.php | 280 +++++------------- .../Domain/Account/Dtos/AccountHistoryDto.php | 151 ++++------ .../Account/Dtos/AccountHistoryViewDto.php | 102 +------ lib/SP/Domain/Account/Dtos/AccountViewDto.php | 68 ++--- lib/SP/Domain/Account/Dtos/FileDto.php | 47 +++ .../Domain/Account/Models/AccountHistory.php | 17 +- .../Domain/Account/Models/AccountUseCases.php | 54 ++-- .../Account/Ports/AccountAclService.php | 6 +- .../Account/Ports/AccountFileRepository.php | 14 +- .../Account/Ports/AccountFileService.php | 12 +- .../Account/Ports/AccountHistoryService.php | 5 +- .../Domain/Account/Ports/AccountService.php | 4 +- lib/SP/Domain/Account/Services/Account.php | 49 +-- lib/SP/Domain/Account/Services/AccountAcl.php | 30 +- .../Domain/Account/Services/AccountFile.php | 28 +- .../Account/Services/AccountHistory.php | 7 +- .../Domain/Account/Services/AccountItems.php | 55 ++-- .../Domain/Account/Services/AccountPreset.php | 14 +- .../Domain/Account/Services/AccountSearch.php | 4 +- .../Services/Builders/AccountFilter.php | 19 +- lib/SP/Domain/Api/Services/Api.php | 13 +- .../Auth/Ports/LoginMasterPassService.php | 7 +- lib/SP/Domain/Auth/Ports/LoginUserService.php | 7 +- lib/SP/Domain/Auth/Providers/AuthDataBase.php | 6 +- lib/SP/Domain/Auth/Providers/AuthProvider.php | 4 +- .../Auth/Providers/AuthProviderService.php | 6 +- .../Auth/Providers/Database/DatabaseAuth.php | 33 ++- lib/SP/Domain/Auth/Services/AuthToken.php | 2 +- lib/SP/Domain/Auth/Services/Login.php | 15 +- .../Domain/Auth/Services/LoginMasterPass.php | 15 +- lib/SP/Domain/Auth/Services/LoginUser.php | 17 +- .../Common/Attributes/DtoTransformation.php | 42 +++ .../Domain/Common/Attributes/Hydratable.php | 4 +- .../Domain/Common/Attributes/ModelBounded.php | 49 +++ .../Common/Attributes/UpgradeVersion.php | 2 + lib/SP/Domain/Common/Dtos/Dto.php | 189 ++++++++---- lib/SP/Domain/Common/Models/Model.php | 84 ++---- lib/SP/Domain/Common/Ports/Dto.php | 59 ++++ lib/SP/Domain/Config/Services/ConfigFile.php | 2 +- lib/SP/Domain/Core/Context/Context.php | 6 +- lib/SP/Domain/Export/Services/XmlExport.php | 6 +- lib/SP/Domain/Import/Services/CsvImport.php | 4 +- lib/SP/Domain/Import/Services/ImportBase.php | 32 +- .../Domain/Import/Services/KeepassImport.php | 12 +- .../Domain/Import/Services/SyspassImport.php | 2 +- .../Domain/ItemPreset/Services/ItemPreset.php | 9 +- lib/SP/Domain/Log/Providers/LoggerBase.php | 2 +- .../Notification/Services/MailEvent.php | 4 +- .../Notification/Services/Notification.php | 13 +- lib/SP/Domain/Security/Services/Eventlog.php | 4 +- lib/SP/Domain/User/Dtos/UserDataDto.php | 158 ---------- lib/SP/Domain/User/Dtos/UserDto.php | 79 +++++ .../User/Ports/UserMasterPassService.php | 7 +- .../Domain/User/Services/UserMasterPass.php | 25 +- .../Account/Repositories/AccountFile.php | 43 +-- .../Account/Repositories/AccountSearch.php | 2 +- .../Infrastructure/Database/QueryResult.php | 4 +- .../Infrastructure/User/Repositories/User.php | 2 +- lib/SP/Util/Util.php | 27 +- tests/SP/Core/Acl/ActionsTest.php | 2 + tests/SP/Core/LanguageTest.php | 12 +- tests/SP/Core/UI/ThemeTest.php | 13 +- .../Account/Services/AccountAclTest.php | 9 +- .../Account/Services/AccountFileTest.php | 16 +- .../Services/AccountFilterUserTest.php | 55 ++-- .../Account/Services/AccountHistoryTest.php | 6 +- .../Account/Services/AccountItemsTest.php | 44 +-- .../Account/Services/AccountPresetTest.php | 4 +- .../Account/Services/AccountSearchTest.php | 2 +- .../Domain/Account/Services/AccountTest.php | 118 ++++---- .../SP/Domain/Auth/Services/AuthTokenTest.php | 28 +- .../Auth/Services/LoginMasterPassTest.php | 64 ++-- tests/SP/Domain/Auth/Services/LoginTest.php | 36 ++- .../SP/Domain/Auth/Services/LoginUserTest.php | 17 +- tests/SP/Domain/Common/Models/ModelTest.php | 132 +++++++++ .../Export/Services/FileBackupServiceTest.php | 4 +- .../Domain/Export/Services/XmlExportTest.php | 38 ++- .../Domain/Import/Services/CsvImportTest.php | 43 +-- .../Import/Services/SyspassImportTest.php | 141 +++++---- .../ItemPreset/Services/ItemPresetTest.php | 4 +- .../Domain/Log/Providers/LogHandlerTest.php | 6 +- .../Services/NotificationTest.php | 28 +- .../Domain/Security/Services/EventlogTest.php | 5 +- .../User/Services/UserMasterPassTest.php | 79 ++--- tests/SP/Generators/AccountDataGenerator.php | 70 ++--- .../Account/Repositories/AccountFileTest.php | 12 +- .../User/Repositories/UserTest.php | 6 +- tests/SP/IntegrationTestCase.php | 34 ++- .../UpdateMasterPasswordCommandTest.php | 5 +- .../Account/CopyControllerTest.php | 4 +- .../Account/CopyPassControllerTest.php | 2 +- .../Account/CopyPassHistoryControllerTest.php | 2 +- .../Account/DeleteControllerTest.php | 4 +- .../Account/EditControllerTest.php | 2 +- .../Account/RequestAccessControllerTest.php | 2 +- .../Account/SaveCopyControllerTest.php | 2 +- .../Account/SaveCreateControllerTest.php | 2 +- .../Account/SaveDeleteControllerTest.php | 4 +- .../Account/SaveEditControllerTest.php | 4 +- .../Account/SaveEditPassControllerTest.php | 4 +- .../Account/SaveEditRestoreControllerTest.php | 6 +- .../Account/SaveRequestControllerTest.php | 2 +- .../Account/SearchControllerTest.php | 8 +- .../Account/ViewControllerTest.php | 4 +- .../Account/ViewHistoryControllerTest.php | 4 +- .../Account/ViewLinkControllerTest.php | 2 +- .../Account/ViewPassControllerTest.php | 2 +- .../Account/ViewPassHistoryControllerTest.php | 2 +- .../AccountFile/AccountFileTest.php | 227 ++++++++++++++ .../SP/Stubs/ModelStub.php | 23 +- tests/SP/UnitaryTestCase.php | 8 +- 146 files changed, 2175 insertions(+), 1798 deletions(-) create mode 100644 lib/SP/Domain/Account/Dtos/FileDto.php create mode 100644 lib/SP/Domain/Common/Attributes/DtoTransformation.php create mode 100644 lib/SP/Domain/Common/Attributes/ModelBounded.php create mode 100644 lib/SP/Domain/Common/Ports/Dto.php delete mode 100644 lib/SP/Domain/User/Dtos/UserDataDto.php create mode 100644 lib/SP/Domain/User/Dtos/UserDto.php create mode 100644 tests/SP/Domain/Common/Models/ModelTest.php create mode 100644 tests/SP/Modules/Web/Controllers/AccountFile/AccountFileTest.php rename lib/SP/Domain/Account/Models/FileExtData.php => tests/SP/Stubs/ModelStub.php (72%) diff --git a/app/modules/web/Controllers/Account/SaveEditRestoreController.php b/app/modules/web/Controllers/Account/SaveEditRestoreController.php index 4c244c5a..7f294a41 100644 --- a/app/modules/web/Controllers/Account/SaveEditRestoreController.php +++ b/app/modules/web/Controllers/Account/SaveEditRestoreController.php @@ -29,7 +29,6 @@ use JsonException; use SP\Core\Application; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; -use SP\Domain\Account\Dtos\AccountHistoryDto; use SP\Domain\Account\Ports\AccountHistoryService; use SP\Domain\Account\Ports\AccountService; use SP\Domain\Core\Acl\AclActionsInterface; @@ -73,9 +72,7 @@ final class SaveEditRestoreController extends AccountControllerBase public function saveEditRestoreAction(int $historyId, int $id): bool { try { - $this->accountService->restoreModified( - AccountHistoryDto::fromAccount($this->accountHistoryService->getById($historyId)) - ); + $this->accountService->restoreModified($this->accountHistoryService->getById($historyId)); $accountDetails = $this->accountService->getByIdEnriched($id); diff --git a/app/modules/web/Controllers/Account/SaveRequestController.php b/app/modules/web/Controllers/Account/SaveRequestController.php index eb6f017c..6a5c33ed 100644 --- a/app/modules/web/Controllers/Account/SaveRequestController.php +++ b/app/modules/web/Controllers/Account/SaveRequestController.php @@ -96,7 +96,7 @@ final class SaveRequestController extends AccountControllerBase ->addDescription(__u('Request')) ->addDetail( __u('Requester'), - sprintf('%s (%s)', $this->userData->getName(), $this->userData->getLogin()) + sprintf('%s (%s)', $this->userDto->name, $this->userDto->login) ) ->addDetail(__u('Account'), $accountView->getName()) ->addDetail(__u('Client'), $accountView->getClientName()) @@ -106,7 +106,7 @@ final class SaveRequestController extends AccountControllerBase $deepLink->getUriSigned($this->configData->getPasswordSalt()) ) ->addExtra('accountId', $id) - ->addExtra('whoId', $this->userData->getId()) + ->addExtra('whoId', $this->userDto->id) ->setExtra('userId', $usersId) ->setExtra( 'email', diff --git a/app/modules/web/Controllers/Account/ViewHistoryController.php b/app/modules/web/Controllers/Account/ViewHistoryController.php index 39d5c720..2352b1be 100644 --- a/app/modules/web/Controllers/Account/ViewHistoryController.php +++ b/app/modules/web/Controllers/Account/ViewHistoryController.php @@ -65,12 +65,10 @@ final class ViewHistoryController extends AccountControllerBase try { $this->accountHistoryHelper->initializeFor(AclActionsInterface::ACCOUNT_HISTORY_VIEW); - $accountHistoryViewDto = AccountHistoryViewDto::fromArray( - $this->accountHistoryService->getById($id)->toArray(includeOuter: true) + $this->accountHistoryHelper->setViewForAccount( + AccountHistoryViewDto::fromArray($this->accountHistoryService->getById($id)->toArray()) ); - $this->accountHistoryHelper->setViewForAccount($accountHistoryViewDto); - $this->view->addTemplate('account-history'); $this->view->assign( diff --git a/app/modules/web/Controllers/Account/ViewLinkController.php b/app/modules/web/Controllers/Account/ViewLinkController.php index 0ddb22e8..d8b4225a 100644 --- a/app/modules/web/Controllers/Account/ViewLinkController.php +++ b/app/modules/web/Controllers/Account/ViewLinkController.php @@ -88,7 +88,9 @@ final class ViewLinkController extends AccountControllerBase $accountViewDto = AccountViewDto::fromModel( Serde::deserialize( - $vault->getData($this->publicLinkService->getPublicLinkKey($publicLink->getHash())->getKey()), + $vault->getData( + $this->publicLinkService->getPublicLinkKey($publicLink->getHash())->getKey() + ), Simple::class ) ); @@ -110,7 +112,7 @@ final class ViewLinkController extends AccountControllerBase if ($useImage) { $this->view->assign( 'accountPassImage', - $this->imageUtil->convertText($accountViewDto->getPass()) + $this->imageUtil->convertText($accountViewDto->pass) ); } else { $this->view->assign( diff --git a/app/modules/web/Controllers/AccountFavorite/AccountFavoriteBase.php b/app/modules/web/Controllers/AccountFavorite/AccountFavoriteBase.php index a5bcfb63..c8a99ff8 100644 --- a/app/modules/web/Controllers/AccountFavorite/AccountFavoriteBase.php +++ b/app/modules/web/Controllers/AccountFavorite/AccountFavoriteBase.php @@ -42,9 +42,9 @@ abstract class AccountFavoriteBase extends SimpleControllerBase * @throws SPException */ public function __construct( - Application $application, - SimpleControllerHelper $simpleControllerHelper, - protected AccountToFavoriteService $accountToFavoriteService + Application $application, + SimpleControllerHelper $simpleControllerHelper, + protected readonly AccountToFavoriteService $accountToFavoriteService ) { parent::__construct($application, $simpleControllerHelper); diff --git a/app/modules/web/Controllers/AccountFavorite/MarkController.php b/app/modules/web/Controllers/AccountFavorite/MarkController.php index d791a9bc..ba10075d 100644 --- a/app/modules/web/Controllers/AccountFavorite/MarkController.php +++ b/app/modules/web/Controllers/AccountFavorite/MarkController.php @@ -51,7 +51,7 @@ final class MarkController extends AccountFavoriteBase public function markAction(int $accountId): bool { try { - $this->accountToFavoriteService->add($accountId, $this->session->getUserData()->getId()); + $this->accountToFavoriteService->add($accountId, $this->session->getUserData()->id); return $this->returnJsonResponse(JsonMessage::JSON_SUCCESS, __u('Favorite added')); } catch (Exception $e) { diff --git a/app/modules/web/Controllers/AccountFavorite/UnmarkController.php b/app/modules/web/Controllers/AccountFavorite/UnmarkController.php index 4b191346..e127d64b 100644 --- a/app/modules/web/Controllers/AccountFavorite/UnmarkController.php +++ b/app/modules/web/Controllers/AccountFavorite/UnmarkController.php @@ -51,7 +51,7 @@ final class UnmarkController extends AccountFavoriteBase public function unmarkAction(int $accountId): bool { try { - $this->accountToFavoriteService->delete($accountId, $this->session->getUserData()->getId()); + $this->accountToFavoriteService->delete($accountId, $this->session->getUserData()->id); return $this->returnJsonResponse(JsonMessage::JSON_SUCCESS, __u('Favorite deleted')); } catch (Exception $e) { diff --git a/app/modules/web/Controllers/AccountFile/AccountFileBase.php b/app/modules/web/Controllers/AccountFile/AccountFileBase.php index 90528514..46fce048 100644 --- a/app/modules/web/Controllers/AccountFile/AccountFileBase.php +++ b/app/modules/web/Controllers/AccountFile/AccountFileBase.php @@ -24,25 +24,30 @@ namespace SP\Modules\Web\Controllers\AccountFile; - use SP\Core\Application; use SP\Domain\Account\Ports\AccountFileService; +use SP\Domain\Auth\Services\AuthException; +use SP\Domain\Core\Exceptions\SessionTimeout; use SP\Modules\Web\Controllers\ControllerBase; use SP\Mvc\Controller\WebControllerHelper; +/** + * Class AccountFileBase + */ abstract class AccountFileBase extends ControllerBase { - protected AccountFileService $accountFileService; + /** + * @throws AuthException + * @throws SessionTimeout + */ public function __construct( - Application $application, - WebControllerHelper $webControllerHelper, - AccountFileService $accountFileService + Application $application, + WebControllerHelper $webControllerHelper, + protected readonly AccountFileService $accountFileService ) { parent::__construct($application, $webControllerHelper); $this->checkLoggedIn(); - - $this->accountFileService = $accountFileService; } } diff --git a/app/modules/web/Controllers/AccountFile/DeleteController.php b/app/modules/web/Controllers/AccountFile/DeleteController.php index 4ebeabd4..a3996ee6 100644 --- a/app/modules/web/Controllers/AccountFile/DeleteController.php +++ b/app/modules/web/Controllers/AccountFile/DeleteController.php @@ -27,9 +27,13 @@ namespace SP\Modules\Web\Controllers\AccountFile; use Exception; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; +use SP\Domain\Core\Exceptions\SPException; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Mvc\Controller\ItemTrait; +use function SP\__u; +use function SP\processException; + /** * Class DeleteController * @@ -37,17 +41,18 @@ use SP\Mvc\Controller\ItemTrait; */ final class DeleteController extends AccountFileBase { - use JsonTrait, ItemTrait; + use ItemTrait; + use JsonTrait; /** * Delete action * - * @param int|null $id + * @param int|null $id * * @return bool - * @throws \JsonException + * @throws SPException */ - public function deleteAction(?int $id = null): bool + public function deleteAction(?int $id): bool { try { if ($id === null) { @@ -71,7 +76,7 @@ final class DeleteController extends AccountFileBase $this->accountFileService->delete($id); - return $this->returnJsonResponse(0, __u('File Deleted')); + return $this->returnJsonResponse(0, __u('File deleted')); } catch (Exception $e) { processException($e); diff --git a/app/modules/web/Controllers/AccountFile/DownloadController.php b/app/modules/web/Controllers/AccountFile/DownloadController.php index ddd52cc3..8267dbdd 100644 --- a/app/modules/web/Controllers/AccountFile/DownloadController.php +++ b/app/modules/web/Controllers/AccountFile/DownloadController.php @@ -27,9 +27,11 @@ namespace SP\Modules\Web\Controllers\AccountFile; use Exception; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; -use SP\Domain\Core\Exceptions\SPException; use SP\Modules\Web\Controllers\Traits\JsonTrait; +use function SP\__u; +use function SP\processException; + /** * Class DownloadController * @@ -38,20 +40,18 @@ use SP\Modules\Web\Controllers\Traits\JsonTrait; final class DownloadController extends AccountFileBase { use JsonTrait; - + /** * Download action * - * @param int $id + * @param int $id * * @return string */ public function downloadAction(int $id): string { try { - if (null === ($fileData = $this->accountFileService->getById($id))) { - throw new SPException(__u('File does not exist'), SPException::INFO); - } + $fileDto = $this->accountFileService->getById($id); $this->eventDispatcher->notify( 'download.accountFile', @@ -59,29 +59,29 @@ final class DownloadController extends AccountFileBase $this, EventMessage::factory() ->addDescription(__u('File downloaded')) - ->addDetail(__u('File'), $fileData->getName()) + ->addDetail(__u('File'), $fileDto->name) ) ); $response = $this->router->response(); - $response->header('Content-Length', $fileData->getSize()); - $response->header('Content-Type', $fileData->getType()); + $response->header('Content-Length', $fileDto->size); + $response->header('Content-Type', $fileDto->type); $response->header('Content-Description', ' sysPass file'); $response->header('Content-Transfer-Encoding', 'binary'); $response->header('Accept-Ranges', 'bytes'); - $type = strtolower($fileData->getType()); + $type = strtolower($fileDto->type); if ($type === 'application/pdf') { - $disposition = sprintf('inline; filename="%s"', $fileData->getName()); + $disposition = sprintf('inline; filename="%s"', $fileDto->name); } else { - $disposition = sprintf('attachment; filename="%s"', $fileData->getName()); + $disposition = sprintf('attachment; filename="%s"', $fileDto->name); $response->header('Set-Cookie', 'fileDownload=true; path=/'); } $response->header('Content-Disposition', $disposition); - $response->body($fileData->getContent()); + $response->body($fileDto->content); $response->send(true); } catch (Exception $e) { processException($e); diff --git a/app/modules/web/Controllers/AccountFile/ListController.php b/app/modules/web/Controllers/AccountFile/ListController.php index 8da41f91..7bd7cf51 100644 --- a/app/modules/web/Controllers/AccountFile/ListController.php +++ b/app/modules/web/Controllers/AccountFile/ListController.php @@ -25,11 +25,13 @@ namespace SP\Modules\Web\Controllers\AccountFile; use Exception; -use SP\Core\Acl\Acl; use SP\Core\Events\Event; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Modules\Web\Util\ErrorUtil; +use function SP\__; +use function SP\processException; + /** * Class ListController * @@ -40,7 +42,7 @@ final class ListController extends AccountFileBase /** * Obtener los datos para la vista de archivos de una cuenta * - * @param int $accountId Account's ID + * @param int $accountId Account's ID */ public function listAction(int $accountId): void { @@ -53,14 +55,18 @@ final class ListController extends AccountFileBase try { $this->view->addTemplate('files-list', 'account'); - $this->view->assign('deleteEnabled', $this->request->analyzeInt('del', false)); - $this->view->assign('files', $this->accountFileService->getByAccountId($accountId)); - $this->view->assign('fileViewRoute', Acl::getActionRoute(AclActionsInterface::ACCOUNT_FILE_VIEW)); - $this->view->assign('fileDownloadRoute', Acl::getActionRoute(AclActionsInterface::ACCOUNT_FILE_DOWNLOAD)); - $this->view->assign('fileDeleteRoute', Acl::getActionRoute(AclActionsInterface::ACCOUNT_FILE_DELETE)); + $files = $this->accountFileService->getByAccountId($accountId); - if (!is_array($this->view->files) - || count($this->view->files) === 0) { + $this->view->assign('deleteEnabled', $this->request->analyzeInt('del', false)); + $this->view->assign('files', $files); + $this->view->assign('fileViewRoute', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_FILE_VIEW)); + $this->view->assign( + 'fileDownloadRoute', + $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_FILE_DOWNLOAD) + ); + $this->view->assign('fileDeleteRoute', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_FILE_DELETE)); + + if (count($files) === 0) { $this->view->addTemplate('no_records_found', '_partials'); $this->view->assign('message', __('There are no linked files for the account')); diff --git a/app/modules/web/Controllers/AccountFile/SearchController.php b/app/modules/web/Controllers/AccountFile/SearchController.php index 962d24aa..992e1d91 100644 --- a/app/modules/web/Controllers/AccountFile/SearchController.php +++ b/app/modules/web/Controllers/AccountFile/SearchController.php @@ -27,9 +27,12 @@ namespace SP\Modules\Web\Controllers\AccountFile; use JsonException; use SP\Core\Application; use SP\Domain\Account\Ports\AccountFileService; +use SP\Domain\Auth\Services\AuthException; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; +use SP\Domain\Core\Exceptions\SessionTimeout; +use SP\Domain\Core\Exceptions\SPException; use SP\Domain\Http\Dtos\JsonMessage; use SP\Html\DataGrid\DataGridInterface; use SP\Modules\Web\Controllers\ControllerBase; @@ -38,6 +41,8 @@ use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Mvc\Controller\ItemTrait; use SP\Mvc\Controller\WebControllerHelper; +use function SP\__u; + /** * Class SearchController * @@ -48,21 +53,19 @@ final class SearchController extends ControllerBase use ItemTrait; use JsonTrait; - private AccountFileService $accountFileService; - private FileGrid $fileGrid; - + /** + * @throws AuthException + * @throws SessionTimeout + */ public function __construct( - Application $application, - WebControllerHelper $webControllerHelper, - FileGrid $fileGrid, - AccountFileService $accountFileService + Application $application, + WebControllerHelper $webControllerHelper, + private readonly FileGrid $fileGrid, + private readonly AccountFileService $accountFileService ) { parent::__construct($application, $webControllerHelper); $this->checkLoggedIn(); - - $this->fileGrid = $fileGrid; - $this->accountFileService = $accountFileService; } /** @@ -72,9 +75,11 @@ final class SearchController extends ControllerBase * @throws JsonException * @throws ConstraintException * @throws QueryException + * @throws SPException */ public function searchAction(): bool { + /** @noinspection DuplicatedCode */ if (!$this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_FILE_SEARCH)) { return $this->returnJsonResponse( JsonMessage::JSON_ERROR, @@ -95,6 +100,7 @@ final class SearchController extends ControllerBase * @return DataGridInterface * @throws ConstraintException * @throws QueryException + * @throws SPException */ protected function getSearchGrid(): DataGridInterface { diff --git a/app/modules/web/Controllers/AccountHistoryManager/SearchController.php b/app/modules/web/Controllers/AccountHistoryManager/SearchController.php index 037c0b47..52ba01e8 100644 --- a/app/modules/web/Controllers/AccountHistoryManager/SearchController.php +++ b/app/modules/web/Controllers/AccountHistoryManager/SearchController.php @@ -24,12 +24,12 @@ namespace SP\Modules\Web\Controllers\AccountHistoryManager; -use JsonException; use SP\Core\Application; use SP\Domain\Account\Ports\AccountHistoryService; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; +use SP\Domain\Core\Exceptions\SPException; use SP\Domain\Http\Dtos\JsonMessage; use SP\Html\DataGrid\DataGridInterface; use SP\Modules\Web\Controllers\ControllerBase; @@ -39,6 +39,8 @@ use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Mvc\Controller\ItemTrait; use SP\Mvc\Controller\WebControllerHelper; +use function SP\__u; + /** * Class SearchController * @@ -69,12 +71,13 @@ final class SearchController extends ControllerBase /** * @return bool - * @throws JsonException * @throws ConstraintException * @throws QueryException + * @throws SPException */ public function searchAction(): bool { + /** @noinspection DuplicatedCode */ if (!$this->acl->checkUserAccess(AclActionsInterface::ACCOUNTMGR_HISTORY_SEARCH)) { return $this->returnJsonResponse( JsonMessage::JSON_ERROR, diff --git a/app/modules/web/Controllers/ConfigManager/IndexController.php b/app/modules/web/Controllers/ConfigManager/IndexController.php index a97fa162..c962b1d6 100644 --- a/app/modules/web/Controllers/ConfigManager/IndexController.php +++ b/app/modules/web/Controllers/ConfigManager/IndexController.php @@ -215,12 +215,12 @@ final class IndexController extends ControllerBase $template->assign( 'isDemoMode', $this->configData->isDemoEnabled() - && !$this->userData->getIsAdminApp() + && !$this->userDto->getIsAdminApp() ); $template->assign( 'isDisabled', $this->configData->isDemoEnabled() - && !$this->userData->getIsAdminApp() ? 'disabled' : '' + && !$this->userDto->getIsAdminApp() ? 'disabled' : '' ); $template->assign( 'users', @@ -528,12 +528,12 @@ final class IndexController extends ControllerBase $template->assign( 'userGroups', SelectItemAdapter::factory($this->userGroupService->getAll()) - ->getItemsFromModelSelected([$this->userData->getUserGroupId()]) + ->getItemsFromModelSelected([$this->userDto->getUserGroupId()]) ); $template->assign( 'users', SelectItemAdapter::factory($this->userService->getAll()) - ->getItemsFromModelSelected([$this->userData->getId()]) + ->getItemsFromModelSelected([$this->userDto->getId()]) ); return new DataTab(__('Import Accounts'), $template); @@ -571,11 +571,11 @@ final class IndexController extends ControllerBase $template->assign( 'downloadConfigBackup', - !$isDemo && $this->userData->getIsAdminApp() + !$isDemo && $this->userDto->getIsAdminApp() ); $template->assign( 'downloadLog', - !$isDemo && is_readable($this->pathsContext[Path::LOG_FILE]) && $this->userData->getIsAdminApp() + !$isDemo && is_readable($this->pathsContext[Path::LOG_FILE]) && $this->userDto->getIsAdminApp() ); return new DataTab(__('Information'), $template); diff --git a/app/modules/web/Controllers/ControllerBase.php b/app/modules/web/Controllers/ControllerBase.php index 16d70f03..9bd186d0 100644 --- a/app/modules/web/Controllers/ControllerBase.php +++ b/app/modules/web/Controllers/ControllerBase.php @@ -42,7 +42,7 @@ use SP\Domain\Core\Exceptions\SPException; use SP\Domain\Core\PhpExtensionCheckerService; use SP\Domain\Core\UI\ThemeInterface; use SP\Domain\Http\Ports\RequestService; -use SP\Domain\User\Dtos\UserDataDto; +use SP\Domain\User\Dtos\UserDto; use SP\Domain\User\Models\ProfileData; use SP\Modules\Web\Controllers\Helpers\LayoutHelper; use SP\Modules\Web\Controllers\Traits\WebControllerTrait; @@ -72,7 +72,7 @@ abstract class ControllerBase protected readonly TemplateInterface $view; protected readonly LayoutHelper $layoutHelper; protected readonly UriContextInterface $uriContext; - protected ?UserDataDto $userData = null; + protected ?UserDto $userDto = null; protected ?ProfileData $userProfileData = null; protected readonly bool $isAjax; protected readonly string $actionName; @@ -104,7 +104,7 @@ abstract class ControllerBase $loggedIn = $this->session->isLoggedIn(); if ($loggedIn) { - $this->userData = clone $this->session->getUserData(); + $this->userDto = clone $this->session->getUserData(); $this->userProfileData = clone $this->session->getUserProfile(); } @@ -128,10 +128,10 @@ abstract class ControllerBase $this->view->assign('action', $this->actionName); if ($loggedIn) { - $this->view->assignWithScope('userId', $this->userData->getId(), 'ctx'); - $this->view->assignWithScope('userGroupId', $this->userData->getUserGroupId(), 'ctx'); - $this->view->assignWithScope('userIsAdminApp', $this->userData->getIsAdminApp(), 'ctx'); - $this->view->assignWithScope('userIsAdminAcc', $this->userData->getIsAdminAcc(), 'ctx'); + $this->view->assignWithScope('userId', $this->userDto->id, 'ctx'); + $this->view->assignWithScope('userGroupId', $this->userDto->userGroupId, 'ctx'); + $this->view->assignWithScope('userIsAdminApp', $this->userDto->isAdminApp, 'ctx'); + $this->view->assignWithScope('userIsAdminAcc', $this->userDto->isAdminAcc, 'ctx'); } } @@ -185,8 +185,8 @@ abstract class ControllerBase if ($this->session->isLoggedIn() && $this->session->getAuthCompleted() === $requireAuthCompleted && $this->configData->isAuthBasicEnabled() - && $this->browser->checkServerAuthUser($this->userData->getLogin()) === false - && $this->browser->checkServerAuthUser($this->userData->getSsoLogin()) === false + && $this->browser->checkServerAuthUser($this->userDto->login) === false + && $this->browser->checkServerAuthUser($this->userDto->ssoLogin) === false ) { throw new AuthException('Invalid browser auth'); } @@ -220,6 +220,6 @@ abstract class ControllerBase */ protected function checkAccess(int $action): bool { - return $this->userData->getIsAdminApp() || $this->acl->checkUserAccess($action); + return $this->userDto->isAdminApp || $this->acl->checkUserAccess($action); } } diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php index cbf2ab6f..e027eead 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php @@ -191,8 +191,8 @@ final class AccountHelper extends AccountHelperBase if ($this->configData->isPublinksEnabled() && $this->accountPermission->isShowLink()) { try { $publicLinkData = $this->publicLinkService->getHashForItem($this->accountId); - $accountActionsDto->setPublicLinkId($publicLinkData->getId()); - $accountActionsDto->setPublicLinkCreatorId($publicLinkData->getUserId()); + $accountActionsDto->setPublicLinkId($publicLinkData['id']); + $accountActionsDto->setPublicLinkCreatorId($publicLinkData['userId']); $baseUrl = ($this->configData->getApplicationUrl() ?: $this->uriContext->getWebUri()) . $this->uriContext->getSubUri(); @@ -201,10 +201,10 @@ final class AccountHelper extends AccountHelperBase 'publicLinkUrl', PublicLink::getLinkForHash( $baseUrl, - $publicLinkData->getHash() + $publicLinkData['hash'] ) ); - $this->view->assign('publicLinkId', $publicLinkData->getId()); + $this->view->assign('publicLinkId', $publicLinkData['id']); } catch (NoSuchItemException $e) { $this->view->assign('publicLinkId', 0); $this->view->assign('publicLinkUrl', null); @@ -221,15 +221,15 @@ final class AccountHelper extends AccountHelperBase $this->view->assign( 'allowPrivate', ($userProfileData->isAccPrivate() - && $accountData->getUserId() === $userData->getId()) - || $userData->getIsAdminApp() + && $accountData->getUserId() === $userData->id) + || $userData->isAdminApp ); $this->view->assign( 'allowPrivateGroup', ($userProfileData->isAccPrivateGroup() - && $accountData->getUserGroupId() === $userData->getUserGroupId()) - || $userData->getIsAdminApp() + && $accountData->getUserGroupId() === $userData->userGroupId) + || $userData->isAdminApp ); $this->view->assign( @@ -382,8 +382,8 @@ final class AccountHelper extends AccountHelperBase $userData = $this->context->getUserData(); $this->accountPermission->setShowPermission( - $userData->getIsAdminApp() - || $userData->getIsAdminAcc() + $userData->isAdminApp + || $userData->isAdminAcc || $userProfileData->isAccPermission() ); @@ -427,8 +427,8 @@ final class AccountHelper extends AccountHelperBase $this->view->assign('users', $selectUsers->getItemsFromModel()); $this->view->assign('userGroups', $selectUserGroups->getItemsFromModel()); $this->view->assign('tags', $selectTags->getItemsFromModel()); - $this->view->assign('allowPrivate', $userProfileData->isAccPrivate() || $userData->getIsAdminApp()); - $this->view->assign('allowPrivateGroup', $userProfileData->isAccPrivateGroup() || $userData->getIsAdminApp()); + $this->view->assign('allowPrivate', $userProfileData->isAccPrivate() || $userData->isAdminApp); + $this->view->assign('allowPrivateGroup', $userProfileData->isAccPrivateGroup() || $userData->isAdminApp); $this->view->assign('privateUserCheck', $accountPrivate->isPrivateUser()); $this->view->assign('privateUserGroupCheck', $accountPrivate->isPrivateGroup()); $this->view->assign('accountId', 0); diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHelperBase.php b/app/modules/web/Controllers/Helpers/Account/AccountHelperBase.php index 2d7e19ae..72c35e0d 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHelperBase.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHelperBase.php @@ -73,7 +73,7 @@ abstract class AccountHelperBase extends HelperBase throw UnauthorizedPageException::info($actionId); } - if (!$this->masterPassService->checkUserUpdateMPass($this->context->getUserData()->getLastUpdateMPass()) + if (!$this->masterPassService->checkUserUpdateMPass($this->context->getUserData()->lastUpdateMPass) ) { throw UpdatedMasterPassException::info(__u('The master password needs to be updated')); } diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php index 087e34fe..ef806651 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php @@ -28,25 +28,20 @@ use SP\Core\Application; use SP\Domain\Account\Adapters\AccountPermission; use SP\Domain\Account\Dtos\AccountAclDto; use SP\Domain\Account\Dtos\AccountHistoryViewDto; -use SP\Domain\Account\Models\AccountHistory; use SP\Domain\Account\Ports\AccountAclService; use SP\Domain\Account\Ports\AccountHistoryService; use SP\Domain\Account\Ports\AccountToUserGroupService; use SP\Domain\Account\Ports\AccountToUserService; use SP\Domain\Category\Ports\CategoryService; use SP\Domain\Client\Ports\ClientService; -use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Acl\AccountPermissionException; use SP\Domain\Core\Acl\AclInterface; use SP\Domain\Core\Acl\UnauthorizedActionException; -use SP\Domain\Core\Acl\UnauthorizedPageException; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\Crypt\Ports\MasterPassService; use SP\Domain\Http\Ports\RequestService; -use SP\Domain\User\Services\UpdatedMasterPassException; -use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Mvc\View\Components\SelectItemAdapter; use SP\Mvc\View\TemplateInterface; @@ -76,16 +71,13 @@ final class AccountHistoryHelper extends AccountHelperBase } /** - * @param AccountHistory $accountHistoryViewDto + * @param AccountHistoryViewDto $accountHistoryViewDto * * @throws AccountPermissionException - * @throws UnauthorizedPageException * @throws ConstraintException * @throws QueryException * @throws SPException - * @throws ServiceException - * @throws UpdatedMasterPassException - * @throws NoSuchItemException + * @throws UnauthorizedActionException */ public function setViewForAccount(AccountHistoryViewDto $accountHistoryViewDto): void { @@ -93,7 +85,7 @@ final class AccountHistoryHelper extends AccountHelperBase throw new UnauthorizedActionException(); } - $this->accountId = $accountHistoryViewDto->getAccountId(); + $this->accountId = $accountHistoryViewDto->accountId; $this->checkAccess($accountHistoryViewDto); @@ -108,30 +100,30 @@ final class AccountHistoryHelper extends AccountHelperBase 'historyData', SelectItemAdapter::factory( self::mapHistoryForDateSelect($this->accountHistoryService->getHistoryForAccount($this->accountId)) - )->getItemsFromArraySelected([$accountHistoryViewDto->getId()]) + )->getItemsFromArraySelected([$accountHistoryViewDto->id]) ); - $this->view->assign('accountPassDate', date('Y-m-d H:i:s', $accountHistoryViewDto->getPassDate())); + $this->view->assign('accountPassDate', date('Y-m-d H:i:s', $accountHistoryViewDto->passDate)); $this->view->assign( 'accountPassDateChange', - date('Y-m-d', $accountHistoryViewDto->getPassDateChange() ?: 0) + date('Y-m-d', $accountHistoryViewDto->passDateChange ?: 0) ); $this->view->assign( 'categories', SelectItemAdapter::factory($this->categoryService->getAll()) - ->getItemsFromModelSelected([$accountHistoryViewDto->getCategoryId()]) + ->getItemsFromModelSelected([$accountHistoryViewDto->categoryId]) ); $this->view->assign( 'clients', SelectItemAdapter::factory($this->clientService->getAll()) - ->getItemsFromModelSelected([$accountHistoryViewDto->getClientId()]) + ->getItemsFromModelSelected([$accountHistoryViewDto->clientId]) ); $this->view->assign( 'isModified', - strtotime($accountHistoryViewDto->getDateEdit()) !== false + strtotime($accountHistoryViewDto->dateEdit) !== false ); - $accountActionsDto = new AccountActionsDto($this->accountId, $accountHistoryViewDto->getId(), 0); + $accountActionsDto = new AccountActionsDto($this->accountId, $accountHistoryViewDto->id, 0); $this->view->assign( 'accountActions', @@ -144,10 +136,6 @@ final class AccountHistoryHelper extends AccountHelperBase } /** - * Comprobar si el usuario dispone de acceso al módulo - * - * @param AccountHistoryViewDto $accountHistoryViewDto - * * @throws AccountPermissionException * @throws ConstraintException * @throws QueryException @@ -157,11 +145,11 @@ final class AccountHistoryHelper extends AccountHelperBase { $acccountAclDto = new AccountAclDto( $this->accountId, - $accountHistoryViewDto->getUserId(), + $accountHistoryViewDto->userId, $this->accountToUserService->getUsersByAccountId($this->accountId), - $accountHistoryViewDto->getUserGroupId(), + $accountHistoryViewDto->userGroupId, $this->accountToUserGroupService->getUserGroupsByAccountId($this->accountId), - $accountHistoryViewDto->getDateEdit() + $accountHistoryViewDto->dateEdit ); $this->accountPermission = $this->accountAclService->getAcl($this->actionId, $acccountAclDto, true); diff --git a/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php index 8751aa3a..1ed1670d 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php @@ -129,7 +129,7 @@ final class AccountPasswordHelper extends HelperBase { $this->checkActionAccess(); - if (!$this->masterPassService->checkUserUpdateMPass($this->context->getUserData()->getLastUpdateMPass())) { + if (!$this->masterPassService->checkUserUpdateMPass($this->context->getUserData()->lastUpdateMPass)) { throw new HelperException( __('Master password updated') . '
' diff --git a/app/modules/web/Controllers/Helpers/Account/AccountSearchData.php b/app/modules/web/Controllers/Helpers/Account/AccountSearchData.php index 7102c168..9acaa541 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountSearchData.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountSearchData.php @@ -133,11 +133,11 @@ final class AccountSearchData public function buildFrom(QueryResult $queryResult): QueryResult { $maxTextLength = $this->configData->isResultsAsCards() ? self::TEXT_LENGTH_CARDS : self::TEXT_LENGTH_NORMAL; - $userPreferencesData = $this->context->getUserData()->getPreferences(); + $userPreferencesData = $this->context->getUserData()->preferences; $accountLinkEnabled = (null !== $userPreferencesData && $userPreferencesData->isAccountLink()) || $this->configData->isAccountLink(); - $favorites = $this->accountToFavoriteService->getForUserId($this->context->getUserData()->getId()); + $favorites = $this->accountToFavoriteService->getForUserId($this->context->getUserData()->id); return $queryResult->mutateWithCallback( function (AccountSearchView $accountSearchView) use ( diff --git a/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php index 2b811cf2..5fe15983 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php @@ -99,7 +99,7 @@ final class AccountSearchHelper extends HelperBase { $userData = $this->context->getUserData(); - $this->view->assign('isAdmin', $userData->getIsAdminApp() || $userData->getIsAdminAcc()); + $this->view->assign('isAdmin', $userData->isAdminApp || $userData->isAdminAcc); $profileData = $this->context->getUserProfile() ?? new ProfileData(); @@ -136,7 +136,7 @@ final class AccountSearchHelper extends HelperBase return $accountSearchFilter; } - $userPreferences = $this->context->getUserData()->getPreferences() ?? new UserPreferences(); + $userPreferences = $this->context->getUserData()->preferences ?? new UserPreferences(); $limitCount = $userPreferences->getResultsPerPage() > 0 ? $userPreferences->getResultsPerPage() : $this->configData->getAccountCount(); @@ -207,7 +207,7 @@ final class AccountSearchHelper extends HelperBase || $this->accountSearchFilter->isSearchFavorites() || $this->accountSearchFilter->isSortViews()); - $userPreferences = $this->context->getUserData()->getPreferences() ?? new UserPreferences(); + $userPreferences = $this->context->getUserData()->preferences ?? new UserPreferences(); AccountSearchItem::$accountLink = $userPreferences->isAccountLink(); AccountSearchItem::$topNavbar = $userPreferences->isTopNavbar(); @@ -283,7 +283,7 @@ final class AccountSearchHelper extends HelperBase $gridPager->setFilterOn($this->filterOn); $gridPager->setSourceAction(new DataGridActionSearch(AclActionsInterface::ACCOUNT_SEARCH)); - $userPreferences = $this->context->getUserData()->getPreferences() ?? new UserPreferences(); + $userPreferences = $this->context->getUserData()->preferences ?? new UserPreferences(); $showOptionalActions = $userPreferences->isOptionalActions() || $userPreferences->isResultsAsCards() || ($userPreferences->getUserId() === 0 diff --git a/app/modules/web/Controllers/Helpers/Grid/FileGrid.php b/app/modules/web/Controllers/Helpers/Grid/FileGrid.php index 659fbdc8..34688b72 100644 --- a/app/modules/web/Controllers/Helpers/Grid/FileGrid.php +++ b/app/modules/web/Controllers/Helpers/Grid/FileGrid.php @@ -24,7 +24,6 @@ namespace SP\Modules\Web\Controllers\Helpers\Grid; -use SP\Core\Acl\Acl; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\SPException; use SP\Html\DataGrid\Action\DataGridAction; @@ -52,6 +51,7 @@ final class FileGrid extends GridBase * @param QueryResult $queryResult * * @return DataGridInterface + * @throws SPException */ public function getGrid(QueryResult $queryResult): DataGridInterface { @@ -81,6 +81,9 @@ final class FileGrid extends GridBase return $grid; } + /** + * @throws SPException + */ protected function getGridLayout(): DataGridInterface { // Grid @@ -143,7 +146,7 @@ final class FileGrid extends GridBase $gridActionSearch->setOnSubmitFunction('appMgmt/search'); $gridActionSearch->addData( 'action-route', - Acl::getActionRoute(AclActionsInterface::ACCOUNT_FILE_SEARCH) + $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_FILE_SEARCH) ); return $gridActionSearch; @@ -161,7 +164,7 @@ final class FileGrid extends GridBase $gridAction->setFilterRowSource('type', 'application/pdf'); $gridAction->addData( 'action-route', - Acl::getActionRoute(AclActionsInterface::ACCOUNT_FILE_VIEW) + $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_FILE_VIEW) ); return $gridAction; @@ -178,7 +181,7 @@ final class FileGrid extends GridBase $gridAction->setOnClickFunction('file/download'); $gridAction->addData( 'action-route', - Acl::getActionRoute(AclActionsInterface::ACCOUNT_FILE_DOWNLOAD) + $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_FILE_DOWNLOAD) ); $gridAction->setRuntimeData( function ($dataItem) { @@ -200,7 +203,7 @@ final class FileGrid extends GridBase $gridAction->setOnClickFunction('appMgmt/delete'); $gridAction->addData( 'action-route', - Acl::getActionRoute(AclActionsInterface::ACCOUNT_FILE_DELETE) + $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_FILE_DELETE) ); return $gridAction; diff --git a/app/modules/web/Controllers/Helpers/LayoutHelper.php b/app/modules/web/Controllers/Helpers/LayoutHelper.php index 93baf1d1..459c2691 100644 --- a/app/modules/web/Controllers/Helpers/LayoutHelper.php +++ b/app/modules/web/Controllers/Helpers/LayoutHelper.php @@ -178,7 +178,7 @@ final class LayoutHelper extends HelperBase $this->view->append('jsLinks', $jsUriTheme->getUriSigned($this->configData->getPasswordSalt())); } - $userPreferences = $this->context->getUserData()->getPreferences(); + $userPreferences = $this->context->getUserData()->preferences; if ($this->loggedIn && $userPreferences @@ -237,20 +237,20 @@ final class LayoutHelper extends HelperBase { $userType = null; - $userData = $this->context->getUserData(); + $userDto = $this->context->getUserData(); $icons = $this->theme->getIcons(); - if ($userData->getIsAdminApp()) { + if ($userDto->isAdminApp) { $userType = $icons->appAdmin(); - } elseif ($userData->getIsAdminAcc()) { + } elseif ($userDto->isAdminAcc) { $userType = $icons->accAdmin(); } $this->view->assign('ctx_userType', $userType); - $this->view->assign('ctx_userLogin', mb_strtoupper($userData->getLogin())); - $this->view->assign('ctx_userName', $userData->getName() ?: mb_strtoupper($userData->getLogin())); - $this->view->assign('ctx_userGroup', $userData->getUserGroupName()); - $this->view->assign('showPassIcon', !($this->configData->isLdapEnabled() && $userData->getIsLdap())); + $this->view->assign('ctx_userLogin', mb_strtoupper($userDto->login)); + $this->view->assign('ctx_userName', $userDto->name ?: mb_strtoupper($userDto->login)); + $this->view->assign('ctx_userGroup', $userDto->userGroupName); + $this->view->assign('showPassIcon', !($this->configData->isLdapEnabled() && $userDto->isLdap)); } /** diff --git a/app/modules/web/Controllers/Notification/DeleteController.php b/app/modules/web/Controllers/Notification/DeleteController.php index c4197a77..f30e78e8 100644 --- a/app/modules/web/Controllers/Notification/DeleteController.php +++ b/app/modules/web/Controllers/Notification/DeleteController.php @@ -53,7 +53,7 @@ final class DeleteController extends NotificationSaveBase { try { if ($id === null) { - if ($this->userData->getIsAdminApp()) { + if ($this->userDto->getIsAdminApp()) { $this->notificationService->deleteAdminBatch($this->getItemsIdFromRequest($this->request)); } else { $this->notificationService->deleteByIdBatch($this->getItemsIdFromRequest($this->request)); @@ -67,7 +67,7 @@ final class DeleteController extends NotificationSaveBase return $this->returnJsonResponse(JsonMessage::JSON_SUCCESS, __u('Notifications deleted')); } - if ($this->userData->getIsAdminApp()) { + if ($this->userDto->getIsAdminApp()) { $this->notificationService->deleteAdmin($id); } else { $this->notificationService->delete($id); diff --git a/app/modules/web/Controllers/Notification/NotificationViewBase.php b/app/modules/web/Controllers/Notification/NotificationViewBase.php index 2f80de16..a6fbef07 100644 --- a/app/modules/web/Controllers/Notification/NotificationViewBase.php +++ b/app/modules/web/Controllers/Notification/NotificationViewBase.php @@ -79,7 +79,7 @@ abstract class NotificationViewBase extends ControllerBase $this->view->assign('notification', $notification); - if ($this->userData->getIsAdminApp()) { + if ($this->userDto->getIsAdminApp()) { $this->view->assign( 'users', SelectItemAdapter::factory($this->userService->getAll()) diff --git a/app/modules/web/Controllers/UserSettingsGeneral/SaveController.php b/app/modules/web/Controllers/UserSettingsGeneral/SaveController.php index 29fa9174..35af7401 100644 --- a/app/modules/web/Controllers/UserSettingsGeneral/SaveController.php +++ b/app/modules/web/Controllers/UserSettingsGeneral/SaveController.php @@ -29,7 +29,7 @@ use JsonException; use SP\Core\Application; use SP\Core\Events\Event; use SP\Domain\Http\Dtos\JsonMessage; -use SP\Domain\User\Dtos\UserDataDto; +use SP\Domain\User\Dtos\UserDto; use SP\Domain\User\Models\UserPreferences; use SP\Domain\User\Ports\UserService; use SP\Domain\User\Services\User; @@ -87,11 +87,11 @@ final class SaveController extends SimpleControllerBase } /** - * @param UserDataDto $userData + * @param UserDto $userData * * @return UserPreferences */ - private function getUserPreferencesData(UserDataDto $userData): UserPreferences + private function getUserPreferencesData(UserDto $userData): UserPreferences { $userPreferencesData = clone $userData->getPreferences(); diff --git a/app/modules/web/Forms/AccountForm.php b/app/modules/web/Forms/AccountForm.php index a0139681..874bf37a 100644 --- a/app/modules/web/Forms/AccountForm.php +++ b/app/modules/web/Forms/AccountForm.php @@ -30,6 +30,7 @@ use SP\Domain\Account\Dtos\AccountDto; use SP\Domain\Account\Dtos\AccountUpdateDto; use SP\Domain\Account\Ports\AccountPresetService; use SP\Domain\Core\Acl\AclActionsInterface; +use SP\Domain\Core\Exceptions\SPException; use SP\Domain\Core\Exceptions\ValidationException; use SP\Domain\Http\Ports\RequestService; use SP\Util\Chainable; @@ -41,18 +42,15 @@ use function SP\__u; */ final class AccountForm extends FormBase implements FormInterface { - private AccountPresetService $accountPresetService; private null|AccountCreateDto|AccountUpdateDto $accountDto = null; public function __construct( - Application $application, - RequestService $request, - AccountPresetService $accountPresetService, - ?int $itemId = null + Application $application, + RequestService $request, + private readonly AccountPresetService $accountPresetService, + ?int $itemId = null ) { parent::__construct($application, $request, $itemId); - - $this->accountPresetService = $accountPresetService; } /** @@ -71,39 +69,35 @@ final class AccountForm extends FormBase implements FormInterface $chain = new Chainable(fn() => $this->analyzeRequestData(), $this); - switch ($action) { - case AclActionsInterface::ACCOUNT_EDIT_PASS: - $this->accountDto = $chain->next(fn(AccountDto $dto) => $this->checkPassword($dto)) - ->next( - fn(AccountDto $dto) => $this->accountPresetService->checkPasswordPreset( - $dto - ) - ) - ->resolve(); - break; - case AclActionsInterface::ACCOUNT_EDIT: - $this->accountDto = $chain->next(fn(AccountDto $dto) => $this->analyzeItems($dto)) - ->next(fn(AccountDto $dto) => $this->checkCommon($dto)) - ->resolve(); - break; - case AclActionsInterface::ACCOUNT_CREATE: - case AclActionsInterface::ACCOUNT_COPY: - $this->accountDto = $chain->next(fn(AccountDto $dto) => $this->analyzeItems($dto)) - ->next(fn(AccountDto $dto) => $this->checkCommon($dto)) - ->next(fn(AccountDto $dto) => $this->checkPassword($dto)) - ->next( - fn(AccountDto $dto) => $this->accountPresetService->checkPasswordPreset( - $dto - ) - ) - ->resolve(); - break; - case AclActionsInterface::ACCOUNTMGR_BULK_EDIT: - $this->accountDto = $chain->next(fn(AccountDto $dto) => $this->analyzeItems($dto)) - ->next(fn(AccountDto $dto) => $this->analyzeBulkEdit($dto)) - ->resolve(); - break; - } + $this->accountDto = match ($action) { + AclActionsInterface::ACCOUNT_EDIT_PASS => + $chain->next(fn(AccountDto $dto) => $this->checkPassword($dto)) + ->next( + fn(AccountDto $dto) => $this->accountPresetService->checkPasswordPreset( + $dto + ) + ) + ->resolve(), + AclActionsInterface::ACCOUNT_EDIT => + $chain->next(fn(AccountDto $dto) => $this->analyzeItems($dto)) + ->next(fn(AccountDto $dto) => $this->checkCommon($dto)) + ->resolve(), + AclActionsInterface::ACCOUNT_CREATE, + AclActionsInterface::ACCOUNT_COPY => + $chain->next(fn(AccountDto $dto) => $this->analyzeItems($dto)) + ->next(fn(AccountDto $dto) => $this->checkCommon($dto)) + ->next(fn(AccountDto $dto) => $this->checkPassword($dto)) + ->next( + fn(AccountDto $dto) => $this->accountPresetService->checkPasswordPreset( + $dto + ) + ) + ->resolve(), + AclActionsInterface::ACCOUNTMGR_BULK_EDIT => + $chain->next(fn(AccountDto $dto) => $this->analyzeItems($dto)) + ->next(fn(AccountDto $dto) => $this->analyzeBulkEdit($dto)) + ->resolve() + }; return $this; } @@ -112,62 +106,29 @@ final class AccountForm extends FormBase implements FormInterface * Analizar los datos de la petición HTTP * * @return AccountCreateDto|AccountUpdateDto + * @throws SPException */ private function analyzeRequestData(): AccountCreateDto|AccountUpdateDto { - $name = $this->request->analyzeString('name'); - $login = $this->request->analyzeString('login'); - $clientId = $this->request->analyzeInt('client_id'); - $categoryId = $this->request->analyzeInt('category_id'); - $password = $this->request->analyzeEncrypted('password'); - $userId = $this->request->analyzeInt('owner_id'); - $url = $this->request->analyzeString('url'); - $notes = $this->request->analyzeUnsafeString('notes'); - $private = (int)$this->request->analyzeBool('private_enabled', false); - $privateGroup = (int)$this->request->analyzeBool('private_group_enabled', false); - $passDateChange = $this->request->analyzeInt('password_date_expire_unix'); - $parentId = $this->request->analyzeInt('parent_account_id'); - $userGroupId = $this->request->analyzeInt('main_usergroup_id'); + $properties = [ + 'name' => $this->request->analyzeString('name'), + 'login' => $this->request->analyzeString('login'), + 'clientId' => $this->request->analyzeInt('client_id'), + 'categoryId' => $this->request->analyzeInt('category_id'), + 'pass' => $this->request->analyzeEncrypted('password'), + 'userId' => $this->request->analyzeInt('owner_id', $this->context->getUserData()->id), + 'url' => $this->request->analyzeString('url'), + 'notes' => $this->request->analyzeUnsafeString('notes'), + 'private' => (int)$this->request->analyzeBool('private_enabled', false), + 'privateGroup' => (int)$this->request->analyzeBool('private_group_enabled', false), + 'passDateChange' => $this->request->analyzeInt('password_date_expire_unix'), + 'parentId' => $this->request->analyzeInt('parent_account_id'), + 'userGroupId' => $this->request->analyzeInt('main_usergroup_id'), + ]; - if (null === $this->itemId) { - $accountDto = new AccountCreateDto( - $name, - $login, - $clientId, - $categoryId, - $password, - $userId, - null, - $url, - $notes, - $this->context->getUserData()->getId(), - $private, - $privateGroup, - $passDateChange, - $parentId, - $userGroupId - ); - } else { - $accountDto = new AccountUpdateDto( - $name, - $login, - $clientId, - $categoryId, - $password, - $userId, - null, - $url, - $notes, - $this->context->getUserData()->getId(), - $private, - $privateGroup, - $passDateChange, - $parentId, - $userGroupId - ); - } - - return $accountDto; + return $this->itemId === null ? AccountCreateDto::fromArray($properties) : AccountUpdateDto::fromArray( + $properties + ); } /** @@ -175,21 +136,24 @@ final class AccountForm extends FormBase implements FormInterface */ private function checkPassword(AccountDto $accountDto): AccountDto { - if ($accountDto->getParentId() > 0) { + if ($accountDto->parentId > 0) { return $accountDto; } - if (!$accountDto->getPass()) { + if (!$accountDto->pass) { throw new ValidationException(__u('A key is needed')); } - if ($this->request->analyzeEncrypted('password_repeat') !== $accountDto->getPass()) { + if ($this->request->analyzeEncrypted('password_repeat') !== $accountDto->pass) { throw new ValidationException(__u('Passwords do not match')); } return $accountDto; } + /** + * @throws SPException + */ private function analyzeItems(AccountDto $accountDto): AccountDto { if ($this->request->analyzeInt('other_users_view_update') === 1) { @@ -222,21 +186,24 @@ final class AccountForm extends FormBase implements FormInterface */ private function checkCommon(AccountDto $accountDto): AccountDto { - if (!$accountDto->getName()) { + if (!$accountDto->name) { throw new ValidationException(__u('An account name needed')); } - if (!$accountDto->getClientId()) { + if (!$accountDto->clientId) { throw new ValidationException(__u('A client is needed')); } - if (!$accountDto->getCategoryId()) { + if (!$accountDto->categoryId) { throw new ValidationException(__u('A category is needed')); } return $accountDto; } + /** + * @throws SPException + */ private function analyzeBulkEdit(AccountDto $accountDto): AccountDto { if ($this->request->analyzeBool('clear_permission_users_view', false)) { diff --git a/app/modules/web/themes/material-blue/views/account/account-history.inc b/app/modules/web/themes/material-blue/views/account/account-history.inc index d8a65480..bb06e98c 100644 --- a/app/modules/web/themes/material-blue/views/account/account-history.inc +++ b/app/modules/web/themes/material-blue/views/account/account-history.inc @@ -25,6 +25,7 @@ use SP\Domain\Account\Adapters\AccountPermission; use SP\Domain\Account\Dtos\AccountHistoryViewDto; +use SP\Domain\Account\Dtos\AccountViewDto; use SP\Domain\Config\Ports\ConfigDataInterface; use SP\Domain\Core\UI\ThemeIconsInterface; use SP\Mvc\View\Components\SelectItem; @@ -34,7 +35,7 @@ use function SP\__; /** * @var callable $_getvar * @var ThemeIconsInterface $icons - * @var AccountHistoryViewDto $accountView + * @var AccountHistoryViewDto|AccountViewDto $accountView * @var AccountPermission $accountAcl * @var ConfigDataInterface $configData */ @@ -90,7 +91,7 @@ $accountAcl = $_getvar('accountAcl'); class="mdl-textfield__input mdl-color-text--indigo-400" maxlength="50" value="getName(), ENT_QUOTES); ?>" + echo htmlspecialchars($accountView->name, ENT_QUOTES); ?>" tabindex="1" readonly>