From a597d8ae6238091d22678ccca7fc6986e66a0998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D?= Date: Sat, 10 Dec 2022 12:07:38 +0100 Subject: [PATCH] chore: Create AccountService tests and rework models. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rubén D --- .phpstorm.meta.php | 25 +- .../Controllers/Account/CreateController.php | 2 +- .../Controllers/Account/DeleteController.php | 4 +- .../Controllers/Account/EditController.php | 2 +- .../Account/EditPassController.php | 2 +- .../Controllers/Account/ViewController.php | 14 +- .../Account/ViewPassController.php | 4 +- .../Controllers/Account/CopyController.php | 13 +- .../Controllers/Account/DeleteController.php | 10 +- .../Controllers/Account/EditController.php | 13 +- .../Account/EditPassController.php | 11 +- .../Account/RequestAccessController.php | 2 +- .../Account/SaveCopyController.php | 4 +- .../Account/SaveCreateController.php | 4 +- .../Account/SaveDeleteController.php | 2 +- .../Account/SaveEditController.php | 4 +- .../Account/SaveEditPassController.php | 2 +- .../Account/SaveEditRestoreController.php | 4 +- .../Account/SaveRequestController.php | 2 +- .../Controllers/Account/ViewController.php | 6 +- .../AccountFile/UploadController.php | 2 +- .../RestoreController.php | 4 +- .../AccountManager/DeleteController.php | 2 +- .../AccountManager/SaveBulkEditController.php | 23 +- .../Helpers/Account/AccountHelper.php | 4 +- .../Helpers/Account/AccountHistoryHelper.php | 10 +- .../Helpers/Account/AccountRequestHelper.php | 6 +- .../Controllers/Helpers/ItemPresetHelper.php | 12 +- .../ItemPreset/ItemPresetViewBase.php | 4 +- app/modules/web/Forms/AccountForm.php | 183 ++- app/modules/web/Forms/FormBase.php | 14 +- app/modules/web/Forms/FormInterface.php | 6 +- app/modules/web/Forms/ItemsPresetForm.php | 13 +- .../views/account/search-rows.inc | 2 +- .../views/itemshow/item_preset.inc | 4 +- lib/SP/Core/Acl/ActionsInterface.php | 312 ++-- lib/SP/DataModel/AccountExtData.php | 4 - lib/SP/DataModel/AccountSearchVData.php | 4 +- lib/SP/DataModel/AccountToUserGroupData.php | 4 +- lib/SP/DataModel/AccountVData.php | 4 +- lib/SP/DataModel/AuthTokenData.php | 4 +- lib/SP/DataModel/CategoryData.php | 4 +- lib/SP/DataModel/ClientData.php | 4 +- lib/SP/DataModel/CustomFieldBaseData.php | 4 +- lib/SP/DataModel/CustomFieldTypeData.php | 4 +- lib/SP/DataModel/EventlogData.php | 4 +- lib/SP/DataModel/FileData.php | 6 +- lib/SP/DataModel/ItemData.php | 4 +- .../DataModel/ItemPreset/AccountPrivate.php | 41 +- lib/SP/DataModel/PublicLinkData.php | 32 +- lib/SP/DataModel/TagData.php | 4 +- lib/SP/DataModel/TrackData.php | 4 +- lib/SP/DataModel/UserGroupData.php | 4 +- lib/SP/DataModel/UserPassData.php | 4 +- lib/SP/DataModel/UserPassRecoverData.php | 4 +- lib/SP/DataModel/UserProfileData.php | 4 +- lib/SP/DataModel/UserToUserGroupData.php | 4 +- .../Account/Adapters/AccountAdapter.php | 2 +- .../Domain/Account/Adapters/AccountData.php | 9 +- .../Account/Adapters/AccountPassData.php | 3 +- lib/SP/Domain/Account/Dtos/AccountAclDto.php | 19 +- .../Account/Dtos/AccountBulkRequest.php | 75 - .../Account/Dtos/AccountCreateDto.php} | 17 +- lib/SP/Domain/Account/Dtos/AccountDto.php | 281 ++++ .../Account/Dtos/AccountEnrichedDto.php | 86 +- .../Account/Dtos/AccountHistoryCreateDto.php | 8 +- .../Domain/Account/Dtos/AccountHistoryDto.php | 119 ++ .../Account/Dtos/AccountUpdateBulkDto.php | 52 + .../Domain/Account/Dtos/AccountUpdateDto.php | 33 + .../Domain/Account/Dtos/EncryptedPassword.php | 7 +- lib/SP/Domain/Account/Models/Account.php | 174 +++ .../Domain/Account/Models/AccountDataView.php | 218 +++ .../Domain/Account/Models/AccountHistory.php | 190 +++ .../Account/Models/AccountSearchView.php | 196 +++ .../Domain/Account/Models/AccountUseCases.php | 118 ++ .../Account/Models/ItemPreset.php} | 11 +- .../AccountHistoryRepositoryInterface.php | 6 +- .../Ports/AccountHistoryServiceInterface.php | 9 +- .../Ports/AccountItemsServiceInterface.php | 54 + .../Ports/AccountPresetServiceInterface.php | 11 +- .../Ports/AccountRepositoryInterface.php | 200 +-- .../Account/Ports/AccountServiceInterface.php | 158 +- .../Ports/AccountToTagRepositoryInterface.php | 10 +- .../AccountToUserGroupRepositoryInterface.php | 2 +- .../AccountToUserRepositoryInterface.php | 2 +- .../Search/AccountSearchDataBuilder.php | 26 +- .../Account/Services/AccountCryptService.php | 41 +- .../Account/Services/AccountFileService.php | 1 + .../Services/AccountHistoryService.php | 13 +- .../Account/Services/AccountItemsService.php | 177 +++ .../Account/Services/AccountPresetService.php | 65 +- .../Account/Services/AccountSearchItem.php | 44 +- .../Account/Services/AccountService.php | 750 +++++----- lib/SP/Domain/Common/Adapters/DataModel.php | 101 -- lib/SP/Domain/Common/Dtos/Dto.php | 69 + lib/SP/Domain/Common/Models/Model.php | 198 +++ .../Common/Models}/SerializedModel.php | 2 +- .../SimpleModel.php => Models/Simple.php} | 9 +- .../Common/Ports/RepositoryInterface.php | 5 +- .../Ports/ItemPresetServiceInterface.php | 10 +- .../ItemPreset/Services/ItemPresetRequest.php | 14 +- .../ItemPreset/Services/ItemPresetService.php | 10 +- .../Repositories/AccountHistoryRepository.php | 17 +- .../Repositories/AccountRepository.php | 497 +++--- .../Repositories/AccountToTagRepository.php | 10 +- .../AccountToUserGroupRepository.php | 2 +- .../Repositories/AccountToUserRepository.php | 2 +- .../Common/Repositories/Repository.php | 28 +- lib/SP/Infrastructure/Database/QueryData.php | 46 +- .../Infrastructure/Database/QueryResult.php | 35 +- .../Repositories/ItemPresetRepository.php | 14 +- .../Plugin/Repositories/PluginDataModel.php | 2 +- .../Plugin/Repositories/PluginModel.php | 4 +- lib/SP/Util/Chainable.php | 52 + lib/SP/Util/Util.php | 4 +- .../Account/Adapters/AccountAdapterTest.php | 10 +- .../Search/AccountSearchDataBuilderTest.php | 6 +- .../Services/AccountAclServiceTest.php | 18 +- .../Services/AccountCryptServiceTest.php | 146 +- .../Services/AccountFileServiceTest.php | 1 - .../Services/AccountHistoryServiceTest.php | 36 +- .../Services/AccountPresetServiceTest.php | 79 +- .../Account/Services/AccountServiceTest.php | 1330 +++++++++++++++++ tests/SP/Generators/AccountDataGenerator.php | 141 +- tests/SP/Generators/CustomFieldGenerator.php | 6 +- tests/SP/Generators/FileDataGenerator.php | 14 +- .../SP/Generators/ItemPresetDataGenerator.php | 16 +- .../AccountFileRepositoryTest.php | 10 +- .../AccountHistoryRepositoryTest.php | 97 +- .../Repositories/AccountRepositoryTest.php | 671 ++++----- .../AccountToFavoriteRepositoryTest.php | 4 +- .../AccountToTagRepositoryTest.php | 22 +- .../Repositories/PublicLinkRepositoryTest.php | 16 +- .../AccountHistoryRepositoryTest.php | 8 +- .../Repositories/ItemPresetRepositoryTest.php | 33 +- .../Account/AccountHistoryServiceTest.php | 6 +- .../Account/AccountSearchServiceTest.php | 12 +- .../Services/Account/AccountServiceTest.php | 56 +- tests/SP/Services/Import/CsvImportTest.php | 16 +- .../SP/Services/Import/SyspassImportTest.php | 24 +- .../ItemPreset/ItemPresetServiceTest.php | 34 +- tests/SP/Stubs/AccountRepositoryStub.php | 154 ++ tests/SP/UnitaryTestCase.php | 4 +- tests/SP/Util/ChainableTest.php | 51 + 144 files changed, 5804 insertions(+), 2417 deletions(-) delete mode 100644 lib/SP/Domain/Account/Dtos/AccountBulkRequest.php rename lib/SP/{DataModel/AccountHistoryData.php => Domain/Account/Dtos/AccountCreateDto.php} (71%) create mode 100644 lib/SP/Domain/Account/Dtos/AccountDto.php create mode 100644 lib/SP/Domain/Account/Dtos/AccountHistoryDto.php create mode 100644 lib/SP/Domain/Account/Dtos/AccountUpdateBulkDto.php create mode 100644 lib/SP/Domain/Account/Dtos/AccountUpdateDto.php create mode 100644 lib/SP/Domain/Account/Models/Account.php create mode 100644 lib/SP/Domain/Account/Models/AccountDataView.php create mode 100644 lib/SP/Domain/Account/Models/AccountHistory.php create mode 100644 lib/SP/Domain/Account/Models/AccountSearchView.php create mode 100644 lib/SP/Domain/Account/Models/AccountUseCases.php rename lib/SP/{DataModel/ItemPresetData.php => Domain/Account/Models/ItemPreset.php} (90%) create mode 100644 lib/SP/Domain/Account/Ports/AccountItemsServiceInterface.php create mode 100644 lib/SP/Domain/Account/Services/AccountItemsService.php delete mode 100644 lib/SP/Domain/Common/Adapters/DataModel.php create mode 100644 lib/SP/Domain/Common/Dtos/Dto.php create mode 100644 lib/SP/Domain/Common/Models/Model.php rename lib/SP/{DataModel => Domain/Common/Models}/SerializedModel.php (97%) rename lib/SP/Domain/Common/{Adapters/SimpleModel.php => Models/Simple.php} (82%) create mode 100644 lib/SP/Util/Chainable.php create mode 100644 tests/SP/Domain/Account/Services/AccountServiceTest.php create mode 100644 tests/SP/Stubs/AccountRepositoryStub.php create mode 100644 tests/SP/Util/ChainableTest.php diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php index eef24ddc..9111ee35 100644 --- a/.phpstorm.meta.php +++ b/.phpstorm.meta.php @@ -1,5 +1,28 @@ . + */ namespace PHPSTORM_META { override(\Psr\Container\ContainerInterface::get(0), type(0)); -} \ No newline at end of file + override(\SP\Infrastructure\Database\QueryResult::getData(0), type(0)); +} diff --git a/app/modules/api/Controllers/Account/CreateController.php b/app/modules/api/Controllers/Account/CreateController.php index 24359dbd..b537584b 100644 --- a/app/modules/api/Controllers/Account/CreateController.php +++ b/app/modules/api/Controllers/Account/CreateController.php @@ -51,7 +51,7 @@ final class CreateController extends AccountBase $accountId = $this->accountService->create($accountRequest); - $accountDetails = $this->accountService->getById($accountId)->getAccountVData(); + $accountDetails = $this->accountService->getByIdEnriched($accountId)->getAccountVData(); $this->eventDispatcher->notifyEvent( 'create.account', diff --git a/app/modules/api/Controllers/Account/DeleteController.php b/app/modules/api/Controllers/Account/DeleteController.php index feed5362..71fa367d 100644 --- a/app/modules/api/Controllers/Account/DeleteController.php +++ b/app/modules/api/Controllers/Account/DeleteController.php @@ -46,7 +46,7 @@ final class DeleteController extends AccountBase $id = $this->apiService->getParamInt('id', true); - $accountDetails = $this->accountService->getById($id)->getAccountVData(); + $accountDetails = $this->accountService->getByIdEnriched($id)->getAccountVData(); $this->accountService->delete($id); @@ -69,4 +69,4 @@ final class DeleteController extends AccountBase $this->returnResponseException($e); } } -} \ No newline at end of file +} diff --git a/app/modules/api/Controllers/Account/EditController.php b/app/modules/api/Controllers/Account/EditController.php index 8d743b32..e9e1dd8f 100644 --- a/app/modules/api/Controllers/Account/EditController.php +++ b/app/modules/api/Controllers/Account/EditController.php @@ -48,7 +48,7 @@ final class EditController extends AccountBase $this->accountService->update($accountRequest); - $accountDetails = $this->accountService->getById($accountRequest->id)->getAccountVData(); + $accountDetails = $this->accountService->getByIdEnriched($accountRequest->id)->getAccountVData(); $this->eventDispatcher->notifyEvent( 'edit.account', diff --git a/app/modules/api/Controllers/Account/EditPassController.php b/app/modules/api/Controllers/Account/EditPassController.php index 8162c4a4..8686a418 100644 --- a/app/modules/api/Controllers/Account/EditPassController.php +++ b/app/modules/api/Controllers/Account/EditPassController.php @@ -50,7 +50,7 @@ final class EditPassController extends AccountBase $this->accountService->editPassword($accountRequest); - $accountDetails = $this->accountService->getById($accountRequest->id)->getAccountVData(); + $accountDetails = $this->accountService->getByIdEnriched($accountRequest->id)->getAccountVData(); $this->eventDispatcher->notifyEvent( 'edit.account.pass', diff --git a/app/modules/api/Controllers/Account/ViewController.php b/app/modules/api/Controllers/Account/ViewController.php index ebcfd27d..4f42b22d 100644 --- a/app/modules/api/Controllers/Account/ViewController.php +++ b/app/modules/api/Controllers/Account/ViewController.php @@ -55,16 +55,14 @@ final class ViewController extends AccountBase $this->apiService->requireMasterPass(); } - $accountDetails = $this->accountService->getById($id)->getAccountVData(); + $accountDetails = $this->accountService->getByIdEnriched($id)->getAccountVData(); $this->accountService->incrementViewCounter($id); - $accountResponse = new AccountEnrichedDto($accountDetails); - - $this->accountService - ->withUsersById($accountResponse) - ->withUserGroupsById($accountResponse) - ->withTagsById($accountResponse); + $accountEnrichedDto = new AccountEnrichedDto($accountDetails); + $accountEnrichedDto = $this->accountService->withUsers($accountEnrichedDto); + $accountEnrichedDto = $this->accountService->withUserGroups($accountEnrichedDto); + $accountEnrichedDto = $this->accountService->withTags($accountEnrichedDto); $this->eventDispatcher->notifyEvent( 'show.account', @@ -78,7 +76,7 @@ final class ViewController extends AccountBase ) ); - $out = $this->fractal->createData(new Item($accountResponse, $this->accountAdapter)); + $out = $this->fractal->createData(new Item($accountEnrichedDto, $this->accountAdapter)); if ($customFields) { $this->fractal->parseIncludes(['customFields']); diff --git a/app/modules/api/Controllers/Account/ViewPassController.php b/app/modules/api/Controllers/Account/ViewPassController.php index 411cfa4d..d1251a0e 100644 --- a/app/modules/api/Controllers/Account/ViewPassController.php +++ b/app/modules/api/Controllers/Account/ViewPassController.php @@ -55,7 +55,7 @@ final class ViewPassController extends AccountBase $this->accountService->incrementDecryptCounter($id); - $accountDetails = $this->accountService->getById($id)->getAccountVData(); + $accountDetails = $this->accountService->getByIdEnriched($id)->getAccountVData(); $this->eventDispatcher->notifyEvent( 'show.account.pass', @@ -76,4 +76,4 @@ final class ViewPassController extends AccountBase $this->returnResponseException($e); } } -} \ No newline at end of file +} diff --git a/app/modules/web/Controllers/Account/CopyController.php b/app/modules/web/Controllers/Account/CopyController.php index 2d2ee5fb..2a810270 100644 --- a/app/modules/web/Controllers/Account/CopyController.php +++ b/app/modules/web/Controllers/Account/CopyController.php @@ -42,13 +42,12 @@ final class CopyController extends AccountViewBase public function copyAction(int $id): void { try { - $accountDetailsResponse = $this->accountService->getById($id); - $this->accountService - ->withUsersById($accountDetailsResponse) - ->withUserGroupsById($accountDetailsResponse) - ->withTagsById($accountDetailsResponse); + $accountEnrichedDto = $this->accountService->getByIdEnriched($id); + $accountEnrichedDto = $this->accountService->withUsers($accountEnrichedDto); + $accountEnrichedDto = $this->accountService->withUserGroups($accountEnrichedDto); + $accountEnrichedDto = $this->accountService->withTags($accountEnrichedDto); - $this->accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_COPY); + $this->accountHelper->setViewForAccount($accountEnrichedDto, ActionsInterface::ACCOUNT_COPY); $this->view->addTemplate('account'); $this->view->assign( @@ -80,4 +79,4 @@ final class CopyController extends AccountViewBase ErrorUtil::showExceptionInView($this->view, $e, 'account'); } } -} \ No newline at end of file +} diff --git a/app/modules/web/Controllers/Account/DeleteController.php b/app/modules/web/Controllers/Account/DeleteController.php index 9bddbc76..07c16b13 100644 --- a/app/modules/web/Controllers/Account/DeleteController.php +++ b/app/modules/web/Controllers/Account/DeleteController.php @@ -67,12 +67,12 @@ final class DeleteController extends AccountControllerBase public function deleteAction(?int $id = null): void { try { - $accountDetailsResponse = $this->accountService->getById($id); - $this->accountService - ->withUsersById($accountDetailsResponse) - ->withUserGroupsById($accountDetailsResponse); + $accountEnrichedDto = $this->accountService->getByIdEnriched($id); + $accountEnrichedDto = $this->accountService->withUsers($accountEnrichedDto); + $accountEnrichedDto = $this->accountService->withUserGroups($accountEnrichedDto); + $accountEnrichedDto = $this->accountService->withTags($accountEnrichedDto); - $this->accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_DELETE); + $this->accountHelper->setViewForAccount($accountEnrichedDto, ActionsInterface::ACCOUNT_DELETE); $this->view->addTemplate('account'); $this->view->assign( diff --git a/app/modules/web/Controllers/Account/EditController.php b/app/modules/web/Controllers/Account/EditController.php index a03d3946..29fce6a2 100644 --- a/app/modules/web/Controllers/Account/EditController.php +++ b/app/modules/web/Controllers/Account/EditController.php @@ -43,13 +43,12 @@ final class EditController extends AccountViewBase public function editAction(int $id): void { try { - $accountDetailsResponse = $this->accountService->getById($id); - $this->accountService - ->withUsersById($accountDetailsResponse) - ->withUserGroupsById($accountDetailsResponse) - ->withTagsById($accountDetailsResponse); + $accountEnrichedDto = $this->accountService->getByIdEnriched($id); + $accountEnrichedDto = $this->accountService->withUsers($accountEnrichedDto); + $accountEnrichedDto = $this->accountService->withUserGroups($accountEnrichedDto); + $accountEnrichedDto = $this->accountService->withTags($accountEnrichedDto); - $this->accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_EDIT); + $this->accountHelper->setViewForAccount($accountEnrichedDto, ActionsInterface::ACCOUNT_EDIT); $this->view->addTemplate('account'); $this->view->assign( @@ -83,4 +82,4 @@ final class EditController extends AccountViewBase ErrorUtil::showExceptionInView($this->view, $e, 'account'); } } -} \ No newline at end of file +} diff --git a/app/modules/web/Controllers/Account/EditPassController.php b/app/modules/web/Controllers/Account/EditPassController.php index c5b44dae..52883218 100644 --- a/app/modules/web/Controllers/Account/EditPassController.php +++ b/app/modules/web/Controllers/Account/EditPassController.php @@ -47,12 +47,11 @@ final class EditPassController extends AccountViewBase public function editPassAction(int $id): void { try { - $accountDetailsResponse = $this->accountService->getById($id); - $this->accountService - ->withUsersById($accountDetailsResponse) - ->withUserGroupsById($accountDetailsResponse); + $accountEnrichedDto = $this->accountService->getByIdEnriched($id); + $accountEnrichedDto = $this->accountService->withUsers($accountEnrichedDto); + $accountEnrichedDto = $this->accountService->withUserGroups($accountEnrichedDto); - $this->accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_EDIT_PASS); + $this->accountHelper->setViewForAccount($accountEnrichedDto, ActionsInterface::ACCOUNT_EDIT_PASS); $this->view->addTemplate('account-editpass'); $this->view->assign( @@ -84,4 +83,4 @@ final class EditPassController extends AccountViewBase ErrorUtil::showExceptionInView($this->view, $e, 'account-editpass'); } } -} \ No newline at end of file +} diff --git a/app/modules/web/Controllers/Account/RequestAccessController.php b/app/modules/web/Controllers/Account/RequestAccessController.php index d38b8fef..17d3e40a 100644 --- a/app/modules/web/Controllers/Account/RequestAccessController.php +++ b/app/modules/web/Controllers/Account/RequestAccessController.php @@ -65,7 +65,7 @@ final class RequestAccessController extends ControllerBase try { $this->accountRequestHelper->setIsView(true); $this->accountRequestHelper->setViewForRequest( - $this->accountService->getById($id), + $this->accountService->getByIdEnriched($id), ActionsInterface::ACCOUNT_REQUEST ); diff --git a/app/modules/web/Controllers/Account/SaveCopyController.php b/app/modules/web/Controllers/Account/SaveCopyController.php index 19684012..7d3e11f2 100644 --- a/app/modules/web/Controllers/Account/SaveCopyController.php +++ b/app/modules/web/Controllers/Account/SaveCopyController.php @@ -48,7 +48,7 @@ final class SaveCopyController extends AccountSaveBase $accountId = $this->accountService->create($this->accountForm->getItemData()); - $accountDetails = $this->accountService->getById($accountId)->getAccountVData(); + $accountDetails = $this->accountService->getByIdEnriched($accountId)->getAccountVData(); $this->eventDispatcher->notifyEvent( 'create.account', @@ -85,4 +85,4 @@ final class SaveCopyController extends AccountSaveBase return $this->returnJsonResponseException($e); } } -} \ No newline at end of file +} diff --git a/app/modules/web/Controllers/Account/SaveCreateController.php b/app/modules/web/Controllers/Account/SaveCreateController.php index a89cf096..ae4866a3 100644 --- a/app/modules/web/Controllers/Account/SaveCreateController.php +++ b/app/modules/web/Controllers/Account/SaveCreateController.php @@ -48,7 +48,7 @@ final class SaveCreateController extends AccountSaveBase $accountId = $this->accountService->create($this->accountForm->getItemData()); - $accountDetails = $this->accountService->getById($accountId)->getAccountVData(); + $accountDetails = $this->accountService->getByIdEnriched($accountId)->getAccountVData(); $this->eventDispatcher->notifyEvent( 'create.account', @@ -85,4 +85,4 @@ final class SaveCreateController extends AccountSaveBase return $this->returnJsonResponseException($e); } } -} \ No newline at end of file +} diff --git a/app/modules/web/Controllers/Account/SaveDeleteController.php b/app/modules/web/Controllers/Account/SaveDeleteController.php index ae6cd889..bc5a928f 100644 --- a/app/modules/web/Controllers/Account/SaveDeleteController.php +++ b/app/modules/web/Controllers/Account/SaveDeleteController.php @@ -72,7 +72,7 @@ final class SaveDeleteController extends AccountControllerBase public function saveDeleteAction(int $id): bool { try { - $accountDetails = $this->accountService->getById($id)->getAccountVData(); + $accountDetails = $this->accountService->getByIdEnriched($id)->getAccountVData(); $this->accountService->delete($id); diff --git a/app/modules/web/Controllers/Account/SaveEditController.php b/app/modules/web/Controllers/Account/SaveEditController.php index a017487f..23827638 100644 --- a/app/modules/web/Controllers/Account/SaveEditController.php +++ b/app/modules/web/Controllers/Account/SaveEditController.php @@ -55,7 +55,7 @@ final class SaveEditController extends AccountSaveBase $this->accountService->update($itemData); - $accountDetails = $this->accountService->getById($id)->getAccountVData(); + $accountDetails = $this->accountService->getByIdEnriched($id)->getAccountVData(); $this->eventDispatcher->notifyEvent( 'edit.account', @@ -92,4 +92,4 @@ final class SaveEditController extends AccountSaveBase return $this->returnJsonResponseException($e); } } -} \ No newline at end of file +} diff --git a/app/modules/web/Controllers/Account/SaveEditPassController.php b/app/modules/web/Controllers/Account/SaveEditPassController.php index 140ef194..1a09cf46 100644 --- a/app/modules/web/Controllers/Account/SaveEditPassController.php +++ b/app/modules/web/Controllers/Account/SaveEditPassController.php @@ -77,7 +77,7 @@ final class SaveEditPassController extends AccountControllerBase $this->accountService->editPassword($this->accountForm->getItemData()); - $accountDetails = $this->accountService->getById($id)->getAccountVData(); + $accountDetails = $this->accountService->getByIdEnriched($id)->getAccountVData(); $this->eventDispatcher->notifyEvent( 'edit.account.pass', diff --git a/app/modules/web/Controllers/Account/SaveEditRestoreController.php b/app/modules/web/Controllers/Account/SaveEditRestoreController.php index 4c3fe4a7..eac8a894 100644 --- a/app/modules/web/Controllers/Account/SaveEditRestoreController.php +++ b/app/modules/web/Controllers/Account/SaveEditRestoreController.php @@ -70,9 +70,9 @@ final class SaveEditRestoreController extends AccountControllerBase public function saveEditRestoreAction(int $historyId, int $id): bool { try { - $this->accountService->editRestore($historyId, $id); + $this->accountService->restoreModified($historyId, $id); - $accountDetails = $this->accountService->getById($id)->getAccountVData(); + $accountDetails = $this->accountService->getByIdEnriched($id)->getAccountVData(); $this->eventDispatcher->notifyEvent( 'edit.account.restore', diff --git a/app/modules/web/Controllers/Account/SaveRequestController.php b/app/modules/web/Controllers/Account/SaveRequestController.php index 8e4b523f..d2f07bb5 100644 --- a/app/modules/web/Controllers/Account/SaveRequestController.php +++ b/app/modules/web/Controllers/Account/SaveRequestController.php @@ -83,7 +83,7 @@ final class SaveRequestController extends AccountControllerBase throw new ValidationException(__u('A description is needed')); } - $accountDetails = $this->accountService->getById($id)->getAccountVData(); + $accountDetails = $this->accountService->getByIdEnriched($id)->getAccountVData(); $baseUrl = ($this->configData->getApplicationUrl() ?: BootstrapBase::$WEBURI).BootstrapBase::$SUBURI; diff --git a/app/modules/web/Controllers/Account/ViewController.php b/app/modules/web/Controllers/Account/ViewController.php index c7469c49..2518d5a0 100644 --- a/app/modules/web/Controllers/Account/ViewController.php +++ b/app/modules/web/Controllers/Account/ViewController.php @@ -46,9 +46,9 @@ final class ViewController extends AccountViewBase try { $this->view->addTemplate('account'); - $accountDetailsResponse = $this->accountService->getById($id); + $accountDetailsResponse = $this->accountService->getByIdEnriched($id); $this->accountService - ->withUsersById($accountDetailsResponse) + ->withUsers($accountDetailsResponse) ->withUserGroupsById($accountDetailsResponse) ->withTagsById($accountDetailsResponse); @@ -85,4 +85,4 @@ final class ViewController extends AccountViewBase ErrorUtil::showExceptionInView($this->view, $e, 'account'); } } -} \ No newline at end of file +} diff --git a/app/modules/web/Controllers/AccountFile/UploadController.php b/app/modules/web/Controllers/AccountFile/UploadController.php index 218ae986..a4ac6126 100644 --- a/app/modules/web/Controllers/AccountFile/UploadController.php +++ b/app/modules/web/Controllers/AccountFile/UploadController.php @@ -128,7 +128,7 @@ final class UploadController extends ControllerBase $this->accountFileService->create($fileData); - $account = $this->accountService->getById($accountId)->getAccountVData(); + $account = $this->accountService->getByIdEnriched($accountId)->getAccountVData(); $this->eventDispatcher->notifyEvent( 'upload.accountFile', diff --git a/app/modules/web/Controllers/AccountHistoryManager/RestoreController.php b/app/modules/web/Controllers/AccountHistoryManager/RestoreController.php index 426bb761..84ddf361 100644 --- a/app/modules/web/Controllers/AccountHistoryManager/RestoreController.php +++ b/app/modules/web/Controllers/AccountHistoryManager/RestoreController.php @@ -76,9 +76,9 @@ final class RestoreController extends ControllerBase $accountDetails = $this->accountHistoryService->getById($id); if ($accountDetails->isModify) { - $this->accountService->editRestore($id, $accountDetails->getAccountId()); + $this->accountService->restoreModified($id, $accountDetails->getAccountId()); } else { - $this->accountService->createFromHistory($accountDetails); + $this->accountService->restoreRemoved($accountDetails); } $this->eventDispatcher->notifyEvent( diff --git a/app/modules/web/Controllers/AccountManager/DeleteController.php b/app/modules/web/Controllers/AccountManager/DeleteController.php index 6a42c206..7f4770b5 100644 --- a/app/modules/web/Controllers/AccountManager/DeleteController.php +++ b/app/modules/web/Controllers/AccountManager/DeleteController.php @@ -87,7 +87,7 @@ final class DeleteController extends ControllerBase return $this->returnJsonResponseData(JsonResponse::JSON_SUCCESS, __u('Accounts removed')); } - $accountDetails = $this->accountService->getById($id)->getAccountVData(); + $accountDetails = $this->accountService->getByIdEnriched($id)->getAccountVData(); $this->accountService->delete($id); diff --git a/app/modules/web/Controllers/AccountManager/SaveBulkEditController.php b/app/modules/web/Controllers/AccountManager/SaveBulkEditController.php index a06d9dda..c0eeba8d 100644 --- a/app/modules/web/Controllers/AccountManager/SaveBulkEditController.php +++ b/app/modules/web/Controllers/AccountManager/SaveBulkEditController.php @@ -29,7 +29,7 @@ use SP\Core\Acl\ActionsInterface; use SP\Core\Application; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; -use SP\Domain\Account\Dtos\AccountBulkRequest; +use SP\Domain\Account\Dtos\AccountUpdateBulkDto; use SP\Domain\Account\Ports\AccountHistoryServiceInterface; use SP\Domain\Account\Ports\AccountPresetServiceInterface; use SP\Domain\Account\Ports\AccountServiceInterface; @@ -40,6 +40,7 @@ use SP\Modules\Web\Forms\AccountForm; use SP\Mvc\Controller\ItemTrait; use SP\Mvc\Controller\WebControllerHelper; use SP\Util\Util; +use function SP\processException; /** * Class AccountManagerController @@ -74,24 +75,26 @@ final class SaveBulkEditController extends ControllerBase * saveBulkEditAction * * @return bool - * @throws \JsonException + * @throws \SP\Core\Exceptions\SPException */ public function saveBulkEditAction(): bool { try { - $this->accountForm->validateFor(ActionsInterface::ACCOUNTMGR_BULK_EDIT, null); + $itemsId = Util::itemsIdAdapter($this->request->analyzeString('itemsId')); - $request = new AccountBulkRequest( - Util::itemsIdAdapter($this->request->analyzeString('itemsId')), - $this->accountForm->getItemData() + $accountBulkDto = new AccountUpdateBulkDto( + array_map(function ($itemId) { + $this->accountForm->validateFor(ActionsInterface::ACCOUNTMGR_BULK_EDIT, $itemId); + + return $this->accountForm->getItemData(); + }, $itemsId) ); - $request->setDeleteHistory($this->request->analyzeBool('delete_history', false)); - if ($request->isDeleteHistory()) { - $this->accountHistoryService->deleteByAccountIdBatch($request->getItemsId()); + if ($this->request->analyzeBool('delete_history', false)) { + $this->accountHistoryService->deleteByAccountIdBatch($itemsId); } - $this->accountService->updateBulk($request); + $this->accountService->updateBulk($accountBulkDto); $this->eventDispatcher->notifyEvent( 'edit.account.bulk', diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php index 1740ac69..b1a4a111 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php @@ -140,14 +140,14 @@ final class AccountHelper extends AccountHelperBase AccountEnrichedDto $accountDetailsResponse, int $actionId ): void { - $this->accountId = $accountDetailsResponse->getAccountVData()->getId(); + $this->accountId = $accountDetailsResponse->getAccountDataView()->getId(); $this->actionId = $actionId; $this->checkActionAccess(); $this->accountAcl = $this->checkAccess($accountDetailsResponse); - $accountData = $accountDetailsResponse->getAccountVData(); + $accountData = $accountDetailsResponse->getAccountDataView(); $accountActionsDto = new AccountActionsDto($this->accountId, null, $accountData->getParentId()); diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php index 30bd6a20..1f472d70 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php @@ -28,8 +28,8 @@ use SP\Core\Acl\AccountPermissionException; use SP\Core\Acl\Acl; use SP\Core\Application; use SP\Core\Exceptions\SPException; -use SP\DataModel\AccountHistoryData; use SP\Domain\Account\Dtos\AccountAclDto; +use SP\Domain\Account\Models\AccountHistory; use SP\Domain\Account\Ports\AccountAclServiceInterface; use SP\Domain\Account\Ports\AccountHistoryServiceInterface; use SP\Domain\Account\Ports\AccountToUserGroupServiceInterface; @@ -70,7 +70,7 @@ final class AccountHistoryHelper extends AccountHelperBase } /** - * @param AccountHistoryData $accountHistoryData + * @param \SP\Domain\Account\Models\AccountHistory $accountHistoryData * @param int $actionId * * @throws \SP\Core\Acl\AccountPermissionException @@ -82,7 +82,7 @@ final class AccountHistoryHelper extends AccountHelperBase * @throws \SP\Domain\User\Services\UpdatedMasterPassException * @throws \SP\Infrastructure\Common\Repositories\NoSuchItemException */ - public function setView(AccountHistoryData $accountHistoryData, int $actionId): void + public function setView(AccountHistory $accountHistoryData, int $actionId): void { $this->actionId = $actionId; $this->accountId = $accountHistoryData->getAccountId(); @@ -142,14 +142,14 @@ final class AccountHistoryHelper extends AccountHelperBase /** * Comprobar si el usuario dispone de acceso al módulo * - * @param AccountHistoryData $accountHistoryData + * @param AccountHistory $accountHistoryData * * @throws \SP\Core\Acl\AccountPermissionException * @throws \SP\Core\Exceptions\ConstraintException * @throws \SP\Core\Exceptions\QueryException * @throws \SP\Core\Exceptions\SPException */ - protected function checkAccess(AccountHistoryData $accountHistoryData): void + protected function checkAccess(AccountHistory $accountHistoryData): void { $acccountAclDto = AccountAclDto::makeFromAccountHistory( $accountHistoryData, diff --git a/app/modules/web/Controllers/Helpers/Account/AccountRequestHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountRequestHelper.php index fd885437..bef063ad 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountRequestHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountRequestHelper.php @@ -49,16 +49,16 @@ final class AccountRequestHelper extends AccountHelperBase AccountEnrichedDto $accountDetailsResponse, int $actionId ): bool { - $this->accountId = $accountDetailsResponse->getAccountVData()->getId(); + $this->accountId = $accountDetailsResponse->getAccountDataView()->getId(); $this->actionId = $actionId; $this->accountAcl = new AccountAcl($actionId); $this->checkActionAccess(); - $accountData = $accountDetailsResponse->getAccountVData(); + $accountData = $accountDetailsResponse->getAccountDataView(); $this->view->assign('accountId', $accountData->getId()); - $this->view->assign('accountData', $accountDetailsResponse->getAccountVData()); + $this->view->assign('accountData', $accountDetailsResponse->getAccountDataView()); $this->view->assign( 'accountActions', $this->accountActionsHelper->getActionsForAccount( diff --git a/app/modules/web/Controllers/Helpers/ItemPresetHelper.php b/app/modules/web/Controllers/Helpers/ItemPresetHelper.php index c4ae2b5f..21d81f70 100644 --- a/app/modules/web/Controllers/Helpers/ItemPresetHelper.php +++ b/app/modules/web/Controllers/Helpers/ItemPresetHelper.php @@ -31,7 +31,7 @@ use SP\DataModel\ItemPreset\AccountPermission; use SP\DataModel\ItemPreset\AccountPrivate; use SP\DataModel\ItemPreset\Password; use SP\DataModel\ItemPreset\SessionTimeout; -use SP\DataModel\ItemPresetData; +use SP\Domain\Account\Models\ItemPreset; use SP\Domain\User\Ports\UserGroupServiceInterface; use SP\Domain\User\Ports\UserProfileServiceInterface; use SP\Domain\User\Ports\UserServiceInterface; @@ -71,7 +71,7 @@ final class ItemPresetHelper extends HelperBase /** * @throws NoSuchPropertyException */ - public function makeAccountPermissionView(ItemPresetData $itemPresetData): void + public function makeAccountPermissionView(ItemPreset $itemPresetData): void { $accountPermission = $itemPresetData->hydrate(AccountPermission::class) ?? new AccountPermission(); @@ -101,7 +101,7 @@ final class ItemPresetHelper extends HelperBase /** * @throws NoSuchPropertyException */ - public function makeAccountPrivateView(ItemPresetData $itemPresetData): void + public function makeAccountPrivateView(ItemPreset $itemPresetData): void { $accountPrivate = $itemPresetData->hydrate(AccountPrivate::class) ?? new AccountPrivate(); @@ -115,7 +115,7 @@ final class ItemPresetHelper extends HelperBase * @throws NoSuchPropertyException * @throws InvalidArgumentException */ - public function makeSessionTimeoutView(ItemPresetData $itemPresetData): void + public function makeSessionTimeoutView(ItemPreset $itemPresetData): void { $sessionTimeout = $itemPresetData->hydrate(SessionTimeout::class) ?? new SessionTimeout($this->request->getClientAddress(), 3600); @@ -129,7 +129,7 @@ final class ItemPresetHelper extends HelperBase /** * @throws NoSuchPropertyException */ - public function makeAccountPasswordView(ItemPresetData $itemPresetData): void + public function makeAccountPasswordView(ItemPreset $itemPresetData): void { $password = $itemPresetData->hydrate(Password::class) ?? new Password; @@ -145,7 +145,7 @@ final class ItemPresetHelper extends HelperBase * @throws \SP\Core\Exceptions\ConstraintException * @throws \SP\Core\Exceptions\QueryException */ - public function setCommon(ItemPresetData $itemPresetData): void + public function setCommon(ItemPreset $itemPresetData): void { $this->users = SelectItemAdapter::factory($this->userService->getAllBasic()); $this->userGroups = SelectItemAdapter::factory($this->userGroupService->getAllBasic()); diff --git a/app/modules/web/Controllers/ItemPreset/ItemPresetViewBase.php b/app/modules/web/Controllers/ItemPreset/ItemPresetViewBase.php index e6648883..8010c727 100644 --- a/app/modules/web/Controllers/ItemPreset/ItemPresetViewBase.php +++ b/app/modules/web/Controllers/ItemPreset/ItemPresetViewBase.php @@ -32,7 +32,7 @@ use SP\Core\Exceptions\ConstraintException; use SP\Core\Exceptions\InvalidArgumentException; use SP\Core\Exceptions\NoSuchPropertyException; use SP\Core\Exceptions\QueryException; -use SP\DataModel\ItemPresetData; +use SP\Domain\Account\Models\ItemPreset; use SP\Domain\ItemPreset\Ports\ItemPresetInterface; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Modules\Web\Controllers\ControllerBase; @@ -79,7 +79,7 @@ abstract class ItemPresetViewBase extends ControllerBase $itemPresetData = $id ? $this->itemPresetService->getById($id) - : new ItemPresetData(); + : new ItemPreset(); $this->itemPresetHelper->setCommon($itemPresetData); diff --git a/app/modules/web/Forms/AccountForm.php b/app/modules/web/Forms/AccountForm.php index 1bc563a4..1363f96d 100644 --- a/app/modules/web/Forms/AccountForm.php +++ b/app/modules/web/Forms/AccountForm.php @@ -26,23 +26,22 @@ namespace SP\Modules\Web\Forms; use SP\Core\Acl\ActionsInterface; use SP\Core\Application; -use SP\Core\Exceptions\ConstraintException; -use SP\Core\Exceptions\NoSuchPropertyException; -use SP\Core\Exceptions\QueryException; use SP\Core\Exceptions\ValidationException; -use SP\Domain\Account\Dtos\AccountRequest; +use SP\Domain\Account\Dtos\AccountCreateDto; +use SP\Domain\Account\Dtos\AccountDto; +use SP\Domain\Account\Dtos\AccountUpdateDto; use SP\Domain\Account\Ports\AccountPresetServiceInterface; use SP\Http\RequestInterface; +use SP\Util\Chainable; +use function SP\__u; /** * Class AccountForm - * - * @package SP\Account */ final class AccountForm extends FormBase implements FormInterface { - private AccountPresetServiceInterface $accountPresetService; - private AccountRequest $accountRequest; + private AccountPresetServiceInterface $accountPresetService; + private null|AccountCreateDto|AccountUpdateDto $accountDto = null; public function __construct( Application $application, @@ -53,7 +52,6 @@ final class AccountForm extends FormBase implements FormInterface parent::__construct($application, $request, $itemId); $this->accountPresetService = $accountPresetService; - $this->accountRequest = new AccountRequest(); } /** @@ -62,41 +60,47 @@ final class AccountForm extends FormBase implements FormInterface * @param int $action * @param int|null $id * - * @return AccountForm|FormInterface - * @throws ValidationException - * @throws ConstraintException - * @throws NoSuchPropertyException - * @throws QueryException + * @return \SP\Modules\Web\Forms\FormInterface */ public function validateFor(int $action, ?int $id = null): FormInterface { if ($id !== null) { $this->itemId = $id; } - + + $chain = new Chainable(fn() => $this->analyzeRequestData(), $this); + switch ($action) { case ActionsInterface::ACCOUNT_EDIT_PASS: - $this->analyzeRequestData(); - $this->checkPassword(); - $this->accountPresetService->checkPasswordPreset($this->accountRequest); + $this->accountDto = $chain->next(fn(AccountDto $dto) => $this->checkPassword($dto)) + ->next( + fn(AccountDto $dto) => $this->accountPresetService->checkPasswordPreset( + $dto + ) + ) + ->resolve(); break; case ActionsInterface::ACCOUNT_EDIT: - $this->analyzeRequestData(); - $this->analyzeItems(); - $this->checkCommon(); + $this->accountDto = $chain->next(fn(AccountDto $dto) => $this->analyzeItems($dto)) + ->next(fn(AccountDto $dto) => $this->checkCommon($dto)) + ->resolve(); break; case ActionsInterface::ACCOUNT_CREATE: case ActionsInterface::ACCOUNT_COPY: - $this->analyzeRequestData(); - $this->analyzeItems(); - $this->checkCommon(); - $this->checkPassword(); - $this->accountPresetService->checkPasswordPreset($this->accountRequest); + $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 ActionsInterface::ACCOUNTMGR_BULK_EDIT: - $this->analyzeRequestData(); - $this->analyzeItems(); - $this->analyzeBulkEdit(); + $this->accountDto = $chain->next(fn(AccountDto $dto) => $this->analyzeItems($dto)) + ->next(fn(AccountDto $dto) => $this->analyzeBulkEdit($dto)) + ->resolve(); break; } @@ -106,111 +110,154 @@ final class AccountForm extends FormBase implements FormInterface /** * Analizar los datos de la petición HTTP * - * @return void + * @return \SP\Domain\Account\Dtos\AccountCreateDto|\SP\Domain\Account\Dtos\AccountUpdateDto */ - protected function analyzeRequestData(): void + private function analyzeRequestData(): AccountCreateDto|AccountUpdateDto { - $this->accountRequest->id = $this->itemId; - $this->accountRequest->name = $this->request->analyzeString('name'); - $this->accountRequest->clientId = $this->request->analyzeInt('client_id'); - $this->accountRequest->categoryId = $this->request->analyzeInt('category_id'); - $this->accountRequest->login = $this->request->analyzeString('login'); - $this->accountRequest->url = $this->request->analyzeString('url'); - $this->accountRequest->notes = $this->request->analyzeUnsafeString('notes'); - $this->accountRequest->userEditId = $this->context->getUserData()->getId(); - $this->accountRequest->pass = $this->request->analyzeEncrypted('password'); - $this->accountRequest->isPrivate = (int)$this->request->analyzeBool('private_enabled', false); - $this->accountRequest->isPrivateGroup = (int)$this->request->analyzeBool('private_group_enabled', false); + $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'); - if ($this->request->analyzeInt('password_date_expire')) { - $this->accountRequest->passDateChange = $this->request->analyzeInt('password_date_expire_unix'); + 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( + $this->itemId, + $name, + $login, + $clientId, + $categoryId, + $password, + $userId, + null, + $url, + $notes, + $this->context->getUserData()->getId(), + $private, + $privateGroup, + $passDateChange, + $parentId, + $userGroupId + ); } - $this->accountRequest->parentId = $this->request->analyzeInt('parent_account_id'); - $this->accountRequest->userId = $this->request->analyzeInt('owner_id'); - $this->accountRequest->userGroupId = $this->request->analyzeInt('main_usergroup_id'); + return $accountDto; } /** * @throws ValidationException */ - private function checkPassword(): void + private function checkPassword(AccountDto $accountDto): void { - if ($this->accountRequest->parentId > 0) { + if ($accountDto->getParentId() > 0) { return; } - if (!$this->accountRequest->pass) { + if (!$accountDto->getPass()) { throw new ValidationException(__u('A key is needed')); } - if ($this->request->analyzeEncrypted('password_repeat') !== $this->accountRequest->pass) { + if ($this->request->analyzeEncrypted('password_repeat') !== $accountDto->getPass()) { throw new ValidationException(__u('Passwords do not match')); } } - private function analyzeItems(): void + private function analyzeItems(AccountDto $accountDto): AccountDto { if ($this->request->analyzeInt('other_users_view_update') === 1) { - $this->accountRequest->usersView = $this->request->analyzeArray('other_users_view', null, []); + $accountDto = $accountDto->withUsersView($this->request->analyzeArray('other_users_view', null, [])); } if ($this->request->analyzeInt('other_users_edit_update') === 1) { - $this->accountRequest->usersEdit = $this->request->analyzeArray('other_users_edit', null, []); + $accountDto = $accountDto->withUsersEdit($this->request->analyzeArray('other_users_edit', null, [])); } if ($this->request->analyzeInt('other_usergroups_view_update') === 1) { - $this->accountRequest->userGroupsView = $this->request->analyzeArray('other_usergroups_view', null, []); + $accountDto = + $accountDto->withUserGroupsView($this->request->analyzeArray('other_usergroups_view', null, [])); } if ($this->request->analyzeInt('other_usergroups_edit_update') === 1) { - $this->accountRequest->userGroupsEdit = $this->request->analyzeArray('other_usergroups_edit', null, []); + $accountDto = + $accountDto->withUserGroupsEdit($this->request->analyzeArray('other_usergroups_edit', null, [])); } if ($this->request->analyzeInt('tags_update') === 1) { - $this->accountRequest->tags = $this->request->analyzeArray('tags', null, []); + $accountDto = $accountDto->withTags($this->request->analyzeArray('tags', null, [])); } + + return $accountDto; } /** * @throws ValidationException */ - private function checkCommon(): void + private function checkCommon(AccountDto $accountDto): AccountDto { - if (!$this->accountRequest->name) { + if (!$accountDto->getName()) { throw new ValidationException(__u('An account name needed')); } - if (!$this->accountRequest->clientId) { + if (!$accountDto->getClientId()) { throw new ValidationException(__u('A client name needed')); } - if (!$this->accountRequest->categoryId) { + if (!$accountDto->getCategoryId()) { throw new ValidationException(__u('A category is needed')); } + + return $accountDto; } - private function analyzeBulkEdit(): void + private function analyzeBulkEdit(AccountDto $accountDto): AccountDto { if ($this->request->analyzeBool('clear_permission_users_view', false)) { - $this->accountRequest->usersView = []; + $accountDto = $accountDto->withUsersView([]); } if ($this->request->analyzeBool('clear_permission_users_edit', false)) { - $this->accountRequest->usersEdit = []; + $accountDto = $accountDto->withUsersEdit([]); } if ($this->request->analyzeBool('clear_permission_usergroups_view', false)) { - $this->accountRequest->userGroupsView = []; + $accountDto = $accountDto->withUserGroupsView([]); } if ($this->request->analyzeBool('clear_permission_usergroups_edit', false)) { - $this->accountRequest->userGroupsEdit = []; + $accountDto = $accountDto->withUserGroupsEdit([]); } + + return $accountDto; } - public function getItemData(): AccountRequest + public function getItemData(): AccountCreateDto|AccountUpdateDto|null { - return $this->accountRequest; + return $this->accountDto; } } diff --git a/app/modules/web/Forms/FormBase.php b/app/modules/web/Forms/FormBase.php index da8199f1..5f67e90e 100644 --- a/app/modules/web/Forms/FormBase.php +++ b/app/modules/web/Forms/FormBase.php @@ -28,7 +28,6 @@ use SP\Core\Application; use SP\Core\Context\ContextInterface; use SP\Domain\Config\Ports\ConfigDataInterface; use SP\Domain\Config\Services\ConfigFileService; -use SP\Http\Request; use SP\Http\RequestInterface; /** @@ -38,11 +37,9 @@ use SP\Http\RequestInterface; */ abstract class FormBase { - protected ?int $itemId; protected ConfigFileService $config; protected ConfigDataInterface $configData; protected ContextInterface $context; - protected Request $request; /** * FormBase constructor. @@ -53,14 +50,12 @@ abstract class FormBase */ public function __construct( Application $application, - RequestInterface $request, - ?int $itemId = null + protected RequestInterface $request, + protected ?int $itemId = null ) { $this->config = $application->getConfig(); $this->configData = $this->config->getConfigData(); $this->context = $application->getContext(); - $this->request = $request; - $this->itemId = $itemId; } /** @@ -70,9 +65,4 @@ abstract class FormBase { return $this->itemId; } - - /** - * Analizar los datos de la petición HTTP - */ - abstract protected function analyzeRequestData(); } diff --git a/app/modules/web/Forms/FormInterface.php b/app/modules/web/Forms/FormInterface.php index dc03f446..e288eb53 100644 --- a/app/modules/web/Forms/FormInterface.php +++ b/app/modules/web/Forms/FormInterface.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2021, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -47,5 +47,5 @@ interface FormInterface /** * @return mixed */ - public function getItemData(); -} \ No newline at end of file + public function getItemData(): mixed; +} diff --git a/app/modules/web/Forms/ItemsPresetForm.php b/app/modules/web/Forms/ItemsPresetForm.php index ae7a9d70..f89de672 100644 --- a/app/modules/web/Forms/ItemsPresetForm.php +++ b/app/modules/web/Forms/ItemsPresetForm.php @@ -31,7 +31,7 @@ use SP\DataModel\ItemPreset\AccountPermission; use SP\DataModel\ItemPreset\AccountPrivate; use SP\DataModel\ItemPreset\Password; use SP\DataModel\ItemPreset\SessionTimeout; -use SP\DataModel\ItemPresetData; +use SP\Domain\Account\Models\ItemPreset; use SP\Domain\ItemPreset\Ports\ItemPresetInterface; use SP\Domain\ItemPreset\Services\ItemPresetRequest; use SP\Mvc\Controller\Validators\Validator; @@ -79,7 +79,7 @@ final class ItemsPresetForm extends FormBase implements FormInterface */ protected function analyzeRequestData(): void { - $itemPresetData = new ItemPresetData(); + $itemPresetData = new ItemPreset(); if ($this->itemId > 0) { $itemPresetData->setId($this->itemId); @@ -143,11 +143,10 @@ final class ItemsPresetForm extends FormBase implements FormInterface */ private function makePrivatePreset(): AccountPrivate { - $accountPrivate = new AccountPrivate(); - $accountPrivate->setPrivateUser($this->request->analyzeBool('private_user_enabled', false)); - $accountPrivate->setPrivateGroup($this->request->analyzeBool('private_group_enabled', false)); - - return $accountPrivate; + return new AccountPrivate( + $this->request->analyzeBool('private_user_enabled', false), + $this->request->analyzeBool('private_group_enabled', false) + ); } /** diff --git a/app/modules/web/themes/material-blue/views/account/search-rows.inc b/app/modules/web/themes/material-blue/views/account/search-rows.inc index ab3509e5..662b0bd1 100644 --- a/app/modules/web/themes/material-blue/views/account/search-rows.inc +++ b/app/modules/web/themes/material-blue/views/account/search-rows.inc @@ -52,7 +52,7 @@ $favoriteRouteOff = $_getvar('favoriteRouteOff');