diff --git a/app/modules/web/Controllers/AccountController.php b/app/modules/web/Controllers/AccountController.php
index 9d3f8c70..0d778284 100644
--- a/app/modules/web/Controllers/AccountController.php
+++ b/app/modules/web/Controllers/AccountController.php
@@ -35,14 +35,14 @@ use SP\DataModel\AccountExtData;
use SP\Forms\AccountForm;
use SP\Http\JsonResponse;
use SP\Http\Request;
-use SP\Modules\Web\Controllers\Helpers\AccountHelper;
-use SP\Modules\Web\Controllers\Helpers\AccountPasswordHelper;
-use SP\Modules\Web\Controllers\Helpers\AccountSearchHelper;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountHelper;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountHistoryHelper;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountPasswordHelper;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountSearchHelper;
use SP\Modules\Web\Controllers\Helpers\LayoutHelper;
use SP\Modules\Web\Controllers\Traits\ItemTrait;
use SP\Modules\Web\Controllers\Traits\JsonTrait;
use SP\Mvc\Controller\CrudControllerInterface;
-use SP\Repositories\PublicLink\PublicLinkRepository;
use SP\Services\Account\AccountFileService;
use SP\Services\Account\AccountHistoryService;
use SP\Services\Account\AccountService;
@@ -73,9 +73,9 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
public function indexAction()
{
try {
- $AccountSearchHelper = new AccountSearchHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
- $AccountSearchHelper->getSearchBox();
- $AccountSearchHelper->getAccountSearch();
+ $accountSearchHelper = new AccountSearchHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
+ $accountSearchHelper->getSearchBox();
+ $accountSearchHelper->getAccountSearch();
$this->eventDispatcher->notifyEvent('show.account.search', $this);
} catch (\Exception $e) {
@@ -127,15 +127,9 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
->withUserGroupsById($accountDetailsResponse)
->withTagsById($accountDetailsResponse);
- $AccountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
-
- if (!$AccountHelper->setAccount(
- $accountDetailsResponse,
- $this->accountService,
- ActionsInterface::ACCOUNT_VIEW
- )) {
- return;
- }
+ $accountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
+ $accountHelper->setIsView(true);
+ $accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_VIEW);
$this->view->addTemplate('account');
$this->view->assign('title',
@@ -146,12 +140,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
]
);
- $this->view->assign('isView', true);
-
$this->accountService->incrementViewCounter($id);
- $AccountHelper->setCommonData();
-
$this->eventDispatcher->notifyEvent('show.account', $this);
} catch (\Exception $e) {
debugLog($e->getMessage(), true);
@@ -170,8 +160,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
*/
public function viewLinkAction($hash)
{
- $LayoutHelper = new LayoutHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
- $LayoutHelper->getPublicLayout('account-link', 'account');
+ $layoutHelper = new LayoutHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
+ $layoutHelper->getPublicLayout('account-link', 'account');
try {
$publicLinkService = new PublicLinkService();
@@ -259,13 +249,11 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
$this->view->addTemplate('files-list', 'account');
$this->view->assign('deleteEnabled', Request::analyze('del', 0));
-
$this->view->assign('files', (new AccountFileService())->getByAccountId($id));
$this->view->assign('sk', SessionUtil::getSessionKey());
$this->view->assign('fileViewRoute', Acl::getActionRoute(ActionsInterface::ACCOUNT_FILE_VIEW));
$this->view->assign('fileDownloadRoute', Acl::getActionRoute(ActionsInterface::ACCOUNT_FILE_DOWNLOAD));
$this->view->assign('fileDeleteRoute', Acl::getActionRoute(ActionsInterface::ACCOUNT_FILE_DELETE));
- $this->view->assign('fileUploadRoute', Acl::getActionRoute(ActionsInterface::ACCOUNT_FILE_UPLOAD));
if (!is_array($this->view->files) || count($this->view->files) === 0) {
return;
@@ -287,13 +275,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
public function createAction()
{
try {
- $AccountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
- $AccountHelper->setActionId(ActionsInterface::ACCOUNT_CREATE);
-
- // Obtener los datos de la cuenta antes y comprobar el acceso
- if (!$AccountHelper->checkAccess()) {
- return;
- }
+ $accountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
+ $accountHelper->setViewForBlank(ActionsInterface::ACCOUNT_CREATE);
$this->view->addTemplate('account');
$this->view->assign('title',
@@ -305,8 +288,6 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
);
$this->view->assign('formRoute', 'account/saveCreate');
- $AccountHelper->setCommonData();
-
$this->eventDispatcher->notifyEvent('show.account.create', $this);
} catch (\Exception $e) {
debugLog($e->getMessage(), true);
@@ -331,15 +312,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
->withUserGroupsById($accountDetailsResponse)
->withTagsById($accountDetailsResponse);
- $AccountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
-
- if (!$AccountHelper->setAccount(
- $accountDetailsResponse,
- $this->accountService,
- ActionsInterface::ACCOUNT_COPY
- )) {
- return;
- }
+ $accountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
+ $accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_COPY);
$this->view->addTemplate('account');
$this->view->assign('title',
@@ -351,8 +325,6 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
);
$this->view->assign('formRoute', 'account/saveCopy');
- $AccountHelper->setCommonData();
-
$this->eventDispatcher->notifyEvent('show.account.copy', $this);
} catch (\Exception $e) {
debugLog($e->getMessage(), true);
@@ -377,15 +349,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
->withUserGroupsById($accountDetailsResponse)
->withTagsById($accountDetailsResponse);
- $AccountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
-
- if (!$AccountHelper->setAccount(
- $accountDetailsResponse,
- $this->accountService,
- ActionsInterface::ACCOUNT_EDIT
- )) {
- return;
- }
+ $accountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
+ $accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_EDIT);
$this->view->addTemplate('account');
$this->view->assign('title',
@@ -396,11 +361,10 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
]
);
$this->view->assign('formRoute', 'account/saveEdit');
+ $this->view->assign(__FUNCTION__);
$this->accountService->incrementViewCounter($id);
- $AccountHelper->setCommonData();
-
$this->eventDispatcher->notifyEvent('show.account.edit', $this);
} catch (\Exception $e) {
debugLog($e->getMessage(), true);
@@ -424,15 +388,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
->withUsersById($accountDetailsResponse)
->withUserGroupsById($accountDetailsResponse);
- $AccountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
-
- if (!$AccountHelper->setAccount(
- $accountDetailsResponse,
- $this->accountService,
- ActionsInterface::ACCOUNT_DELETE
- )) {
- return;
- }
+ $accountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
+ $accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_DELETE);
$this->view->addTemplate('account');
$this->view->assign('title',
@@ -444,8 +401,6 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
);
$this->view->assign('formRoute', 'account/saveDelete');
- $AccountHelper->setCommonData();
-
$this->eventDispatcher->notifyEvent('show.account.delete', $this);
} catch (\Exception $e) {
debugLog($e->getMessage(), true);
@@ -469,15 +424,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
->withUsersById($accountDetailsResponse)
->withUserGroupsById($accountDetailsResponse);
- $AccountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
-
- if (!$AccountHelper->setAccount(
- $accountDetailsResponse,
- $this->accountService,
- ActionsInterface::ACCOUNT_EDIT_PASS
- )) {
- return;
- }
+ $accountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
+ $accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_EDIT_PASS);
$this->view->addTemplate('account-editpass');
$this->view->assign('title',
@@ -489,7 +437,7 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
);
$this->view->assign('formRoute', 'account/saveEditPass');
- $this->view->assign('accountPassDateChange', gmdate('Y-m-d', $AccountHelper->getAccountDetailsResponse()->getAccountVData()->getPassDateChange()));
+ $this->view->assign('accountPassDateChange', gmdate('Y-m-d', $accountDetailsResponse->getAccountVData()->getPassDateChange()));
$this->eventDispatcher->notifyEvent('show.account.editpass', $this);
} catch (\Exception $e) {
@@ -512,15 +460,8 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
$accountHistoryService = new AccountHistoryService();
$accountHistoryData = $accountHistoryService->getById($id);
- $AccountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
-
- if (!$AccountHelper->setAccountHistory(
- $accountHistoryService,
- $accountHistoryData,
- ActionsInterface::ACCOUNT_VIEW_HISTORY)
- ) {
- return;
- }
+ $accountHistoryHelper = new AccountHistoryHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
+ $accountHistoryHelper->setView($accountHistoryData, ActionsInterface::ACCOUNT_VIEW_HISTORY);
$this->view->addTemplate('account-history');
@@ -533,7 +474,6 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
);
$this->view->assign('formRoute', 'account/saveRestore');
- $this->view->assign('isView', true);
$this->eventDispatcher->notifyEvent('show.account.history', $this);
} catch (\Exception $e) {
@@ -553,12 +493,9 @@ class AccountController extends ControllerBase implements CrudControllerInterfac
public function requestAccessAction($id)
{
try {
- $AccountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
- $AccountHelper->setAccount(
- $this->accountService->getById($id),
- $this->accountService,
- ActionsInterface::ACCOUNT_REQUEST
- );
+ $accountHelper = new AccountHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
+ $accountHelper->setIsView(true);
+ $accountHelper->setViewForRequest($this->accountService->getById($id), ActionsInterface::ACCOUNT_REQUEST);
$this->view->addTemplate('account-request');
$this->view->assign('formRoute', 'account/saveRequest');
diff --git a/app/modules/web/Controllers/Helpers/Account/AccountActionsDto.php b/app/modules/web/Controllers/Helpers/Account/AccountActionsDto.php
new file mode 100644
index 00000000..8b58f217
--- /dev/null
+++ b/app/modules/web/Controllers/Helpers/Account/AccountActionsDto.php
@@ -0,0 +1,120 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Helpers\Account;
+
+/**
+ * Class AccountActionsDto
+ *
+ * @package SP\Modules\Web\Controllers\Helpers\Account
+ */
+class AccountActionsDto
+{
+ /**
+ * @var int
+ */
+ private $accountId;
+ /**
+ * @var int
+ */
+ private $accountHistoryId;
+ /**
+ * @var int
+ */
+ private $accountParentId;
+ /**
+ * @var bool
+ */
+ private $publicLink = false;
+
+ /**
+ * AccountActionsDto constructor.
+ *
+ * @param int $accountId
+ * @param int $accountHistoryId
+ * @param int $accountParentId
+ */
+ public function __construct($accountId, $accountHistoryId = null, $accountParentId = null)
+ {
+ $this->accountId = $accountId;
+ $this->accountHistoryId = $accountHistoryId;
+ $this->accountParentId = $accountParentId;
+ }
+
+ /**
+ * @return int
+ */
+ public function getAccountId()
+ {
+ return $this->accountId;
+ }
+
+ /**
+ * @return int
+ */
+ public function getAccountHistoryId()
+ {
+ return $this->accountHistoryId;
+ }
+
+ /**
+ * @return int
+ */
+ public function getAccountParentId()
+ {
+ return $this->accountParentId;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isHistory()
+ {
+ return $this->accountHistoryId !== null;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isLinked()
+ {
+ return $this->accountParentId !== null;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasPublicLink()
+ {
+ return $this->publicLink;
+ }
+
+ /**
+ * @param bool $publicLink
+ */
+ public function setPublicLink($publicLink)
+ {
+ $this->publicLink = (bool)$publicLink;
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Helpers/AccountActionsHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountActionsHelper.php
similarity index 65%
rename from app/modules/web/Controllers/Helpers/AccountActionsHelper.php
rename to app/modules/web/Controllers/Helpers/Account/AccountActionsHelper.php
index 145f2c3e..a08c25ff 100644
--- a/app/modules/web/Controllers/Helpers/AccountActionsHelper.php
+++ b/app/modules/web/Controllers/Helpers/Account/AccountActionsHelper.php
@@ -1,13 +1,37 @@
.
+ */
-namespace SP\Modules\Web\Controllers\Helpers;
+namespace SP\Modules\Web\Controllers\Helpers\Account;
+use SP\Account\AccountAcl;
use SP\Account\AccountSearchItem;
use SP\Core\Acl\Acl;
use SP\Core\Acl\ActionsInterface;
use SP\Core\UI\ThemeIconsBase;
use SP\Html\DataGrid\DataGridAction;
use SP\Html\DataGrid\DataGridActionType;
+use SP\Modules\Web\Controllers\Helpers\HelperBase;
/**
* Class AccountIconsHelper
@@ -20,6 +44,10 @@ class AccountActionsHelper extends HelperBase
* @var ThemeIconsBase
*/
protected $icons;
+ /**
+ * @var string
+ */
+ protected $sk;
/**
* @return DataGridAction
@@ -35,13 +63,184 @@ class AccountActionsHelper extends HelperBase
$action->setIcon($this->icons->getIconView());
$action->setReflectionFilter(AccountSearchItem::class, 'isShowView');
$action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW));
- $action->addData('action-sk', $this->view->sk);
+ $action->addData('action-sk', $this->sk);
$action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW));
$action->addAttribute('type', 'button');
return $action;
}
+ /**
+ * Set icons for view
+ *
+ * @param AccountAcl $accountAcl
+ * @param AccountActionsDto $accountActionsDto
+ * @return DataGridAction[]
+ */
+ public function getActionsForAccount(AccountAcl $accountAcl, AccountActionsDto $accountActionsDto)
+ {
+ $actionsEnabled = [];
+
+ $actionBack = $this->getBackAction();
+
+ if ($accountActionsDto->isHistory()) {
+ $actionBack->addData('item-id', $accountActionsDto->getAccountId());
+ $actionBack->setName(__('Ver Actual'));
+ $actionBack->setTitle(__('Ver Actual'));
+ } else {
+ $actionBack->setData([]);
+ $actionBack->setClasses(['btn-back']);
+ }
+
+ $actionsEnabled[] = $actionBack;
+
+ if ($accountAcl->isShowDelete()) {
+ $actionsEnabled[] = $this->getDeleteAction()->addData('item-id', $accountActionsDto->getAccountId());
+ }
+
+ if ($accountActionsDto->isHistory() === false
+ && $accountActionsDto->isLinked() === false
+ && $accountAcl->isShowLink()
+ && $accountAcl->isShowViewPass()
+ ) {
+ $actionsEnabled[] = $accountActionsDto->hasPublicLink() ? $this->getPublicLinkRefreshAction() : $this->getPublicLinkAction();
+ }
+
+ if ($accountAcl->isShowViewPass()) {
+ $actionViewPass = $this->getViewPassAction();
+ $actionCopy = $this->getCopyPassAction();
+
+ $actionViewPass->addData('parent-id', $accountActionsDto->getAccountParentId());
+ $actionCopy->addData('parent-id', $accountActionsDto->getAccountParentId());
+
+ $actionViewPass->addData('history', (int)$accountActionsDto->isHistory());
+ $actionCopy->addData('history', (int)$accountActionsDto->isHistory());
+
+ if ($accountActionsDto->isHistory()) {
+ $actionViewPass->addData('item-id', $accountActionsDto->getAccountHistoryId());
+ $actionCopy->addData('item-id', $accountActionsDto->getAccountHistoryId());
+ } else {
+ $actionViewPass->addData('item-id', $accountActionsDto->getAccountId());
+ $actionCopy->addData('item-id', $accountActionsDto->getAccountId());
+ }
+
+ $actionsEnabled[] = $actionViewPass;
+ $actionsEnabled[] = $actionCopy;
+ }
+
+ if ($accountAcl->isShowCopy()) {
+ $actionsEnabled[] = $this->getCopyAction()->addData('item-id', $accountActionsDto->getAccountId());
+ }
+
+ if ($accountAcl->isShowEditPass()) {
+ $actionsEnabled[] = $this->getEditPassAction()->addData('item-id', $accountActionsDto->getAccountId());
+ }
+
+ if ($accountAcl->isShowEdit()) {
+ $actionsEnabled[] = $this->getEditAction()->addData('item-id', $accountActionsDto->getAccountId());
+ }
+
+ if ($accountAcl->getAction() === ActionsInterface::ACCOUNT_VIEW
+ && !$accountAcl->isShowEdit()
+ && $this->configData->isMailRequestsEnabled()
+ ) {
+ $actionsEnabled[] = $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());
+
+ $actionsEnabled[] = $actionRestore;
+ }
+
+ if ($accountAcl->isShowSave()) {
+ $actionsEnabled[] = $this->getSaveAction()->addAttribute('form', 'frmAccount');
+ }
+
+ return $actionsEnabled;
+ }
+
+ /**
+ * @return DataGridAction
+ */
+ public function getBackAction()
+ {
+ $action = new DataGridAction();
+ $action->setId('btnBack');
+ $action->setName(__('Atrás'));
+ $action->setTitle(__('Atrás'));
+ $action->addClass('btn-action');
+ $action->setIcon($this->icons->getIconBack());
+ $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW));
+ $action->addData('action-sk', $this->sk);
+ $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW));
+ $action->addAttribute('type', 'button');
+
+ return $action;
+ }
+
+ /**
+ * @return DataGridAction
+ */
+ public function getDeleteAction()
+ {
+ $action = new DataGridAction();
+ $action->setId(ActionsInterface::ACCOUNT_DELETE);
+ $action->setType(DataGridActionType::DELETE_ITEM);
+ $action->setName(__('Eliminar Cuenta'));
+ $action->setTitle(__('Eliminar Cuenta'));
+ $action->addClass('btn-action');
+ $action->setIcon($this->icons->getIconDelete());
+ $action->setReflectionFilter(AccountSearchItem::class, 'isShowDelete');
+ $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_DELETE));
+ $action->addData('action-sk', $this->sk);
+ $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_DELETE));
+ $action->addAttribute('type', 'button');
+
+ return $action;
+ }
+
+ /**
+ * @return DataGridAction
+ */
+ public function getPublicLinkRefreshAction()
+ {
+ $action = new DataGridAction();
+ $action->setId(ActionsInterface::PUBLICLINK_REFRESH);
+ $action->setName(__('Actualizar Enlace Público'));
+ $action->setTitle(__('Actualizar Enlace Público'));
+ $action->setIcon($this->icons->getIconPublicLink());
+ $action->addData('action-route', Acl::getActionRoute(ActionsInterface::PUBLICLINK_REFRESH));
+ $action->addData('action-sk', $this->sk);
+ $action->addData('onclick', 'link/refresh');
+ $action->addData('action-next', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW));
+ $action->addAttribute('type', 'button');
+
+ return $action;
+ }
+
+ /**
+ * @return DataGridAction
+ */
+ public function getPublicLinkAction()
+ {
+ $action = new DataGridAction();
+ $action->setId(ActionsInterface::PUBLICLINK_CREATE);
+ $action->setName(__('Crear Enlace Público'));
+ $action->setTitle(__('Crear Enlace Público'));
+ $action->addClass('btn-action');
+ $action->setIcon($this->icons->getIconPublicLink());
+ $action->addData('action-route', Acl::getActionRoute(ActionsInterface::PUBLICLINK_CREATE));
+ $action->addData('action-sk', $this->sk);
+ $action->addData('onclick', 'link/save');
+ $action->addData('action-next', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW));
+ $action->addAttribute('type', 'button');
+
+ return $action;
+ }
+
/**
* @return DataGridAction
*/
@@ -57,74 +256,13 @@ class AccountActionsHelper extends HelperBase
$action->setReflectionFilter(AccountSearchItem::class, 'isShowViewPass');
$action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW_PASS));
$action->addData('action-full', 1);
- $action->addData('action-sk', $this->view->sk);
+ $action->addData('action-sk', $this->sk);
$action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW_PASS));
$action->addAttribute('type', 'button');
return $action;
}
- /**
- * @return DataGridAction
- */
- public function getEditPassAction()
- {
- $action = new DataGridAction();
- $action->setId(ActionsInterface::ACCOUNT_EDIT_PASS);
- $action->setType(DataGridActionType::VIEW_ITEM);
- $action->setName(__('Modificar Clave de Cuenta'));
- $action->setTitle(__('Modificar Clave de Cuenta'));
- $action->addClass('btn-action');
- $action->setIcon($this->icons->getIconEditPass());
- $action->setReflectionFilter(AccountSearchItem::class, 'isShowViewPass');
- $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT_PASS));
- $action->addData('action-sk', $this->view->sk);
- $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT_PASS));
- $action->addAttribute('type', 'button');
-
- return $action;
- }
-
- /**
- * @return DataGridAction
- */
- public function getRestoreAction()
- {
- $action = new DataGridAction();
- $action->setId(ActionsInterface::ACCOUNT_EDIT_RESTORE);
- $action->setType(DataGridActionType::VIEW_ITEM);
- $action->setName(__('Restaurar cuenta desde este punto'));
- $action->setTitle(__('Restaurar cuenta desde este punto'));
- $action->addClass('btn-action');
- $action->setIcon($this->icons->getIconRestore());
- $action->addData('action-route', 'account/saveEditRestore');
- $action->addData('action-sk', $this->view->sk);
- $action->addData('onclick', 'account/saveEditRestore');
- $action->addAttribute('type', 'button');
-
- return $action;
- }
-
- /**
- * @return DataGridAction
- */
- public function getSaveAction()
- {
- $action = new DataGridAction();
- $action->setId(ActionsInterface::ACCOUNT);
- $action->setType(DataGridActionType::VIEW_ITEM);
- $action->setName(__('Guardar'));
- $action->setTitle(__('Guardar'));
- $action->addClass('btn-action');
- $action->setIcon($this->icons->getIconSave());
- $action->addData('action-route', 'account/save');
- $action->addData('action-sk', $this->view->sk);
- $action->addData('onclick', 'account/save');
- $action->addAttribute('type', 'submit');
-
- return $action;
- }
-
/**
* @return DataGridAction
*/
@@ -143,73 +281,13 @@ class AccountActionsHelper extends HelperBase
$action->setReflectionFilter(AccountSearchItem::class, 'isShowCopyPass');
$action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_COPY_PASS));
$action->addData('action-full', 0);
- $action->addData('action-sk', $this->view->sk);
+ $action->addData('action-sk', $this->sk);
$action->addData('useclipboard', '1');
$action->addAttribute('type', 'button');
return $action;
}
- /**
- * @return DataGridAction
- */
- public function getEditAction()
- {
- $action = new DataGridAction();
- $action->setId(ActionsInterface::ACCOUNT_EDIT);
- $action->setType(DataGridActionType::EDIT_ITEM);
- $action->setName(__('Editar Cuenta'));
- $action->setTitle(__('Editar Cuenta'));
- $action->addClass('btn-action');
- $action->setIcon($this->icons->getIconEdit());
- $action->setReflectionFilter(AccountSearchItem::class, 'isShowEdit');
- $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT));
- $action->addData('action-sk', $this->view->sk);
- $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT));
- $action->addAttribute('type', 'button');
-
- return $action;
- }
-
- /**
- * @return DataGridAction
- */
- public function getPublicLinkAction()
- {
- $action = new DataGridAction();
- $action->setId(ActionsInterface::PUBLICLINK_CREATE);
- $action->setName(__('Crear Enlace Público'));
- $action->setTitle(__('Crear Enlace Público'));
- $action->addClass('btn-action');
- $action->setIcon($this->icons->getIconPublicLink());
- $action->addData('action-route', Acl::getActionRoute(ActionsInterface::PUBLICLINK_CREATE));
- $action->addData('action-sk', $this->view->sk);
- $action->addData('onclick', 'link/save');
- $action->addData('action-next', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW));
- $action->addAttribute('type', 'button');
-
- return $action;
- }
-
- /**
- * @return DataGridAction
- */
- public function getPublicLinkRefreshAction()
- {
- $action = new DataGridAction();
- $action->setId(ActionsInterface::PUBLICLINK_REFRESH);
- $action->setName(__('Actualizar Enlace Público'));
- $action->setTitle(__('Actualizar Enlace Público'));
- $action->setIcon($this->icons->getIconPublicLink());
- $action->addData('action-route', Acl::getActionRoute(ActionsInterface::PUBLICLINK_REFRESH));
- $action->addData('action-sk', $this->view->sk);
- $action->addData('onclick', 'link/refresh');
- $action->addData('action-next', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW));
- $action->addAttribute('type', 'button');
-
- return $action;
- }
-
/**
* @return DataGridAction
*/
@@ -224,7 +302,7 @@ class AccountActionsHelper extends HelperBase
$action->setIcon($this->icons->getIconCopy());
$action->setReflectionFilter(AccountSearchItem::class, 'isShowCopy');
$action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_COPY));
- $action->addData('action-sk', $this->view->sk);
+ $action->addData('action-sk', $this->sk);
$action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_COPY));
$action->addAttribute('type', 'button');
@@ -234,19 +312,40 @@ class AccountActionsHelper extends HelperBase
/**
* @return DataGridAction
*/
- public function getDeleteAction()
+ public function getEditPassAction()
{
$action = new DataGridAction();
- $action->setId(ActionsInterface::ACCOUNT_DELETE);
- $action->setType(DataGridActionType::DELETE_ITEM);
- $action->setName(__('Eliminar Cuenta'));
- $action->setTitle(__('Eliminar Cuenta'));
+ $action->setId(ActionsInterface::ACCOUNT_EDIT_PASS);
+ $action->setType(DataGridActionType::VIEW_ITEM);
+ $action->setName(__('Modificar Clave de Cuenta'));
+ $action->setTitle(__('Modificar Clave de Cuenta'));
$action->addClass('btn-action');
- $action->setIcon($this->icons->getIconDelete());
- $action->setReflectionFilter(AccountSearchItem::class, 'isShowDelete');
- $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_DELETE));
- $action->addData('action-sk', $this->view->sk);
- $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_DELETE));
+ $action->setIcon($this->icons->getIconEditPass());
+ $action->setReflectionFilter(AccountSearchItem::class, 'isShowViewPass');
+ $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT_PASS));
+ $action->addData('action-sk', $this->sk);
+ $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT_PASS));
+ $action->addAttribute('type', 'button');
+
+ return $action;
+ }
+
+ /**
+ * @return DataGridAction
+ */
+ public function getEditAction()
+ {
+ $action = new DataGridAction();
+ $action->setId(ActionsInterface::ACCOUNT_EDIT);
+ $action->setType(DataGridActionType::EDIT_ITEM);
+ $action->setName(__('Editar Cuenta'));
+ $action->setTitle(__('Editar Cuenta'));
+ $action->addClass('btn-action');
+ $action->setIcon($this->icons->getIconEdit());
+ $action->setReflectionFilter(AccountSearchItem::class, 'isShowEdit');
+ $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT));
+ $action->addData('action-sk', $this->sk);
+ $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT));
$action->addAttribute('type', 'button');
return $action;
@@ -265,7 +364,7 @@ class AccountActionsHelper extends HelperBase
$action->setIcon($this->icons->getIconEmail());
$action->setReflectionFilter(AccountSearchItem::class, 'isShowRequest');
$action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_REQUEST));
- $action->addData('action-sk', $this->view->sk);
+ $action->addData('action-sk', $this->sk);
$action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW));
$action->addAttribute('type', 'submit');
@@ -275,27 +374,49 @@ class AccountActionsHelper extends HelperBase
/**
* @return DataGridAction
*/
- public function getBackAction()
+ public function getRestoreAction()
{
$action = new DataGridAction();
- $action->setId('btnBack');
- $action->setName(__('Atrás'));
- $action->setTitle(__('Atrás'));
+ $action->setId(ActionsInterface::ACCOUNT_EDIT_RESTORE);
+ $action->setType(DataGridActionType::VIEW_ITEM);
+ $action->setName(__('Restaurar cuenta desde este punto'));
+ $action->setTitle(__('Restaurar cuenta desde este punto'));
$action->addClass('btn-action');
- $action->setIcon($this->icons->getIconBack());
- $action->addData('action-route', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW));
- $action->addData('action-sk', $this->view->sk);
- $action->addData('onclick', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW));
+ $action->setIcon($this->icons->getIconRestore());
+ $action->addData('action-route', 'account/saveEditRestore');
+ $action->addData('action-sk', $this->sk);
+ $action->addData('onclick', 'account/saveEditRestore');
$action->addAttribute('type', 'button');
return $action;
}
+ /**
+ * @return DataGridAction
+ */
+ public function getSaveAction()
+ {
+ $action = new DataGridAction();
+ $action->setId(ActionsInterface::ACCOUNT);
+ $action->setType(DataGridActionType::VIEW_ITEM);
+ $action->setName(__('Guardar'));
+ $action->setTitle(__('Guardar'));
+ $action->addClass('btn-action');
+ $action->setIcon($this->icons->getIconSave());
+ $action->addData('action-route', 'account/save');
+ $action->addData('action-sk', $this->sk);
+ $action->addData('onclick', 'account/save');
+ $action->addAttribute('type', 'submit');
+
+ return $action;
+ }
+
/**
* Initialize class
*/
protected function initialize()
{
+ $this->sk = $this->session->generateSecurityKey();
$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
new file mode 100644
index 00000000..74bb8e92
--- /dev/null
+++ b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php
@@ -0,0 +1,337 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Helpers\Account;
+
+use SP\Account\AccountAcl;
+use SP\Core\Acl\Acl;
+use SP\Core\Acl\ActionsInterface;
+use SP\Core\Acl\UnauthorizedPageException;
+use SP\Core\Exceptions\SPException;
+use SP\DataModel\Dto\AccountAclDto;
+use SP\DataModel\Dto\AccountDetailsResponse;
+use SP\Mgmt\Users\UserPass;
+use SP\Modules\Web\Controllers\Helpers\HelperBase;
+use SP\Modules\Web\Controllers\Traits\ItemTrait;
+use SP\Mvc\View\Components\SelectItemAdapter;
+use SP\Services\Account\AccountHistoryService;
+use SP\Services\Account\AccountService;
+use SP\Services\Category\CategoryService;
+use SP\Services\Client\ClientService;
+use SP\Services\PublicLink\PublicLinkService;
+use SP\Services\Tag\TagService;
+use SP\Services\User\UpdatedMasterPassException;
+use SP\Services\User\UserService;
+use SP\Services\UserGroup\UserGroupService;
+use SP\Util\ErrorUtil;
+
+/**
+ * Class AccountHelper
+ *
+ * @package SP\Modules\Web\Controllers\Helpers
+ */
+class AccountHelper extends HelperBase
+{
+ use ItemTrait;
+
+ /**
+ * @var Acl
+ */
+ protected $acl;
+ /**
+ * @var AccountService
+ */
+ protected $accountService;
+ /**
+ * @var AccountHistoryService
+ */
+ protected $accountHistoryService;
+ /**
+ * @var PublicLinkService
+ */
+ protected $publicLinkService;
+ /**
+ * @var string
+ */
+ private $actionId;
+ /**
+ * @var AccountAcl
+ */
+ private $accountAcl;
+ /**
+ * @var int con el Id de la cuenta
+ */
+ private $accountId;
+ /**
+ * @var bool
+ */
+ private $isView = false;
+
+ /**
+ * @param Acl $acl
+ * @param AccountService $accountService
+ * @param AccountHistoryService $accountHistoryService
+ * @param PublicLinkService $publicLinkService
+ */
+ public function inject(Acl $acl,
+ AccountService $accountService,
+ AccountHistoryService $accountHistoryService,
+ PublicLinkService $publicLinkService
+ )
+ {
+ $this->acl = $acl;
+ $this->accountService = $accountService;
+ $this->accountHistoryService = $accountHistoryService;
+ $this->publicLinkService = $publicLinkService;
+ }
+
+ /**
+ * Sets account's view variables
+ *
+ * @param AccountDetailsResponse $accountDetailsResponse
+ * @param int $actionId
+ * @throws SPException
+ * @throws UnauthorizedPageException
+ * @throws UpdatedMasterPassException
+ * @throws \SP\Core\Dic\ContainerException
+ */
+ public function setViewForAccount(AccountDetailsResponse $accountDetailsResponse, $actionId)
+ {
+ $this->accountId = $accountDetailsResponse->getAccountVData()->getId();
+ $this->actionId = $actionId;
+ $this->accountAcl = new AccountAcl($actionId);
+
+ $this->checkActionAccess();
+ $this->checkAccess($accountDetailsResponse);
+
+ $accountData = $accountDetailsResponse->getAccountVData();
+ $selectUsers = SelectItemAdapter::factory(UserService::getItemsBasic());
+ $selectUserGroups = SelectItemAdapter::factory(UserGroupService::getItemsBasic());
+ $selectTags = SelectItemAdapter::factory(TagService::getItemsBasic());
+
+ $this->view->assign('otherUsers', $selectUsers->getItemsFromModelSelected(SelectItemAdapter::getIdFromArrayOfObjects($accountDetailsResponse->getUsers()), $accountData->getUserId()));
+ $this->view->assign('otherUserGroups', $selectUserGroups->getItemsFromModelSelected(SelectItemAdapter::getIdFromArrayOfObjects($accountDetailsResponse->getUserGroups()), $accountData->getUserGroupId()));
+ $this->view->assign('userGroups', $selectUserGroups->getItemsFromModelSelected([$accountData->getUserGroupId()]));
+ $this->view->assign('tags', $selectTags->getItemsFromModelSelected(SelectItemAdapter::getIdFromArrayOfObjects($accountDetailsResponse->getTags())));
+
+ $this->view->assign('historyData', $this->accountHistoryService->getHistoryForAccount($this->accountId));
+
+ $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()) {
+ $publicLinkData = $this->publicLinkService->getHashForItem($this->accountId);
+
+ $publicLinkUrl = $publicLinkData ? PublicLinkService::getLinkForHash($publicLinkData->getHash()) : null;
+ $this->view->assign('publicLinkUrl', $publicLinkUrl);
+ $this->view->assign('publicLinkId', $publicLinkData ? $publicLinkData->getId() : 0);
+ $this->view->assign('publicLinkShow', true);
+ } else {
+ $this->view->assign('publicLinkShow', false);
+ }
+
+ $this->view->assign('accountPassDate', date('Y-m-d H:i:s', $accountData->getPassDate()));
+ $this->view->assign('accountPassDateChange', date('Y-m-d', $accountData->getPassDateChange() ?: 0));
+ $this->view->assign('linkedAccounts', $this->accountService->getLinked($this->accountId));
+
+ $this->view->assign('accountId', $accountData->getId());
+ $this->view->assign('accountData', $accountData);
+ $this->view->assign('gotData', true);
+
+ $this->view->assign('actions', $this->getActionsHelper()->getActionsForAccount($this->accountAcl->getStoredAcl(), new AccountActionsDto($this->accountId, null, $accountData->getParentId())));
+
+ $this->setViewCommon();
+ }
+
+ /**
+ * @throws UnauthorizedPageException
+ * @throws UpdatedMasterPassException
+ */
+ public function checkActionAccess()
+ {
+ if (!$this->acl->checkUserAccess($this->actionId)) {
+ throw new UnauthorizedPageException(SPException::SP_INFO);
+ }
+
+ if (!UserPass::checkUserUpdateMPass($this->session->getUserData()->getId())) {
+ throw new UpdatedMasterPassException(SPException::SP_INFO);
+ }
+ }
+
+ /**
+ * Comprobar si el usuario dispone de acceso al módulo
+ *
+ * @param AccountDetailsResponse $accountDetailsResponse
+ * @return bool
+ */
+ protected function checkAccess(AccountDetailsResponse $accountDetailsResponse)
+ {
+ $accountData = $accountDetailsResponse->getAccountVData();
+
+ $acccountAclDto = new AccountAclDto();
+ $acccountAclDto->setAccountId($accountData->getId());
+ $acccountAclDto->setDateEdit(strtotime($accountData->getDateEdit()));
+ $acccountAclDto->setUserId($accountData->getUserId());
+ $acccountAclDto->setUserGroupId($accountData->getUserGroupId());
+ $acccountAclDto->setUsersId($accountDetailsResponse->getUsers());
+ $acccountAclDto->setUserGroupsId($accountDetailsResponse->getUserGroups());
+
+ if (!$this->accountAcl->getAcl($acccountAclDto)->checkAccountAccess()) {
+ ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_ACCOUNT_NO_PERMISSION);
+
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * @return AccountActionsHelper
+ * @throws \SP\Core\Dic\ContainerException
+ */
+ protected function getActionsHelper()
+ {
+ return new AccountActionsHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
+ }
+
+ /**
+ * Sets account's view common data
+ */
+ protected function setViewCommon()
+ {
+ $userProfileData = $this->session->getUserProfile();
+
+ $this->view->assign('actionId', $this->actionId);
+ $this->view->assign('isView', $this->isView);
+
+ $this->view->assign('accountIsHistory', false);
+
+ $this->view->assign('customFields', $this->getCustomFieldsForItem(ActionsInterface::ACCOUNT, $this->accountId));
+ $this->view->assign('categories', SelectItemAdapter::factory(CategoryService::getItemsBasic())->getItemsFromModel());
+ $this->view->assign('clients', SelectItemAdapter::factory(ClientService::getItemsBasic())->getItemsFromModel());
+
+ $this->view->assign('allowPrivate', $userProfileData->isAccPrivate());
+ $this->view->assign('allowPrivateGroup', $userProfileData->isAccPrivateGroup());
+ $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->view->assign('addCategoryEnabled', !$this->isView && $this->acl->checkUserAccess(ActionsInterface::CATEGORY));
+ $this->view->assign('addCategoryRoute', Acl::getActionRoute(ActionsInterface::CATEGORY_CREATE));
+
+ $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->getStoredAcl() ?: $this->accountAcl);
+ }
+
+ /**
+ * Sets account's view for a blank form
+ *
+ * @param $actionId
+ * @return void
+ * @throws UnauthorizedPageException
+ * @throws UpdatedMasterPassException
+ * @throws \SP\Core\Dic\ContainerException
+ */
+ public function setViewForBlank($actionId)
+ {
+ $this->actionId = $actionId;
+ $this->accountAcl = new AccountAcl($actionId);
+
+ $this->checkActionAccess();
+
+ $selectUsers = SelectItemAdapter::factory(UserService::getItemsBasic());
+ $selectUserGroups = SelectItemAdapter::factory(UserGroupService::getItemsBasic());
+ $selectTags = SelectItemAdapter::factory(TagService::getItemsBasic());
+
+ $this->view->assign('accountPassDateChange', date('Y-m-d', time() + 7776000));
+ $this->view->assign('otherUsers', $selectUsers->getItemsFromModel());
+ $this->view->assign('otherUserGroups', $selectUserGroups->getItemsFromModel());
+ $this->view->assign('userGroups', $selectUserGroups->getItemsFromModel());
+ $this->view->assign('tags', $selectTags->getItemsFromModel());
+
+ $this->view->assign('accountId', 0);
+ $this->view->assign('gotData', false);
+
+ $this->view->assign('actions', $this->getActionsHelper()->getActionsForAccount($this->accountAcl, new AccountActionsDto($this->accountId)));
+
+ $this->setViewCommon();
+ }
+
+ /**
+ * Sets account's view variables
+ *
+ * @param AccountDetailsResponse $accountDetailsResponse
+ * @param int $actionId
+ * @return bool
+ * @throws UnauthorizedPageException
+ * @throws UpdatedMasterPassException
+ * @throws \SP\Core\Dic\ContainerException
+ */
+ public function setViewForRequest(AccountDetailsResponse $accountDetailsResponse, $actionId)
+ {
+ $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('actions', $this->getActionsHelper()->getActionsForAccount($this->accountAcl->getStoredAcl(), new AccountActionsDto($this->accountId, null, $accountData->getParentId())));
+
+ return true;
+ }
+
+ /**
+ * @param bool $isView
+ */
+ public function setIsView($isView)
+ {
+ $this->isView = (bool)$isView;
+ }
+
+ /**
+ * Initialize class
+ */
+ protected function initialize()
+ {
+ $this->view->assign('changesHash');
+ $this->view->assign('chkUserEdit');
+ $this->view->assign('chkGroupEdit');
+ $this->view->assign('sk', $this->session->generateSecurityKey());
+ }
+}
\ 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
new file mode 100644
index 00000000..eaddd582
--- /dev/null
+++ b/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php
@@ -0,0 +1,173 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Helpers\Account;
+
+use SP\Account\AccountAcl;
+use SP\Core\Acl\Acl;
+use SP\DataModel\AccountHistoryData;
+use SP\DataModel\Dto\AccountAclDto;
+use SP\Mgmt\Users\UserPass;
+use SP\Modules\Web\Controllers\Helpers\HelperBase;
+use SP\Mvc\View\Components\SelectItemAdapter;
+use SP\Services\Account\AccountHistoryService;
+use SP\Services\Category\CategoryService;
+use SP\Services\Client\ClientService;
+use SP\Util\ErrorUtil;
+
+/**
+ * Class AccountHistoryHelper
+ *
+ * @package SP\Modules\Web\Controllers\Helpers
+ */
+class AccountHistoryHelper extends HelperBase
+{
+ /**
+ * @var Acl
+ */
+ protected $acl;
+ /**
+ * @var AccountHistoryService
+ */
+ protected $accountHistoryService;
+ /**
+ * @var int
+ */
+ protected $accountId;
+ /**
+ * @var int
+ */
+ protected $actionId;
+ /**
+ * @var int
+ */
+ protected $accountHistoryId;
+ /**
+ * @var AccountAcl
+ */
+ protected $accountAcl;
+
+
+ /**
+ * @param Acl $acl
+ * @param AccountHistoryService $accountHistoryService
+ */
+ public function inject(Acl $acl, AccountHistoryService $accountHistoryService)
+ {
+ $this->acl = $acl;
+ $this->accountHistoryService = $accountHistoryService;
+ }
+
+ /**
+ * @param AccountHistoryData $accountHistoryData
+ * @param int $actionId
+ * @return bool
+ * @throws \SP\Core\Dic\ContainerException
+ */
+ public function setView(AccountHistoryData $accountHistoryData, $actionId)
+ {
+ $this->actionId = $actionId;
+ $this->accountHistoryId = $accountHistoryData->getId();
+ $this->accountId = $accountHistoryData->getAccountId();
+ $this->accountAcl = new AccountAcl($actionId, true);
+
+ if (!$this->checkActionAccess() || !$this->checkAccess($accountHistoryData)) {
+ // FIXME: throw exception
+ return false;
+ }
+
+ $this->view->assign('isView', true);
+ $this->view->assign('accountIsHistory', true);
+ $this->view->assign('accountData', $accountHistoryData);
+ $this->view->assign('accountAcl', $this->accountAcl->getStoredAcl());
+ $this->view->assign('actionId', $this->actionId);
+ $this->view->assign('accountId', $this->accountId);
+ $this->view->assign('accountHistoryId', $this->accountHistoryId);
+ $this->view->assign('historyData', $this->accountHistoryService->getHistoryForAccount($this->accountId));
+ $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', SelectItemAdapter::factory(CategoryService::getItemsBasic())->getItemsFromModelSelected([$accountHistoryData->getCategoryId()]));
+ $this->view->assign('clients', SelectItemAdapter::factory(ClientService::getItemsBasic())->getItemsFromModelSelected([$accountHistoryData->getClientId()]));
+ $this->view->assign('isModified', strtotime($accountHistoryData->getDateEdit()) !== false);
+
+ $actions = new AccountActionsHelper($this->view, $this->config, $this->session, $this->eventDispatcher);
+
+ $this->view->assign('actions', $actions->getActionsForAccount($this->accountAcl->getStoredAcl(), new AccountActionsDto($this->accountId, $this->accountHistoryId)));
+
+ return true;
+ }
+
+ /**
+ * @return bool
+ */
+ protected function checkActionAccess()
+ {
+ if (!$this->acl->checkUserAccess($this->actionId)) {
+ ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_PAGE_NO_PERMISSION);
+
+ return false;
+ }
+
+ if (!UserPass::checkUserUpdateMPass($this->session->getUserData()->getId())) {
+ ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_UPDATE_MPASS);
+
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Comprobar si el usuario dispone de acceso al módulo
+ *
+ * @param AccountHistoryData $accountHistoryData
+ * @return bool
+ */
+ protected function checkAccess(AccountHistoryData $accountHistoryData)
+ {
+ $acccountAclDto = new AccountAclDto();
+ $acccountAclDto->setAccountId($accountHistoryData->getAccountId());
+ $acccountAclDto->setDateEdit(strtotime($accountHistoryData->getDateEdit()));
+ $acccountAclDto->setUserId($accountHistoryData->getUserId());
+ $acccountAclDto->setUserGroupId($accountHistoryData->getUserGroupId());
+ $acccountAclDto->setUsersId($this->accountHistoryService->getUsersByAccountId($this->accountId));
+ $acccountAclDto->setUserGroupsId($this->accountHistoryService->getUserGroupsByAccountId($this->accountId));
+
+ if (!$this->accountAcl->getAcl($acccountAclDto)->getStoredAcl()->checkAccountAccess()) {
+ ErrorUtil::showErrorInView($this->view, ErrorUtil::ERR_ACCOUNT_NO_PERMISSION);
+
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Initialize class
+ */
+ protected function initialize()
+ {
+ $this->view->assign('sk', $this->session->generateSecurityKey());
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Helpers/AccountPasswordHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php
similarity index 76%
rename from app/modules/web/Controllers/Helpers/AccountPasswordHelper.php
rename to app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php
index 3a4e9402..72385143 100644
--- a/app/modules/web/Controllers/Helpers/AccountPasswordHelper.php
+++ b/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php
@@ -1,6 +1,28 @@
.
+ */
-namespace SP\Modules\Web\Controllers\Helpers;
+namespace SP\Modules\Web\Controllers\Helpers\Account;
use SP\Core\Acl\Acl;
use SP\Core\Acl\ActionsInterface;
@@ -9,6 +31,8 @@ use SP\Core\Crypt\Session as CryptSession;
use SP\Core\SessionUtil;
use SP\DataModel\AccountPassData;
use SP\Mgmt\Users\UserPass;
+use SP\Modules\Web\Controllers\Helpers\HelperBase;
+use SP\Modules\Web\Controllers\Helpers\HelperException;
use SP\Util\ImageUtil;
/**
diff --git a/app/modules/web/Controllers/Helpers/AccountSearchHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php
similarity index 97%
rename from app/modules/web/Controllers/Helpers/AccountSearchHelper.php
rename to app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php
index 108239fe..20b57a89 100644
--- a/app/modules/web/Controllers/Helpers/AccountSearchHelper.php
+++ b/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php
@@ -2,9 +2,9 @@
/**
* sysPass
*
- * @author nuxsmin
- * @link http://syspass.org
- * @copyright 2012-2017, Rubén Domínguez nuxsmin@$syspass.org
+ * @author nuxsmin
+ * @link http://syspass.org
+ * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -22,7 +22,7 @@
* along with sysPass. If not, see
-
@@ -44,20 +43,21 @@