refactor: Improve Account helper hierarchy.

Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
Rubén D
2022-06-12 21:55:29 +02:00
parent 0a6f7e4853
commit 8130582df1
8 changed files with 365 additions and 539 deletions

View File

@@ -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
);

View File

@@ -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();
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,90 @@
<?php
/*
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/
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);
}
}
}

View File

@@ -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
*

View File

@@ -0,0 +1,76 @@
<?php
/*
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@@ -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
*/

View File

@@ -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();
}
}
}