From 8130582df17dec054f93dbd981ea3ec02593c50f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D?= Date: Sun, 12 Jun 2022 21:55:29 +0200 Subject: [PATCH] refactor: Improve Account helper hierarchy. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rubén D --- .../Account/RequestAccessController.php | 26 +- .../Helpers/Account/AccountActionsHelper.php | 273 ++++----------- .../Helpers/Account/AccountHelper.php | 327 ++++-------------- .../Helpers/Account/AccountHelperBase.php | 90 +++++ .../Helpers/Account/AccountHistoryHelper.php | 67 ++-- .../Helpers/Account/AccountRequestHelper.php | 76 ++++ .../Helpers/Account/AccountSearchHelper.php | 41 +-- .../web/Controllers/Helpers/HelperBase.php | 4 - 8 files changed, 365 insertions(+), 539 deletions(-) create mode 100644 app/modules/web/Controllers/Helpers/Account/AccountHelperBase.php create mode 100644 app/modules/web/Controllers/Helpers/Account/AccountRequestHelper.php diff --git a/app/modules/web/Controllers/Account/RequestAccessController.php b/app/modules/web/Controllers/Account/RequestAccessController.php index 808b82bc..54eec363 100644 --- a/app/modules/web/Controllers/Account/RequestAccessController.php +++ b/app/modules/web/Controllers/Account/RequestAccessController.php @@ -26,14 +26,34 @@ namespace SP\Modules\Web\Controllers\Account; use Exception; use SP\Core\Acl\ActionsInterface; +use SP\Core\Application; use SP\Core\Events\Event; +use SP\Domain\Account\AccountServiceInterface; +use SP\Modules\Web\Controllers\ControllerBase; +use SP\Modules\Web\Controllers\Helpers\Account\AccountRequestHelper; +use SP\Mvc\Controller\WebControllerHelper; use SP\Util\ErrorUtil; /** * Class RequestAccessController */ -final class RequestAccessController extends AccountViewBase +final class RequestAccessController extends ControllerBase { + private AccountRequestHelper $accountRequestHelper; + private AccountServiceInterface $accountService; + + public function __construct( + Application $application, + WebControllerHelper $webControllerHelper, + AccountServiceInterface $accountService, + AccountRequestHelper $accountRequestHelper + ) { + parent::__construct($application, $webControllerHelper); + + $this->accountRequestHelper = $accountRequestHelper; + $this->accountService = $accountService; + } + /** * Obtener los datos para mostrar el interface de solicitud de cambios en una cuenta * @@ -43,8 +63,8 @@ final class RequestAccessController extends AccountViewBase public function requestAccessAction(int $id): void { try { - $this->accountHelper->setIsView(true); - $this->accountHelper->setViewForRequest( + $this->accountRequestHelper->setIsView(true); + $this->accountRequestHelper->setViewForRequest( $this->accountService->getById($id), ActionsInterface::ACCOUNT_REQUEST ); diff --git a/app/modules/web/Controllers/Helpers/Account/AccountActionsHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountActionsHelper.php index 1226887c..e2d88ba2 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountActionsHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountActionsHelper.php @@ -26,12 +26,15 @@ namespace SP\Modules\Web\Controllers\Helpers\Account; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; +use SP\Core\Application; use SP\Core\UI\ThemeIcons; use SP\Domain\Account\Services\AccountAcl; use SP\Domain\Account\Services\AccountSearchItem; use SP\Html\DataGrid\Action\DataGridAction; use SP\Html\DataGrid\Action\DataGridActionType; +use SP\Http\RequestInterface; use SP\Modules\Web\Controllers\Helpers\HelperBase; +use SP\Mvc\View\TemplateInterface; /** * Class AccountIconsHelper @@ -40,8 +43,14 @@ use SP\Modules\Web\Controllers\Helpers\HelperBase; */ final class AccountActionsHelper extends HelperBase { - protected ?ThemeIcons $icons = null; - protected ?string $sk = null; + protected ThemeIcons $icons; + + public function __construct(Application $application, TemplateInterface $template, RequestInterface $request) + { + parent::__construct($application, $template, $request); + + $this->icons = $this->view->getTheme()->getIcons(); + } /** * @return DataGridAction @@ -55,18 +64,9 @@ final class AccountActionsHelper extends HelperBase $action->setTitle(__('Account Details')); $action->addClass('btn-action'); $action->setIcon($this->icons->getIconView()); - $action->setRuntimeFilter( - AccountSearchItem::class, - 'isShowView' - ); - $action->addData( - 'action-route', - Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW) - ); - $action->addData( - 'onclick', - Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW) - ); + $action->setRuntimeFilter(AccountSearchItem::class, 'isShowView'); + $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW)); + $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW)); $action->addAttribute('type', 'button'); return $action; @@ -89,10 +89,7 @@ final class AccountActionsHelper extends HelperBase $actionBack = $this->getBackAction(); if ($accountActionsDto->isHistory()) { - $actionBack->addData( - 'item-id', - $accountActionsDto->getAccountId() - ); + $actionBack->addData('item-id', $accountActionsDto->getAccountId()); $actionBack->setName(__('View Current')); $actionBack->setTitle(__('View Current')); } else { @@ -103,40 +100,30 @@ final class AccountActionsHelper extends HelperBase $actions[] = $actionBack; if ($accountAcl->isShowEditPass()) { - $actions[] = $this->getEditPassAction() - ->addData('item-id', $accountActionsDto->getAccountId()); + $actions[] = $this->getEditPassAction()->addData('item-id', $accountActionsDto->getAccountId()); } if ($accountAcl->isShowEdit()) { - $actions[] = $this->getEditAction() - ->addData('item-id', $accountActionsDto->getAccountId()); + $actions[] = $this->getEditAction()->addData('item-id', $accountActionsDto->getAccountId()); } if ($accountAcl->getActionId() === ActionsInterface::ACCOUNT_VIEW && !$accountAcl->isShowEdit() && $this->configData->isMailRequestsEnabled() ) { - $actions[] = $this->getRequestAction() - ->addData('item-id', $accountActionsDto->getAccountId()); + $actions[] = $this->getRequestAction()->addData('item-id', $accountActionsDto->getAccountId()); } if ($accountAcl->isShowRestore()) { $actionRestore = $this->getRestoreAction(); - $actionRestore->addData( - 'item-id', - $accountActionsDto->getAccountId() - ); - $actionRestore->addData( - 'history-id', - $accountActionsDto->getAccountHistoryId() - ); + $actionRestore->addData('item-id', $accountActionsDto->getAccountId()); + $actionRestore->addData('history-id', $accountActionsDto->getAccountHistoryId()); $actions[] = $actionRestore; } if ($accountAcl->isShowSave()) { - $actions[] = $this->getSaveAction() - ->addAttribute('form', 'frmAccount'); + $actions[] = $this->getSaveAction()->addAttribute('form', 'frmAccount'); } return $actions; @@ -153,14 +140,8 @@ final class AccountActionsHelper extends HelperBase $action->setTitle(__('Back')); $action->addClass('btn-action'); $action->setIcon($this->icons->getIconBack()); - $action->addData( - 'action-route', - Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW) - ); - $action->addData( - 'onclick', - Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW) - ); + $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW)); + $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW)); $action->addAttribute('type', 'button'); return $action; @@ -178,18 +159,9 @@ final class AccountActionsHelper extends HelperBase $action->setTitle(__('Edit Account Password')); $action->addClass('btn-action'); $action->setIcon($this->icons->getIconEditPass()); - $action->setRuntimeFilter( - AccountSearchItem::class, - 'isShowViewPass' - ); - $action->addData( - 'action-route', - Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT_PASS) - ); - $action->addData( - 'onclick', - Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT_PASS) - ); + $action->setRuntimeFilter(AccountSearchItem::class, 'isShowViewPass'); + $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT_PASS)); + $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT_PASS)); $action->addAttribute('type', 'button'); return $action; @@ -207,18 +179,9 @@ final class AccountActionsHelper extends HelperBase $action->setTitle(__('Edit Account')); $action->addClass('btn-action'); $action->setIcon($this->icons->getIconEdit()); - $action->setRuntimeFilter( - AccountSearchItem::class, - 'isShowEdit' - ); - $action->addData( - 'action-route', - Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT) - ); - $action->addData( - 'onclick', - Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT) - ); + $action->setRuntimeFilter(AccountSearchItem::class, 'isShowEdit'); + $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT)); + $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT)); $action->addAttribute('type', 'button'); return $action; @@ -235,18 +198,9 @@ final class AccountActionsHelper extends HelperBase $action->setTitle(__('Request Modification')); $action->addClass('btn-action'); $action->setIcon($this->icons->getIconEmail()); - $action->setRuntimeFilter( - AccountSearchItem::class, - 'isShowRequest' - ); - $action->addData( - 'action-route', - Acl::getActionRoute(ActionsInterface::ACCOUNT_REQUEST) - ); - $action->addData( - 'onclick', - Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW) - ); + $action->setRuntimeFilter(AccountSearchItem::class, 'isShowRequest'); + $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_REQUEST)); + $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW)); $action->addAttribute('type', 'submit'); return $action; @@ -322,10 +276,7 @@ final class AccountActionsHelper extends HelperBase if ($itemId) { $actionRefresh = $this->getPublicLinkRefreshAction(); $actionRefresh->addData('item-id', $itemId); - $actionRefresh->addData( - 'account-id', - $accountActionsDto->getAccountId() - ); + $actionRefresh->addData('account-id', $accountActionsDto->getAccountId()); $actions[] = $actionRefresh; @@ -334,19 +285,13 @@ final class AccountActionsHelper extends HelperBase ) { $actionDelete = $this->getPublicLinkDeleteAction(); $actionDelete->addData('item-id', $itemId); - $actionDelete->addData( - 'account-id', - $accountActionsDto->getAccountId() - ); + $actionDelete->addData('account-id', $accountActionsDto->getAccountId()); $actions[] = $actionDelete; } } else { $action = $this->getPublicLinkAction(); - $action->addData( - 'account-id', - $accountActionsDto->getAccountId() - ); + $action->addData('account-id', $accountActionsDto->getAccountId()); $actions[] = $action; } @@ -355,36 +300,18 @@ final class AccountActionsHelper extends HelperBase if ($accountAcl->isShowViewPass()) { if ($accountActionsDto->isHistory()) { $actionViewPass = $this->getViewPassHistoryAction() - ->addData( - 'item-id', - $accountActionsDto->getAccountHistoryId() - ); + ->addData('item-id', $accountActionsDto->getAccountHistoryId()); $actionCopy = $this->getCopyPassHistoryAction() - ->addData( - 'item-id', - $accountActionsDto->getAccountHistoryId() - ); + ->addData('item-id', $accountActionsDto->getAccountHistoryId()); } else { $actionViewPass = $this->getViewPassAction() - ->addData( - 'item-id', - $accountActionsDto->getAccountId() - ); + ->addData('item-id', $accountActionsDto->getAccountId()); $actionCopy = $this->getCopyPassAction() - ->addData( - 'item-id', - $accountActionsDto->getAccountId() - ); + ->addData('item-id', $accountActionsDto->getAccountId()); } - $actionViewPass->addData( - 'parent-id', - $accountActionsDto->getAccountParentId() - ); - $actionCopy->addData( - 'parent-id', - $accountActionsDto->getAccountParentId() - ); + $actionViewPass->addData('parent-id', $accountActionsDto->getAccountParentId()); + $actionCopy->addData('parent-id', $accountActionsDto->getAccountParentId()); $actions[] = $actionViewPass; $actions[] = $actionCopy; @@ -410,18 +337,9 @@ final class AccountActionsHelper extends HelperBase $action->setTitle(__('Remove Account')); $action->addClass('btn-action'); $action->setIcon($this->icons->getIconDelete()); - $action->setRuntimeFilter( - AccountSearchItem::class, - 'isShowDelete' - ); - $action->addData( - 'action-route', - Acl::getActionRoute(ActionsInterface::ACCOUNT_DELETE) - ); - $action->addData( - 'onclick', - Acl::getActionRoute(ActionsInterface::ACCOUNT_DELETE) - ); + $action->setRuntimeFilter(AccountSearchItem::class, 'isShowDelete'); + $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_DELETE)); + $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_DELETE)); $action->addAttribute('type', 'button'); return $action; @@ -438,15 +356,9 @@ final class AccountActionsHelper extends HelperBase $action->setTitle(__('Update Public Link')); $action->addClass('btn-action'); $action->setIcon($this->icons->getIconPublicLink()); - $action->addData( - 'action-route', - Acl::getActionRoute(ActionsInterface::PUBLICLINK_REFRESH) - ); + $action->addData('action-route', Acl::getActionRoute(ActionsInterface::PUBLICLINK_REFRESH)); $action->addData('onclick', 'link/refresh'); - $action->addData( - 'action-next', - Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW) - ); + $action->addData('action-next', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW)); $action->addAttribute('type', 'button'); return $action; @@ -466,15 +378,9 @@ final class AccountActionsHelper extends HelperBase $action->setTitle(__('Delete Public Link')); $action->addClass('btn-action'); $action->setIcon($icon); - $action->addData( - 'action-route', - Acl::getActionRoute(ActionsInterface::PUBLICLINK_DELETE) - ); + $action->addData('action-route', Acl::getActionRoute(ActionsInterface::PUBLICLINK_DELETE)); $action->addData('onclick', 'link/delete'); - $action->addData( - 'action-next', - Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW) - ); + $action->addData('action-next', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW)); $action->addAttribute('type', 'button'); return $action; @@ -491,15 +397,9 @@ final class AccountActionsHelper extends HelperBase $action->setTitle(__('Create Public Link')); $action->addClass('btn-action'); $action->setIcon($this->icons->getIconPublicLink()); - $action->addData( - 'action-route', - 'publicLink/saveCreateFromAccount' - ); + $action->addData('action-route', 'publicLink/saveCreateFromAccount'); $action->addData('onclick', 'link/save'); - $action->addData( - 'action-next', - Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW) - ); + $action->addData('action-next', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW)); $action->addAttribute('type', 'button'); return $action; @@ -517,19 +417,10 @@ final class AccountActionsHelper extends HelperBase $action->setTitle(__('View password')); $action->addClass('btn-action'); $action->setIcon($this->icons->getIconViewPass()); - $action->setRuntimeFilter( - AccountSearchItem::class, - 'isShowViewPass' - ); - $action->addData( - 'action-route', - Acl::getActionRoute(ActionsInterface::ACCOUNT_HISTORY_VIEW_PASS) - ); + $action->setRuntimeFilter(AccountSearchItem::class, 'isShowViewPass'); + $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_HISTORY_VIEW_PASS)); $action->addData('action-full', 1); - $action->addData( - 'onclick', - Acl::getActionRoute(ActionsInterface::ACCOUNT_HISTORY_VIEW_PASS) - ); + $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_HISTORY_VIEW_PASS)); $action->addAttribute('type', 'button'); return $action; @@ -548,14 +439,8 @@ final class AccountActionsHelper extends HelperBase $action->addClass('btn-action'); $action->addClass('clip-pass-button'); $action->setIcon($this->icons->getIconClipboard()); - $action->setRuntimeFilter( - AccountSearchItem::class, - 'isShowCopyPass' - ); - $action->addData( - 'action-route', - Acl::getActionRoute(ActionsInterface::ACCOUNT_HISTORY_COPY_PASS) - ); + $action->setRuntimeFilter(AccountSearchItem::class, 'isShowCopyPass'); + $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_HISTORY_COPY_PASS)); $action->addData('action-full', 0); $action->addData('useclipboard', '1'); $action->addAttribute('type', 'button'); @@ -575,19 +460,10 @@ final class AccountActionsHelper extends HelperBase $action->setTitle(__('View password')); $action->addClass('btn-action'); $action->setIcon($this->icons->getIconViewPass()); - $action->setRuntimeFilter( - AccountSearchItem::class, - 'isShowViewPass' - ); - $action->addData( - 'action-route', - Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW_PASS) - ); + $action->setRuntimeFilter(AccountSearchItem::class, 'isShowViewPass'); + $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW_PASS)); $action->addData('action-full', 1); - $action->addData( - 'onclick', - Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW_PASS) - ); + $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW_PASS)); $action->addAttribute('type', 'button'); return $action; @@ -606,14 +482,8 @@ final class AccountActionsHelper extends HelperBase $action->addClass('btn-action'); $action->addClass('clip-pass-button'); $action->setIcon($this->icons->getIconClipboard()); - $action->setRuntimeFilter( - AccountSearchItem::class, - 'isShowCopyPass' - ); - $action->addData( - 'action-route', - Acl::getActionRoute(ActionsInterface::ACCOUNT_COPY_PASS) - ); + $action->setRuntimeFilter(AccountSearchItem::class, 'isShowCopyPass'); + $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_COPY_PASS)); $action->addData('action-full', 0); $action->addData('useclipboard', '1'); $action->addAttribute('type', 'button'); @@ -633,28 +503,11 @@ final class AccountActionsHelper extends HelperBase $action->setTitle(__('Copy Account')); $action->addClass('btn-action'); $action->setIcon($this->icons->getIconCopy()); - $action->setRuntimeFilter( - AccountSearchItem::class, - 'isShowCopy' - ); - $action->addData( - 'action-route', - Acl::getActionRoute(ActionsInterface::ACCOUNT_COPY) - ); - $action->addData( - 'onclick', - Acl::getActionRoute(ActionsInterface::ACCOUNT_COPY) - ); + $action->setRuntimeFilter(AccountSearchItem::class, 'isShowCopy'); + $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_COPY)); + $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_COPY)); $action->addAttribute('type', 'button'); return $action; } - - /** - * Initialize class - */ - protected function initialize(): void - { - $this->icons = $this->view->getTheme()->getIcons(); - } } \ No newline at end of file diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php index cf07f395..e9282a50 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php @@ -24,12 +24,9 @@ namespace SP\Modules\Web\Controllers\Helpers\Account; -use Psr\Container\ContainerExceptionInterface; -use Psr\Container\NotFoundExceptionInterface; use SP\Core\Acl\AccountPermissionException; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; -use SP\Core\Acl\UnauthorizedPageException; use SP\Core\Application; use SP\Core\Bootstrap\BootstrapBase; use SP\Core\Exceptions\ConstraintException; @@ -39,6 +36,7 @@ use SP\DataModel\Dto\AccountAclDto; use SP\DataModel\Dto\AccountDetailsResponse; use SP\DataModel\ItemPreset\AccountPermission; use SP\DataModel\ItemPreset\AccountPrivate; +use SP\DataModel\ProfileData; use SP\Domain\Account\AccountAclServiceInterface; use SP\Domain\Account\AccountHistoryServiceInterface; use SP\Domain\Account\AccountServiceInterface; @@ -51,13 +49,11 @@ use SP\Domain\Crypt\MasterPassServiceInterface; use SP\Domain\CustomField\CustomFieldServiceInterface; use SP\Domain\ItemPreset\ItemPresetInterface; use SP\Domain\ItemPreset\ItemPresetServiceInterface; -use SP\Domain\Tag\Services\TagService; -use SP\Domain\User\Services\UpdatedMasterPassException; -use SP\Domain\User\Services\UserGroupService; -use SP\Domain\User\Services\UserService; +use SP\Domain\Tag\TagServiceInterface; +use SP\Domain\User\UserGroupServiceInterface; +use SP\Domain\User\UserServiceInterface; use SP\Http\RequestInterface; use SP\Infrastructure\Common\Repositories\NoSuchItemException; -use SP\Modules\Web\Controllers\Helpers\HelperBase; use SP\Mvc\Controller\ItemTrait; use SP\Mvc\View\Components\SelectItemAdapter; use SP\Mvc\View\TemplateInterface; @@ -68,7 +64,7 @@ use SP\Util\Link; * * @package SP\Modules\Web\Controllers\Helpers */ -final class AccountHelper extends HelperBase +final class AccountHelper extends AccountHelperBase { use ItemTrait; @@ -78,15 +74,15 @@ final class AccountHelper extends HelperBase private PublicLinkServiceInterface $publicLinkService; private ItemPresetServiceInterface $itemPresetService; private MasterPassServiceInterface $masterPassService; - private AccountActionsHelper $accountActionsHelper; private AccountAclServiceInterface $accountAclService; private CategoryServiceInterface $categoryService; private ClientServiceInterface $clientService; private CustomFieldServiceInterface $customFieldService; - private ?int $actionId = null; private ?AccountAcl $accountAcl = null; private ?int $accountId = null; - private bool $isView = false; + private UserServiceInterface $userService; + private UserGroupServiceInterface $userGroupService; + private TagServiceInterface $tagService; public function __construct( Application $application, @@ -102,21 +98,24 @@ final class AccountHelper extends HelperBase AccountAclServiceInterface $accountAclService, CategoryServiceInterface $categoryService, ClientServiceInterface $clientService, - CustomFieldServiceInterface $customFieldService + CustomFieldServiceInterface $customFieldService, + UserServiceInterface $userService, + UserGroupServiceInterface $userGroupService, + TagServiceInterface $tagService ) { - parent::__construct($application, $template, $request); + parent::__construct($application, $template, $request, $acl, $accountActionsHelper, $masterPassService); - $this->acl = $acl; $this->accountService = $accountService; $this->accountHistoryService = $accountHistoryService; $this->publicLinkService = $publicLinkService; $this->itemPresetService = $itemPresetService; - $this->masterPassService = $masterPassService; - $this->accountActionsHelper = $accountActionsHelper; $this->accountAclService = $accountAclService; $this->categoryService = $categoryService; $this->clientService = $clientService; $this->customFieldService = $customFieldService; + $this->userService = $userService; + $this->userGroupService = $userGroupService; + $this->tagService = $tagService; $this->view->assign('changesHash'); $this->view->assign('chkUserEdit', false); @@ -130,12 +129,14 @@ final class AccountHelper extends HelperBase * @param AccountDetailsResponse $accountDetailsResponse * @param int $actionId * - * @throws AccountPermissionException - * @throws SPException - * @throws UnauthorizedPageException - * @throws UpdatedMasterPassException - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface + * @throws \SP\Core\Acl\AccountPermissionException + * @throws \SP\Core\Acl\UnauthorizedPageException + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + * @throws \SP\Core\Exceptions\SPException + * @throws \SP\Domain\Common\Services\ServiceException + * @throws \SP\Domain\User\Services\UpdatedMasterPassException + * @throws \SP\Infrastructure\Common\Repositories\NoSuchItemException */ public function setViewForAccount( AccountDetailsResponse $accountDetailsResponse, @@ -145,77 +146,50 @@ final class AccountHelper extends HelperBase $this->actionId = $actionId; $this->checkActionAccess(); + $this->accountAcl = $this->checkAccess($accountDetailsResponse); $accountData = $accountDetailsResponse->getAccountVData(); - $accountActionsDto = new AccountActionsDto( - $this->accountId, - null, - $accountData->getParentId() - ); + $accountActionsDto = new AccountActionsDto($this->accountId, null, $accountData->getParentId()); - // FIXME: use IoC - $selectUsers = SelectItemAdapter::factory(UserService::getItemsBasic()); - $selectUserGroups = SelectItemAdapter::factory(UserGroupService::getItemsBasic()); - $selectTags = SelectItemAdapter::factory(TagService::getItemsBasic()); + $selectUsers = SelectItemAdapter::factory($this->userService->getAllBasic()); + $selectUserGroups = SelectItemAdapter::factory($this->userGroupService->getAllBasic()); + $selectTags = SelectItemAdapter::factory($this->tagService->getAllBasic()); $usersView = SelectItemAdapter::getIdFromArrayOfObjects( array_filter( $accountDetailsResponse->getUsers(), - static function ($value) { - return (int)$value->isEdit === 0; - } + static fn($value) => (int)$value->isEdit === 0 ) ); $usersEdit = SelectItemAdapter::getIdFromArrayOfObjects( array_filter( $accountDetailsResponse->getUsers(), - static function ($value) { - return (int)$value->isEdit === 1; - } + static fn($value) => (int)$value->isEdit === 1 ) ); $userGroupsView = SelectItemAdapter::getIdFromArrayOfObjects( array_filter( $accountDetailsResponse->getUserGroups(), - static function ($value) { - return (int)$value->isEdit === 0; - } + static fn($value) => (int)$value->isEdit === 0 ) ); $userGroupsEdit = SelectItemAdapter::getIdFromArrayOfObjects( array_filter( $accountDetailsResponse->getUserGroups(), - static function ($value) { - return (int)$value->isEdit === 1; - } + static fn($value) => (int)$value->isEdit === 1 ) ); - $this->view->assign( - 'otherUsersView', - $selectUsers->getItemsFromModelSelected($usersView) - ); - $this->view->assign( - 'otherUsersEdit', - $selectUsers->getItemsFromModelSelected($usersEdit) - ); - $this->view->assign( - 'otherUserGroupsView', - $selectUserGroups->getItemsFromModelSelected($userGroupsView) - ); - $this->view->assign( - 'otherUserGroupsEdit', - $selectUserGroups->getItemsFromModelSelected($userGroupsEdit) - ); - $this->view->assign( - 'users', - $selectUsers->getItemsFromModelSelected([$accountData->getUserId()]) - ); + $this->view->assign('otherUsersView', $selectUsers->getItemsFromModelSelected($usersView)); + $this->view->assign('otherUsersEdit', $selectUsers->getItemsFromModelSelected($usersEdit)); + $this->view->assign('otherUserGroupsView', $selectUserGroups->getItemsFromModelSelected($userGroupsView)); + $this->view->assign('otherUserGroupsEdit', $selectUserGroups->getItemsFromModelSelected($userGroupsEdit)); + $this->view->assign('users', $selectUsers->getItemsFromModelSelected([$accountData->getUserId()])); $this->view->assign( 'userGroups', $selectUserGroups->getItemsFromModelSelected([$accountData->getUserGroupId()]) @@ -231,18 +205,9 @@ final class AccountHelper extends HelperBase SelectItemAdapter::factory($this->accountHistoryService->getHistoryForAccount($this->accountId)) ->getItemsFromArray() ); - $this->view->assign( - 'isModified', - strtotime($accountData->getDateEdit()) !== false - ); - $this->view->assign( - 'maxFileSize', - round($this->configData->getFilesAllowedSize() / 1024, 1) - ); - $this->view->assign( - 'filesAllowedExts', - implode(',', $this->configData->getFilesAllowedExts()) - ); + $this->view->assign('isModified', strtotime($accountData->getDateEdit()) !== false); + $this->view->assign('maxFileSize', round($this->configData->getFilesAllowedSize() / 1024, 1)); + $this->view->assign('filesAllowedExts', implode(',', $this->configData->getFilesAllowedExts())); if ($this->configData->isPublinksEnabled() && $this->accountAcl->isShowLink()) { try { @@ -259,10 +224,7 @@ final class AccountHelper extends HelperBase $publicLinkData->getHash() ) ); - $this->view->assign( - 'publicLinkId', - $publicLinkData->getId() - ); + $this->view->assign('publicLinkId', $publicLinkData->getId()); } catch (NoSuchItemException $e) { $this->view->assign('publicLinkId', 0); $this->view->assign('publicLinkUrl', null); @@ -274,7 +236,7 @@ final class AccountHelper extends HelperBase } $userData = $this->context->getUserData(); - $userProfileData = $this->context->getUserProfile(); + $userProfileData = $this->context->getUserProfile() ?? new ProfileData(); $this->view->assign( 'allowPrivate', @@ -300,10 +262,7 @@ final class AccountHelper extends HelperBase ? gmdate('Y-m-d', $accountData->getPassDateChange()) : 0 ); - $this->view->assign( - 'linkedAccounts', - $this->accountService->getLinked($this->accountId) - ); + $this->view->assign('linkedAccounts', $this->accountService->getLinked($this->accountId)); $this->view->assign('accountId', $accountData->getId()); $this->view->assign('accountData', $accountData); @@ -327,24 +286,6 @@ final class AccountHelper extends HelperBase $this->setViewCommon(); } - /** - * @throws NoSuchItemException - * @throws UnauthorizedPageException - * @throws UpdatedMasterPassException - * @throws \SP\Domain\Common\Services\ServiceException - */ - public function checkActionAccess(): void - { - if (!$this->acl->checkUserAccess($this->actionId)) { - throw new UnauthorizedPageException(SPException::INFO); - } - - if (!$this->masterPassService->checkUserUpdateMPass($this->context->getUserData()->getLastUpdateMPass()) - ) { - throw new UpdatedMasterPassException(SPException::INFO); - } - } - /** * Comprobar si el usuario dispone de acceso al módulo * @@ -394,85 +335,42 @@ final class AccountHelper extends HelperBase $this->view->assign( 'categories', - SelectItemAdapter::factory( - $this->categoryService->getAllBasic() - )->getItemsFromModel() + SelectItemAdapter::factory($this->categoryService->getAllBasic())->getItemsFromModel() ); $this->view->assign( 'clients', - SelectItemAdapter::factory( - $this->clientService->getAllForUser() - )->getItemsFromModel() - ); - $this->view->assign( - 'mailRequestEnabled', - $this->configData->isMailRequestsEnabled() - ); - $this->view->assign( - 'passToImageEnabled', - $this->configData->isAccountPassToImage() - ); - $this->view->assign( - 'otherAccounts', - $this->accountService->getForUser($this->accountId) + SelectItemAdapter::factory($this->clientService->getAllForUser())->getItemsFromModel() ); + $this->view->assign('mailRequestEnabled', $this->configData->isMailRequestsEnabled()); + $this->view->assign('passToImageEnabled', $this->configData->isAccountPassToImage()); + $this->view->assign('otherAccounts', $this->accountService->getForUser($this->accountId)); $this->view->assign( 'addClientEnabled', - !$this->isView - && $this->acl->checkUserAccess(ActionsInterface::CLIENT) - ); - $this->view->assign( - 'addClientRoute', - Acl::getActionRoute(ActionsInterface::CLIENT_CREATE) + !$this->isView && $this->acl->checkUserAccess(ActionsInterface::CLIENT) ); + $this->view->assign('addClientRoute', Acl::getActionRoute(ActionsInterface::CLIENT_CREATE)); $this->view->assign( 'addCategoryEnabled', - !$this->isView - && $this->acl->checkUserAccess(ActionsInterface::CATEGORY) - ); - $this->view->assign( - 'addCategoryRoute', - Acl::getActionRoute(ActionsInterface::CATEGORY_CREATE) + !$this->isView && $this->acl->checkUserAccess(ActionsInterface::CATEGORY) ); + $this->view->assign('addCategoryRoute', Acl::getActionRoute(ActionsInterface::CATEGORY_CREATE)); $this->view->assign( 'addTagEnabled', !$this->isView && $this->acl->checkUserAccess(ActionsInterface::TAG) ); - $this->view->assign( - 'addTagRoute', - Acl::getActionRoute(ActionsInterface::TAG_CREATE) - ); - $this->view->assign( - 'fileListRoute', - Acl::getActionRoute(ActionsInterface::ACCOUNT_FILE_LIST) - ); - $this->view->assign( - 'fileUploadRoute', - Acl::getActionRoute(ActionsInterface::ACCOUNT_FILE_UPLOAD) - ); - $this->view->assign( - 'disabled', - $this->isView ? 'disabled' : '' - ); - $this->view->assign( - 'readonly', - $this->isView ? 'readonly' : '' - ); - $this->view->assign( - 'showViewCustomPass', - $this->accountAcl->isShowViewPass() - ); + $this->view->assign('addTagRoute', Acl::getActionRoute(ActionsInterface::TAG_CREATE)); + $this->view->assign('fileListRoute', Acl::getActionRoute(ActionsInterface::ACCOUNT_FILE_LIST)); + $this->view->assign('fileUploadRoute', Acl::getActionRoute(ActionsInterface::ACCOUNT_FILE_UPLOAD)); + $this->view->assign('disabled', $this->isView ? 'disabled' : ''); + $this->view->assign('readonly', $this->isView ? 'readonly' : ''); + $this->view->assign('showViewCustomPass', $this->accountAcl->isShowViewPass()); $this->view->assign('accountAcl', $this->accountAcl); if ($this->accountId) { $this->view->assign( 'deepLink', - Link::getDeepLink( - $this->accountId, - $this->actionId, - $this->configData - ) + Link::getDeepLink($this->accountId, $this->actionId, $this->configData) ); } } @@ -499,7 +397,7 @@ final class AccountHelper extends HelperBase $this->checkActionAccess(); - $userProfileData = $this->context->getUserProfile(); + $userProfileData = $this->context->getUserProfile() ?? new ProfileData(); $userData = $this->context->getUserData(); $this->accountAcl->setShowPermission( @@ -522,15 +420,11 @@ final class AccountHelper extends HelperBase $accountPermission = $itemPresetPermission->hydrate(AccountPermission::class) ?: $accountPermission; } - // FIXME: Use IoC - $selectUsers = SelectItemAdapter::factory(UserService::getItemsBasic()); - $selectUserGroups = SelectItemAdapter::factory(UserGroupService::getItemsBasic()); - $selectTags = SelectItemAdapter::factory(TagService::getItemsBasic()); + $selectUsers = SelectItemAdapter::factory($this->userService->getAllBasic()); + $selectUserGroups = SelectItemAdapter::factory($this->userGroupService->getAllBasic()); + $selectTags = SelectItemAdapter::factory($this->tagService->getAllBasic()); - $this->view->assign( - 'accountPassDateChange', - date('Y-m-d', time() + 7776000) - ); + $this->view->assign('accountPassDateChange', date('Y-m-d', time() + 7776000)); $this->view->assign( 'otherUsersView', $selectUsers->getItemsFromModelSelected($accountPermission->getUsersView()) @@ -547,34 +441,13 @@ final class AccountHelper extends HelperBase 'otherUserGroupsEdit', $selectUserGroups->getItemsFromModelSelected($accountPermission->getUserGroupsEdit()) ); - $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( - 'privateUserCheck', - $accountPrivate->isPrivateUser() - ); - $this->view->assign( - 'privateUserGroupCheck', - $accountPrivate->isPrivateGroup() - ); + $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('privateUserCheck', $accountPrivate->isPrivateUser()); + $this->view->assign('privateUserGroupCheck', $accountPrivate->isPrivateGroup()); $this->view->assign('accountId', 0); $this->view->assign('gotData', false); $this->view->assign( @@ -587,60 +460,4 @@ final class AccountHelper extends HelperBase $this->setViewCommon(); } - - /** - * Sets account's view variables - * - * @param AccountDetailsResponse $accountDetailsResponse - * @param int $actionId - * - * @return bool - * @throws \SP\Core\Acl\UnauthorizedPageException - * @throws \SP\Infrastructure\Common\Repositories\NoSuchItemException - * @throws \SP\Domain\Common\Services\ServiceException - * @throws \SP\Domain\User\Services\UpdatedMasterPassException - */ - public function setViewForRequest( - AccountDetailsResponse $accountDetailsResponse, - int $actionId - ): bool { - $this->accountId = $accountDetailsResponse->getAccountVData()->getId(); - $this->actionId = $actionId; - $this->accountAcl = new AccountAcl($actionId); - - $this->checkActionAccess(); - - $accountData = $accountDetailsResponse->getAccountVData(); - - $this->view->assign( - 'accountId', - $accountData->getId() - ); - $this->view->assign( - 'accountData', - $accountDetailsResponse->getAccountVData() - ); - - $this->view->assign( - 'accountActions', - $this->accountActionsHelper->getActionsForAccount( - $this->accountAcl, - new AccountActionsDto( - $this->accountId, - null, - $accountData->getParentId() - ) - ) - ); - - return true; - } - - /** - * @param bool $isView - */ - public function setIsView(bool $isView): void - { - $this->isView = $isView; - } } \ No newline at end of file diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHelperBase.php b/app/modules/web/Controllers/Helpers/Account/AccountHelperBase.php new file mode 100644 index 00000000..4b79573c --- /dev/null +++ b/app/modules/web/Controllers/Helpers/Account/AccountHelperBase.php @@ -0,0 +1,90 @@ +. + */ + +namespace SP\Modules\Web\Controllers\Helpers\Account; + + +use SP\Core\Acl\Acl; +use SP\Core\Acl\UnauthorizedPageException; +use SP\Core\Application; +use SP\Core\Exceptions\SPException; +use SP\Domain\Crypt\MasterPassServiceInterface; +use SP\Domain\User\Services\UpdatedMasterPassException; +use SP\Http\RequestInterface; +use SP\Infrastructure\Common\Repositories\NoSuchItemException; +use SP\Modules\Web\Controllers\Helpers\HelperBase; +use SP\Mvc\View\TemplateInterface; + +/** + * Class AccountHelperBase + */ +abstract class AccountHelperBase extends HelperBase +{ + protected ?int $actionId = null; + protected AccountActionsHelper $accountActionsHelper; + protected bool $isView = false; + private Acl $acl; + private MasterPassServiceInterface $masterPassService; + + public function __construct( + Application $application, + TemplateInterface $template, + RequestInterface $request, + Acl $acl, + AccountActionsHelper $accountActionsHelper, + MasterPassServiceInterface $masterPassService + ) { + parent::__construct($application, $template, $request); + + $this->acl = $acl; + $this->accountActionsHelper = $accountActionsHelper; + $this->masterPassService = $masterPassService; + } + + /** + * @param bool $isView + */ + public function setIsView(bool $isView): void + { + $this->isView = $isView; + } + + /** + * @throws NoSuchItemException + * @throws UnauthorizedPageException + * @throws UpdatedMasterPassException + * @throws \SP\Domain\Common\Services\ServiceException + */ + final protected function checkActionAccess(): void + { + if (!$this->acl->checkUserAccess($this->actionId)) { + throw new UnauthorizedPageException(SPException::INFO); + } + + if (!$this->masterPassService->checkUserUpdateMPass($this->context->getUserData()->getLastUpdateMPass()) + ) { + throw new UpdatedMasterPassException(SPException::INFO); + } + } +} \ No newline at end of file diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php index 8b6ba243..c9d5bb2f 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php @@ -26,7 +26,6 @@ namespace SP\Modules\Web\Controllers\Helpers\Account; use SP\Core\Acl\AccountPermissionException; use SP\Core\Acl\Acl; -use SP\Core\Acl\UnauthorizedPageException; use SP\Core\Application; use SP\Core\Exceptions\ConstraintException; use SP\Core\Exceptions\QueryException; @@ -34,13 +33,12 @@ use SP\Core\Exceptions\SPException; use SP\DataModel\AccountHistoryData; use SP\DataModel\Dto\AccountAclDto; use SP\Domain\Account\AccountAclServiceInterface; +use SP\Domain\Account\AccountHistoryServiceInterface; use SP\Domain\Account\Services\AccountAcl; -use SP\Domain\Category\Services\CategoryService; -use SP\Domain\Client\Services\ClientService; +use SP\Domain\Category\CategoryServiceInterface; +use SP\Domain\Client\ClientServiceInterface; use SP\Domain\Crypt\MasterPassServiceInterface; -use SP\Domain\User\Services\UpdatedMasterPassException; use SP\Http\RequestInterface; -use SP\Modules\Web\Controllers\Helpers\HelperBase; use SP\Mvc\View\Components\SelectItemAdapter; use SP\Mvc\View\TemplateInterface; @@ -49,34 +47,33 @@ use SP\Mvc\View\TemplateInterface; * * @package SP\Modules\Web\Controllers\Helpers */ -final class AccountHistoryHelper extends HelperBase +final class AccountHistoryHelper extends AccountHelperBase { - private Acl $acl; - private \SP\Domain\Account\AccountHistoryServiceInterface $accountHistoryService; - private AccountActionsHelper $accountActionsHelper; - private MasterPassServiceInterface $masterPassService; + private AccountHistoryServiceInterface $accountHistoryService; private AccountAclServiceInterface $accountAclService; private ?int $accountId = null; - private ?int $actionId = null; private ?AccountAcl $accountAcl = null; + private CategoryServiceInterface $categoryService; + private ClientServiceInterface $clientService; public function __construct( Application $application, TemplateInterface $template, RequestInterface $request, Acl $acl, - \SP\Domain\Account\AccountHistoryServiceInterface $accountHistoryService, + AccountHistoryServiceInterface $accountHistoryService, AccountActionsHelper $accountActionsHelper, MasterPassServiceInterface $masterPassService, - AccountAclServiceInterface $accountAclService + AccountAclServiceInterface $accountAclService, + CategoryServiceInterface $categoryService, + ClientServiceInterface $clientService ) { - $this->acl = $acl; - $this->accountHistoryService = $accountHistoryService; - $this->accountActionsHelper = $accountActionsHelper; - $this->masterPassService = $masterPassService; - $this->accountAclService = $accountAclService; + parent::__construct($application, $template, $request, $acl, $accountActionsHelper, $masterPassService); - parent::__construct($application, $template, $request); + $this->accountHistoryService = $accountHistoryService; + $this->accountAclService = $accountAclService; + $this->categoryService = $categoryService; + $this->clientService = $clientService; } @@ -84,15 +81,13 @@ final class AccountHistoryHelper extends HelperBase * @param AccountHistoryData $accountHistoryData * @param int $actionId * - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface * @throws \SP\Core\Acl\AccountPermissionException * @throws \SP\Core\Acl\UnauthorizedPageException * @throws \SP\Core\Exceptions\ConstraintException * @throws \SP\Core\Exceptions\QueryException - * @throws \SP\Infrastructure\Common\Repositories\NoSuchItemException * @throws \SP\Domain\Common\Services\ServiceException * @throws \SP\Domain\User\Services\UpdatedMasterPassException + * @throws \SP\Infrastructure\Common\Repositories\NoSuchItemException */ public function setView( AccountHistoryData $accountHistoryData, @@ -117,24 +112,19 @@ final class AccountHistoryHelper extends HelperBase ->getItemsFromArraySelected([$accountHistoryData->getId()]) ); - $this->view->assign( - 'accountPassDate', - date('Y-m-d H:i:s', $accountHistoryData->getPassDate()) - ); + $this->view->assign('accountPassDate', date('Y-m-d H:i:s', $accountHistoryData->getPassDate())); $this->view->assign( 'accountPassDateChange', date('Y-m-d', $accountHistoryData->getPassDateChange() ?: 0) ); $this->view->assign( 'categories', - // FIXME: use IoC - SelectItemAdapter::factory(CategoryService::getItemsBasic()) + SelectItemAdapter::factory($this->categoryService->getAllBasic()) ->getItemsFromModelSelected([$accountHistoryData->getCategoryId()]) ); $this->view->assign( 'clients', - // FIXME: use IoC - SelectItemAdapter::factory(ClientService::getItemsBasic()) + SelectItemAdapter::factory($this->clientService->getAllBasic()) ->getItemsFromModelSelected([$accountHistoryData->getClientId()]) ); $this->view->assign( @@ -158,23 +148,6 @@ final class AccountHistoryHelper extends HelperBase ); } - /** - * @throws \SP\Core\Acl\UnauthorizedPageException - * @throws \SP\Infrastructure\Common\Repositories\NoSuchItemException - * @throws \SP\Domain\Common\Services\ServiceException - * @throws \SP\Domain\User\Services\UpdatedMasterPassException - */ - protected function checkActionAccess(): void - { - if (!$this->acl->checkUserAccess($this->actionId)) { - throw new UnauthorizedPageException(SPException::INFO); - } - - if (!$this->masterPassService->checkUserUpdateMPass($this->context->getUserData()->getLastUpdateMPass())) { - throw new UpdatedMasterPassException(SPException::INFO); - } - } - /** * Comprobar si el usuario dispone de acceso al módulo * diff --git a/app/modules/web/Controllers/Helpers/Account/AccountRequestHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountRequestHelper.php new file mode 100644 index 00000000..e200008f --- /dev/null +++ b/app/modules/web/Controllers/Helpers/Account/AccountRequestHelper.php @@ -0,0 +1,76 @@ +. + */ + +namespace SP\Modules\Web\Controllers\Helpers\Account; + + +use SP\DataModel\Dto\AccountDetailsResponse; +use SP\Domain\Account\Services\AccountAcl; + +/** + * Class AccountRequestHelper + */ +final class AccountRequestHelper extends AccountHelperBase +{ + /** + * Sets account's view variables + * + * @param AccountDetailsResponse $accountDetailsResponse + * @param int $actionId + * + * @return bool + * @throws \SP\Core\Acl\UnauthorizedPageException + * @throws \SP\Infrastructure\Common\Repositories\NoSuchItemException + * @throws \SP\Domain\Common\Services\ServiceException + * @throws \SP\Domain\User\Services\UpdatedMasterPassException + */ + public function setViewForRequest( + AccountDetailsResponse $accountDetailsResponse, + int $actionId + ): bool { + $this->accountId = $accountDetailsResponse->getAccountVData()->getId(); + $this->actionId = $actionId; + $this->accountAcl = new AccountAcl($actionId); + + $this->checkActionAccess(); + + $accountData = $accountDetailsResponse->getAccountVData(); + + $this->view->assign('accountId', $accountData->getId()); + $this->view->assign('accountData', $accountDetailsResponse->getAccountVData()); + $this->view->assign( + 'accountActions', + $this->accountActionsHelper->getActionsForAccount( + $this->accountAcl, + new AccountActionsDto( + $this->accountId, + null, + $accountData->getParentId() + ) + ) + ); + + return true; + } +} \ No newline at end of file diff --git a/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php index b86e0049..7ac0c859 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php @@ -34,11 +34,12 @@ use SP\Core\Exceptions\QueryException; use SP\Core\Exceptions\SPException; use SP\DataModel\ProfileData; use SP\DataModel\UserPreferencesData; +use SP\Domain\Account\AccountSearchServiceInterface; use SP\Domain\Account\Services\AccountSearchFilter; use SP\Domain\Account\Services\AccountSearchItem; -use SP\Domain\Category\Services\CategoryService; +use SP\Domain\Category\CategoryServiceInterface; use SP\Domain\Client\ClientServiceInterface; -use SP\Domain\Tag\Services\TagService; +use SP\Domain\Tag\TagServiceInterface; use SP\Html\DataGrid\Action\DataGridAction; use SP\Html\DataGrid\Action\DataGridActionSearch; use SP\Html\DataGrid\DataGrid; @@ -62,27 +63,37 @@ final class AccountSearchHelper extends HelperBase * @var bool Indica si el filtrado de cuentas está activo */ private bool $filterOn = false; - private int $queryTimeStart = 0; private bool $isAjax = false; - private bool $isIndex = false; + private int $queryTimeStart; + private bool $isIndex; private ?AccountSearchFilter $accountSearchFilter = null; - private ClientServiceInterface $clientService; - private \SP\Domain\Account\AccountSearchServiceInterface $accountSearchService; - private AccountActionsHelper $accountActionsHelper; + private ClientServiceInterface $clientService; + private AccountSearchServiceInterface $accountSearchService; + private AccountActionsHelper $accountActionsHelper; + private CategoryServiceInterface $categoryService; + private TagServiceInterface $tagService; public function __construct( Application $application, TemplateInterface $template, RequestInterface $request, ClientServiceInterface $clientService, - \SP\Domain\Account\AccountSearchServiceInterface $accountSearchService, + CategoryServiceInterface $categoryService, + TagServiceInterface $tagService, + AccountSearchServiceInterface $accountSearchService, AccountActionsHelper $accountActionsHelper ) { parent::__construct($application, $template, $request); $this->clientService = $clientService; + $this->categoryService = $categoryService; + $this->tagService = $tagService; $this->accountSearchService = $accountSearchService; $this->accountActionsHelper = $accountActionsHelper; + + $this->queryTimeStart = microtime(true); + $this->isIndex = $this->request->analyzeString('r') === Acl::getActionRoute(ActionsInterface::ACCOUNT); + $this->setVars(); } /** @@ -104,12 +115,12 @@ final class AccountSearchHelper extends HelperBase ); $this->view->assign( 'categories', - SelectItemAdapter::factory(CategoryService::getItemsBasic()) + SelectItemAdapter::factory($this->categoryService->getAllBasic()) ->getItemsFromModelSelected([$this->accountSearchFilter->getCategoryId()]) ); $this->view->assign( 'tags', - SelectItemAdapter::factory(TagService::getItemsBasic()) + SelectItemAdapter::factory($this->tagService->getAllBasic()) ->getItemsFromModelSelected($this->accountSearchFilter->getTagsId()) ); } @@ -306,16 +317,6 @@ final class AccountSearchHelper extends HelperBase return $gridHeaderSort; } - /** - * Initialize - */ - protected function initialize(): void - { - $this->queryTimeStart = microtime(true); - $this->isIndex = $this->request->analyzeString('r') === Acl::getActionRoute(ActionsInterface::ACCOUNT); - $this->setVars(); - } - /** * Establecer las variables necesarias para las plantillas */ diff --git a/app/modules/web/Controllers/Helpers/HelperBase.php b/app/modules/web/Controllers/Helpers/HelperBase.php index 7a8596b6..355b457b 100644 --- a/app/modules/web/Controllers/Helpers/HelperBase.php +++ b/app/modules/web/Controllers/Helpers/HelperBase.php @@ -65,9 +65,5 @@ abstract class HelperBase $this->request = $request; $this->configData = $this->config->getConfigData(); $this->view = $template; - - if (method_exists($this, 'initialize')) { - $this->initialize(); - } } } \ No newline at end of file