diff --git a/app/modules/api/Controllers/AccountController.php b/app/modules/api/Controllers/AccountController.php
index 5b7ae16b..2c7c60be 100644
--- a/app/modules/api/Controllers/AccountController.php
+++ b/app/modules/api/Controllers/AccountController.php
@@ -24,25 +24,26 @@
namespace SP\Modules\Api\Controllers;
-use DI\DependencyException;
-use DI\NotFoundException;
use Exception;
+use Klein\Klein;
use League\Fractal\Resource\Item;
use SP\Adapters\AccountAdapter;
+use SP\Core\Acl\Acl;
use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
use SP\Core\Crypt\Crypt;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
-use SP\Core\Exceptions\InvalidClassException;
use SP\DataModel\Dto\AccountDetailsResponse;
+use SP\Domain\Account\AccountPresetServiceInterface;
+use SP\Domain\Account\AccountServiceInterface;
+use SP\Domain\Account\Services\AccountRequest;
+use SP\Domain\Account\Services\AccountSearchFilter;
+use SP\Domain\Api\ApiServiceInterface;
+use SP\Domain\Api\Services\ApiResponse;
use SP\Modules\Api\Controllers\Help\AccountHelp;
use SP\Mvc\Controller\ItemTrait;
use SP\Mvc\Model\QueryCondition;
-use SP\Services\Account\AccountPresetService;
-use SP\Services\Account\AccountRequest;
-use SP\Services\Account\AccountSearchFilter;
-use SP\Services\Account\AccountService;
-use SP\Services\Api\ApiResponse;
use SP\Util\Util;
/**
@@ -54,8 +55,24 @@ final class AccountController extends ControllerBase
{
use ItemTrait;
- private ?AccountPresetService $accountPresetService = null;
- private ?AccountService $accountService = null;
+ private AccountPresetServiceInterface $accountPresetService;
+ private AccountServiceInterface $accountService;
+
+ public function __construct(
+ Application $application,
+ Klein $router,
+ ApiServiceInterface $apiService,
+ Acl $acl,
+ AccountPresetServiceInterface $accountPresetService,
+ AccountServiceInterface $accountService
+ ) {
+ $this->accountPresetService = $accountPresetService;
+ $this->accountService = $accountService;
+
+ parent::__construct($application, $router, $apiService, $acl);
+
+ $this->apiService->setHelpClass(AccountHelp::class);
+ }
/**
* viewAction
@@ -226,7 +243,8 @@ final class AccountController extends ControllerBase
$userData = $this->context->getUserData();
$accountRequest->userId = $this->apiService->getParamInt('userId', false, $userData->getId());
- $accountRequest->userGroupId = $this->apiService->getParamInt('userGroupId', false, $userData->getUserGroupId());
+ $accountRequest->userGroupId =
+ $this->apiService->getParamInt('userGroupId', false, $userData->getUserGroupId());
$accountRequest->tags = array_map(
'intval',
@@ -363,7 +381,9 @@ final class AccountController extends ControllerBase
}
$accountSearchFilter->setLimitCount($this->apiService->getParamInt('count', false, 50));
- $accountSearchFilter->setSortOrder($this->apiService->getParamInt('order', false, AccountSearchFilter::SORT_DEFAULT));
+ $accountSearchFilter->setSortOrder(
+ $this->apiService->getParamInt('order', false, AccountSearchFilter::SORT_DEFAULT)
+ );
$this->returnResponse(
ApiResponse::makeSuccess(
@@ -416,14 +436,4 @@ final class AccountController extends ControllerBase
$this->returnResponseException($e);
}
}
-
- /**
- * @throws \SP\Core\Exceptions\InvalidClassException
- */
- protected function initialize(): void
- {
- $this->accountService = $this->dic->get(AccountService::class);
- $this->accountPresetService = $this->dic->get(AccountPresetService::class);
- $this->apiService->setHelpClass(AccountHelp::class);
- }
}
\ No newline at end of file
diff --git a/app/modules/api/Controllers/CategoryController.php b/app/modules/api/Controllers/CategoryController.php
index 9f76bee0..a6b91190 100644
--- a/app/modules/api/Controllers/CategoryController.php
+++ b/app/modules/api/Controllers/CategoryController.php
@@ -32,10 +32,10 @@ use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\DataModel\CategoryData;
use SP\DataModel\ItemSearchData;
+use SP\Domain\Api\Services\ApiResponse;
+use SP\Domain\Category\Services\CategoryService;
use SP\Modules\Api\Controllers\Help\CategoryHelp;
use SP\Mvc\Controller\ItemTrait;
-use SP\Services\Api\ApiResponse;
-use SP\Services\Category\CategoryService;
use SP\Util\Util;
diff --git a/app/modules/api/Controllers/ClientController.php b/app/modules/api/Controllers/ClientController.php
index 9852902a..55357f63 100644
--- a/app/modules/api/Controllers/ClientController.php
+++ b/app/modules/api/Controllers/ClientController.php
@@ -24,21 +24,18 @@
namespace SP\Modules\Api\Controllers;
-use DI\DependencyException;
-use DI\NotFoundException;
use Exception;
use League\Fractal\Resource\Item;
use SP\Adapters\ClientAdapter;
use SP\Core\Acl\ActionsInterface;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
-use SP\Core\Exceptions\InvalidClassException;
use SP\DataModel\ClientData;
use SP\DataModel\ItemSearchData;
+use SP\Domain\Api\Services\ApiResponse;
+use SP\Domain\Client\Services\ClientService;
use SP\Modules\Api\Controllers\Help\ClientHelp;
use SP\Mvc\Controller\ItemTrait;
-use SP\Services\Api\ApiResponse;
-use SP\Services\Client\ClientService;
use SP\Util\Util;
/**
diff --git a/app/modules/api/Controllers/ConfigController.php b/app/modules/api/Controllers/ConfigController.php
index c6431051..40b93b2c 100644
--- a/app/modules/api/Controllers/ConfigController.php
+++ b/app/modules/api/Controllers/ConfigController.php
@@ -29,11 +29,11 @@ use SP\Core\Acl\ActionsInterface;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Core\Exceptions\InvalidClassException;
+use SP\Domain\Api\Services\ApiResponse;
+use SP\Domain\Export\Services\BackupFiles;
+use SP\Domain\Export\Services\FileBackupService;
+use SP\Domain\Export\Services\XmlExportService;
use SP\Modules\Api\Controllers\Help\ConfigHelp;
-use SP\Services\Api\ApiResponse;
-use SP\Services\Backup\BackupFiles;
-use SP\Services\Backup\FileBackupService;
-use SP\Services\Export\XmlExportService;
/**
* Class ConfigController
diff --git a/app/modules/api/Controllers/ControllerBase.php b/app/modules/api/Controllers/ControllerBase.php
index d48760fb..a160c745 100644
--- a/app/modules/api/Controllers/ControllerBase.php
+++ b/app/modules/api/Controllers/ControllerBase.php
@@ -28,16 +28,16 @@ use Exception;
use Klein\Klein;
use League\Fractal\Manager;
use Psr\Container\ContainerInterface;
-use SP\Config\ConfigDataInterface;
use SP\Core\Acl\Acl;
+use SP\Core\Application;
use SP\Core\Context\ContextInterface;
use SP\Core\Events\EventDispatcher;
use SP\Core\Exceptions\SPException;
+use SP\Domain\Api\ApiServiceInterface;
+use SP\Domain\Api\Services\ApiResponse;
+use SP\Domain\Api\Services\JsonRpcResponse;
+use SP\Domain\Config\In\ConfigDataInterface;
use SP\Http\Json;
-use SP\Services\Api\ApiResponse;
-use SP\Services\Api\ApiService;
-use SP\Services\Api\JsonRpcResponse;
-use SP\Services\ServiceException;
/**
* Class ControllerBase
@@ -48,34 +48,34 @@ abstract class ControllerBase
{
protected const SEARCH_COUNT_ITEMS = 25;
- protected ContainerInterface $dic;
- protected string $controllerName;
- protected string $actionName;
- protected ContextInterface $context;
- protected EventDispatcher $eventDispatcher;
- protected ApiService $apiService;
- protected Klein $router;
+ protected ContainerInterface $dic;
+ protected string $controllerName;
+ protected ContextInterface $context;
+ protected EventDispatcher $eventDispatcher;
+ protected ApiServiceInterface $apiService;
+ protected Klein $router;
protected ConfigDataInterface $configData;
- protected Manager $fractal;
- protected Acl $acl;
- private bool $isAuthenticated = false;
+ protected Manager $fractal;
+ protected Acl $acl;
+ private bool $isAuthenticated = false;
- final public function __construct(
- ContainerInterface $container,
- string $actionName
- )
- {
- $this->dic = $container;
- $this->context = $container->get(ContextInterface::class);
- $this->configData = $container->get(ConfigDataInterface::class);
- $this->eventDispatcher = $container->get(EventDispatcher::class);
- $this->router = $container->get(Klein::class);
- $this->apiService = $container->get(ApiService::class);
- $this->acl = $container->get(Acl::class);
+ public function __construct(
+ Application $application,
+ Klein $router,
+ ApiServiceInterface $apiService,
+ Acl $acl
+ ) {
+ $this->context = $application->getContext();
+ $this->configData = $application->getConfig()->getConfigData();
+ $this->eventDispatcher = $application->getEventDispatcher();
+ $this->router = $router;
+ $this->apiService = $apiService;
+ $this->acl = $acl;
$this->fractal = new Manager();
$this->controllerName = $this->getControllerName();
- $this->actionName = $actionName;
+ // FIXME: provide action name
+// $this->actionName = $actionName;
if (method_exists($this, 'initialize')) {
$this->initialize();
@@ -89,12 +89,13 @@ abstract class ControllerBase
return substr(
$class,
strrpos($class, '\\') + 1,
- -strlen('Controller')) ?: '';
+ -strlen('Controller')
+ ) ?: '';
}
/**
* @throws SPException
- * @throws ServiceException
+ * @throws \SP\Domain\Common\Services\ServiceException
*/
final protected function setupApi(int $actionId): void
{
diff --git a/app/modules/api/Controllers/TagController.php b/app/modules/api/Controllers/TagController.php
index 11e9ac0e..2af702aa 100644
--- a/app/modules/api/Controllers/TagController.php
+++ b/app/modules/api/Controllers/TagController.php
@@ -24,18 +24,15 @@
namespace SP\Modules\Api\Controllers;
-use DI\DependencyException;
-use DI\NotFoundException;
use Exception;
use SP\Core\Acl\ActionsInterface;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
-use SP\Core\Exceptions\InvalidClassException;
use SP\DataModel\ItemSearchData;
use SP\DataModel\TagData;
+use SP\Domain\Api\Services\ApiResponse;
+use SP\Domain\Tag\Services\TagService;
use SP\Modules\Api\Controllers\Help\TagHelp;
-use SP\Services\Api\ApiResponse;
-use SP\Services\Tag\TagService;
/**
* Class TagController
diff --git a/app/modules/api/Controllers/UserGroupController.php b/app/modules/api/Controllers/UserGroupController.php
index c81b07e3..62875a31 100644
--- a/app/modules/api/Controllers/UserGroupController.php
+++ b/app/modules/api/Controllers/UserGroupController.php
@@ -24,18 +24,15 @@
namespace SP\Modules\Api\Controllers;
-use DI\DependencyException;
-use DI\NotFoundException;
use Exception;
use SP\Core\Acl\ActionsInterface;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
-use SP\Core\Exceptions\InvalidClassException;
use SP\DataModel\ItemSearchData;
use SP\DataModel\UserGroupData;
+use SP\Domain\Api\Services\ApiResponse;
+use SP\Domain\User\Services\UserGroupService;
use SP\Modules\Api\Controllers\Help\TagHelp;
-use SP\Services\Api\ApiResponse;
-use SP\Services\UserGroup\UserGroupService;
/**
* Class UserGroupController
diff --git a/app/modules/api/Init.php b/app/modules/api/Init.php
index 21a649db..be0f3744 100644
--- a/app/modules/api/Init.php
+++ b/app/modules/api/Init.php
@@ -30,13 +30,14 @@ use SP\Core\Application;
use SP\Core\Exceptions\InitializationException;
use SP\Core\HttpModuleBase;
use SP\Core\Language;
+use SP\Core\LanguageInterface;
use SP\Core\ProvidersHelper;
-use SP\Http\Request;
-use SP\Services\Upgrade\UpgradeAppService;
-use SP\Services\Upgrade\UpgradeDatabaseService;
-use SP\Services\Upgrade\UpgradeUtil;
-use SP\Storage\Database\DatabaseUtil;
-use SP\Storage\File\FileException;
+use SP\Domain\Upgrade\Services\UpgradeAppService;
+use SP\Domain\Upgrade\Services\UpgradeDatabaseService;
+use SP\Domain\Upgrade\Services\UpgradeUtil;
+use SP\Http\RequestInterface;
+use SP\Infrastructure\Database\DatabaseUtil;
+use SP\Infrastructure\File\FileException;
use SP\Util\HttpUtil;
/**
@@ -50,9 +51,9 @@ final class Init extends HttpModuleBase
public function __construct(
Application $application,
ProvidersHelper $providersHelper,
- Request $request,
+ RequestInterface $request,
Klein $router,
- Language $language,
+ LanguageInterface $language,
DatabaseUtil $databaseUtil
) {
parent::__construct(
@@ -71,7 +72,7 @@ final class Init extends HttpModuleBase
* @throws \JsonException
* @throws \SP\Core\Context\ContextException
* @throws \SP\Core\Exceptions\InitializationException
- * @throws \SP\Storage\File\FileException
+ * @throws \SP\Infrastructure\File\FileException
*/
public function initialize(string $controller): void
{
diff --git a/app/modules/cli/Commands/BackupCommand.php b/app/modules/cli/Commands/BackupCommand.php
index 18d72a3a..01a4f1b0 100644
--- a/app/modules/cli/Commands/BackupCommand.php
+++ b/app/modules/cli/Commands/BackupCommand.php
@@ -27,8 +27,9 @@ namespace SP\Modules\Cli\Commands;
use Exception;
use Psr\Log\LoggerInterface;
use RuntimeException;
-use SP\Config\Config;
-use SP\Services\Backup\FileBackupService;
+use SP\Domain\Config\ConfigInterface;
+use SP\Domain\Export\FileBackupServiceInterface;
+use SP\Domain\Export\Services\FileBackupService;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@@ -54,9 +55,10 @@ final class BackupCommand extends CommandBase
protected static $defaultName = 'sp:backup';
private FileBackupService $fileBackupService;
- public function __construct(FileBackupService $fileBackupService,
+ public function __construct(
+ FileBackupServiceInterface $fileBackupService,
LoggerInterface $logger,
- Config $config)
+ ConfigInterface $config)
{
$this->fileBackupService = $fileBackupService;
diff --git a/app/modules/cli/Commands/CommandBase.php b/app/modules/cli/Commands/CommandBase.php
index 4ac7eb74..75fc59e6 100644
--- a/app/modules/cli/Commands/CommandBase.php
+++ b/app/modules/cli/Commands/CommandBase.php
@@ -25,8 +25,9 @@
namespace SP\Modules\Cli\Commands;
use Psr\Log\LoggerInterface;
-use SP\Config\Config;
-use SP\Config\ConfigDataInterface;
+use SP\Domain\Config\ConfigInterface;
+use SP\Domain\Config\In\ConfigDataInterface;
+use SP\Domain\Config\Services\ConfigFileService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
@@ -38,13 +39,13 @@ use Symfony\Component\Console\Input\InputInterface;
abstract class CommandBase extends Command
{
public static array $envVarsMapping = [];
- protected LoggerInterface $logger;
- protected Config $config;
+ protected LoggerInterface $logger;
+ protected ConfigFileService $config;
protected ConfigDataInterface $configData;
public function __construct(
LoggerInterface $logger,
- Config $config
+ ConfigInterface $config
)
{
$this->logger = $logger;
diff --git a/app/modules/cli/Commands/Crypt/UpdateMasterPasswordCommand.php b/app/modules/cli/Commands/Crypt/UpdateMasterPasswordCommand.php
index 95879504..b3dd79c6 100644
--- a/app/modules/cli/Commands/Crypt/UpdateMasterPasswordCommand.php
+++ b/app/modules/cli/Commands/Crypt/UpdateMasterPasswordCommand.php
@@ -27,13 +27,15 @@ namespace SP\Modules\Cli\Commands\Crypt;
use Exception;
use Psr\Log\LoggerInterface;
use RuntimeException;
-use SP\Config\Config;
+use SP\Domain\Account\Services\AccountService;
+use SP\Domain\Config\ConfigInterface;
+use SP\Domain\Config\ConfigServiceInterface;
+use SP\Domain\Config\Services\ConfigService;
+use SP\Domain\Crypt\MasterPassServiceInterface;
+use SP\Domain\Crypt\Services\MasterPassService;
+use SP\Domain\Crypt\Services\UpdateMasterPassRequest;
use SP\Modules\Cli\Commands\CommandBase;
use SP\Modules\Cli\Commands\Validators;
-use SP\Services\Account\AccountService;
-use SP\Services\Config\ConfigService;
-use SP\Services\Crypt\MasterPassService;
-use SP\Services\Crypt\UpdateMasterPassRequest;
use SP\Util\Util;
use Symfony\Component\Console\Command\LockableTrait;
use Symfony\Component\Console\Input\InputInterface;
@@ -56,23 +58,24 @@ final class UpdateMasterPasswordCommand extends CommandBase
*/
public static array $envVarsMapping = [
'currentMasterPassword' => 'CURRENT_MASTER_PASSWORD',
- 'masterPassword' => 'MASTER_PASSWORD',
- 'update' => 'UPDATE',
+ 'masterPassword' => 'MASTER_PASSWORD',
+ 'update' => 'UPDATE',
];
/**
* @var string
*/
- protected static $defaultName = 'sp:crypt:update-master-password';
- private MasterPassService $masterPassService;
- private ConfigService $configService;
+ protected static $defaultName = 'sp:crypt:update-master-password';
+ private \SP\Domain\Crypt\MasterPassServiceInterface $masterPassService;
+ private ConfigService $configService;
private AccountService $accountService;
- public function __construct(MasterPassService $masterPassService,
- AccountService $accountService,
- ConfigService $configService,
- LoggerInterface $logger,
- Config $config)
- {
+ public function __construct(
+ MasterPassServiceInterface $masterPassService,
+ AccountService $accountService,
+ ConfigServiceInterface $configService,
+ LoggerInterface $logger,
+ ConfigInterface $config
+ ) {
$this->masterPassService = $masterPassService;
$this->accountService = $accountService;
$this->configService = $configService;
@@ -84,25 +87,30 @@ final class UpdateMasterPasswordCommand extends CommandBase
{
$this->setDescription(__('Update sysPass master password'))
->setHelp(__('This command updates sysPass master password for all the encrypted data'))
- ->addOption('masterPassword',
+ ->addOption(
+ 'masterPassword',
null,
InputOption::VALUE_REQUIRED,
- __('The new master password to encrypt the data'))
- ->addOption('currentMasterPassword',
+ __('The new master password to encrypt the data')
+ )
+ ->addOption(
+ 'currentMasterPassword',
null,
InputOption::VALUE_REQUIRED,
- __('The current master password'))
- ->addOption('update',
+ __('The current master password')
+ )
+ ->addOption(
+ 'update',
null,
InputOption::VALUE_NONE,
- __('Skip asking to confirm the update'));
+ __('Skip asking to confirm the update')
+ );
}
protected function execute(
- InputInterface $input,
+ InputInterface $input,
OutputInterface $output
- ): int
- {
+ ): int {
$style = new SymfonyStyle($input, $output);
if (!$this->lock()) {
@@ -143,10 +151,12 @@ final class UpdateMasterPasswordCommand extends CommandBase
$style->warning(__('You should save the new password on a secure place'));
$style->warning(__('All accounts passwords will be encrypted again.'));
$style->warning(__('Users will need to enter the new Master Password.'));
- $style->warning(printf(
- __('It will be updated %s accounts. This process could take some time long.'),
- $this->accountService->getTotalNumAccounts()
- ));
+ $style->warning(
+ printf(
+ __('It will be updated %s accounts. This process could take some time long.'),
+ $this->accountService->getTotalNumAccounts()
+ )
+ );
$style->newLine();
$style->caution(__('This is a critical process, please do not cancel/close this CLI'));
@@ -194,8 +204,7 @@ final class UpdateMasterPasswordCommand extends CommandBase
private function getMasterPassword(
InputInterface $input,
StyleInterface $style
- )
- {
+ ) {
$password = self::getEnvVarOrOption('masterPassword', $input);
if (empty($password)) {
@@ -232,8 +241,7 @@ final class UpdateMasterPasswordCommand extends CommandBase
private function getCurrentMasterPassword(
InputInterface $input,
StyleInterface $style
- )
- {
+ ) {
$password = self::getEnvVarOrOption('currentMasterPassword', $input);
if (empty($password)) {
@@ -265,8 +273,8 @@ final class UpdateMasterPasswordCommand extends CommandBase
}
/**
- * @throws \SP\Services\ServiceException
- * @throws \SP\Repositories\NoSuchItemException
+ * @throws \SP\Domain\Common\Services\ServiceException
+ * @throws \SP\Infrastructure\Common\Repositories\NoSuchItemException
*/
private function checkMasterPassword(string $password): void
{
@@ -278,8 +286,7 @@ final class UpdateMasterPasswordCommand extends CommandBase
private function getUpdate(
InputInterface $input,
StyleInterface $style
- ): bool
- {
+ ): bool {
$option = 'update';
$envUpdate = self::getEnvVarForOption($option);
diff --git a/app/modules/cli/Commands/InstallCommand.php b/app/modules/cli/Commands/InstallCommand.php
index e0debc03..d5d5ef76 100644
--- a/app/modules/cli/Commands/InstallCommand.php
+++ b/app/modules/cli/Commands/InstallCommand.php
@@ -26,12 +26,13 @@ namespace SP\Modules\Cli\Commands;
use Exception;
use Psr\Log\LoggerInterface;
-use SP\Config\Config;
use SP\Core\Exceptions\InstallError;
use SP\Core\Exceptions\InvalidArgumentException;
use SP\Core\Language;
-use SP\Services\Install\InstallData;
-use SP\Services\Install\Installer;
+use SP\Domain\Config\ConfigInterface;
+use SP\Domain\Install\InstallerInterface;
+use SP\Domain\Install\Services\InstallData;
+use SP\Domain\Install\Services\Installer;
use SP\Util\Util;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -71,8 +72,8 @@ final class InstallCommand extends CommandBase
public function __construct(
LoggerInterface $logger,
- Config $config,
- Installer $installer
+ ConfigInterface $config,
+ InstallerInterface $installer
) {
parent::__construct($logger, $config);
diff --git a/app/modules/cli/Init.php b/app/modules/cli/Init.php
index b9c939c8..3e91a265 100644
--- a/app/modules/cli/Init.php
+++ b/app/modules/cli/Init.php
@@ -26,6 +26,7 @@ namespace SP\Modules\Cli;
use SP\Core\Application;
use SP\Core\Language;
+use SP\Core\LanguageInterface;
use SP\Core\ModuleBase;
use SP\Core\ProvidersHelper;
use SP\Util\VersionUtil;
@@ -49,7 +50,7 @@ final class Init extends ModuleBase
public function __construct(
Application $application,
ProvidersHelper $providersHelper,
- Language $language,
+ LanguageInterface $language,
ConsoleApplication $consoleApplication,
InputInterface $input,
OutputInterface $output,
diff --git a/app/modules/web/Controllers/AccessManagerController.php b/app/modules/web/Controllers/AccessManagerController.php
index d7901bb0..5e699a3e 100644
--- a/app/modules/web/Controllers/AccessManagerController.php
+++ b/app/modules/web/Controllers/AccessManagerController.php
@@ -33,6 +33,12 @@ use SP\Core\Exceptions\ConstraintException;
use SP\Core\Exceptions\QueryException;
use SP\Core\Exceptions\SessionTimeout;
use SP\DataModel\ItemSearchData;
+use SP\Domain\Account\Services\PublicLinkService;
+use SP\Domain\Auth\Services\AuthException;
+use SP\Domain\Auth\Services\AuthTokenService;
+use SP\Domain\User\Services\UserGroupService;
+use SP\Domain\User\Services\UserProfileService;
+use SP\Domain\User\Services\UserService;
use SP\Html\DataGrid\DataGridTab;
use SP\Modules\Web\Controllers\Helpers\Grid\AuthTokenGrid;
use SP\Modules\Web\Controllers\Helpers\Grid\PublicLinkGrid;
@@ -40,12 +46,6 @@ use SP\Modules\Web\Controllers\Helpers\Grid\UserGrid;
use SP\Modules\Web\Controllers\Helpers\Grid\UserGroupGrid;
use SP\Modules\Web\Controllers\Helpers\Grid\UserProfileGrid;
use SP\Modules\Web\Controllers\Helpers\TabsGridHelper;
-use SP\Services\Auth\AuthException;
-use SP\Services\AuthToken\AuthTokenService;
-use SP\Services\PublicLink\PublicLinkService;
-use SP\Services\User\UserService;
-use SP\Services\UserGroup\UserGroupService;
-use SP\Services\UserProfile\UserProfileService;
/**
* Class AccessManagerController
diff --git a/app/modules/web/Controllers/Account/AccountControllerBase.php b/app/modules/web/Controllers/Account/AccountControllerBase.php
new file mode 100644
index 00000000..9e7ce908
--- /dev/null
+++ b/app/modules/web/Controllers/Account/AccountControllerBase.php
@@ -0,0 +1,54 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+use SP\Core\Context\ContextBase;
+use SP\Domain\Account\Services\AccountAclService;
+use SP\Modules\Web\Controllers\ControllerBase;
+
+abstract class AccountControllerBase extends ControllerBase
+{
+ private const LOGIN_NOT_REQUIRED = ['ViewLinkController'];
+
+ /**
+ * Initialize class
+ *
+ * @throws \SP\Core\Exceptions\SessionTimeout
+ * @throws \SP\Domain\Auth\Services\AuthException
+ */
+ protected function initialize(): void
+ {
+ if (in_array(static::class, self::LOGIN_NOT_REQUIRED)) {
+ $this->checkLoggedIn();
+ }
+
+ if (DEBUG === true && $this->session->getAppStatus() === ContextBase::APP_STATUS_RELOADED) {
+ $this->session->resetAppStatus();
+
+ // Reset de los datos de ACL de cuentas
+ AccountAclService::clearAcl($this->session->getUserData()->getId());
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/CopyController.php b/app/modules/web/Controllers/Account/CopyController.php
new file mode 100644
index 00000000..4703ae42
--- /dev/null
+++ b/app/modules/web/Controllers/Account/CopyController.php
@@ -0,0 +1,109 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Core\UI\ThemeIcons;
+use SP\Domain\Account\AccountServiceInterface;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountHelper;
+use SP\Mvc\Controller\WebControllerHelper;
+use SP\Util\ErrorUtil;
+
+final class CopyController extends AccountControllerBase
+{
+ private AccountHelper $accountHelper;
+ private ThemeIcons $icons;
+ private AccountServiceInterface $accountService;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ AccountHelper $accountHelper,
+ AccountServiceInterface $accountService
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountHelper = $accountHelper;
+ $this->accountService = $accountService;
+ $this->icons = $this->theme->getIcons();
+ }
+
+ /**
+ * Copy action
+ *
+ * @param int $id Account's ID
+ */
+ public function copyAction(int $id): void
+ {
+ try {
+ $accountDetailsResponse = $this->accountService->getById($id);
+ $this->accountService
+ ->withUsersById($accountDetailsResponse)
+ ->withUserGroupsById($accountDetailsResponse)
+ ->withTagsById($accountDetailsResponse);
+
+ $this->accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_COPY);
+
+ $this->view->addTemplate('account');
+ $this->view->assign(
+ 'title',
+ [
+ 'class' => 'titleGreen',
+ 'name' => __('New Account'),
+ 'icon' => $this->icons->getIconAdd()->getIcon(),
+ ]
+ );
+ $this->view->assign('formRoute', 'account/saveCopy');
+
+ $this->eventDispatcher->notifyEvent('show.account.copy', new Event($this));
+
+ if ($this->isAjax === false) {
+ $this->upgradeView();
+ }
+
+ $this->view();
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent(
+ 'exception',
+ new Event($e)
+ );
+
+ if ($this->isAjax === false && !$this->view->isUpgraded()) {
+ $this->upgradeView();
+ }
+
+ ErrorUtil::showExceptionInView($this->view, $e, 'account');
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/CopyPassController.php b/app/modules/web/Controllers/Account/CopyPassController.php
new file mode 100644
index 00000000..072ed7bb
--- /dev/null
+++ b/app/modules/web/Controllers/Account/CopyPassController.php
@@ -0,0 +1,93 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Core\Events\EventMessage;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountPasswordHelper;
+use SP\Modules\Web\Controllers\Traits\JsonTrait;
+use SP\Mvc\Controller\WebControllerHelper;
+
+final class CopyPassController extends AccountControllerBase
+{
+ use JsonTrait;
+
+ private \SP\Domain\Account\AccountServiceInterface $accountService;
+ private AccountPasswordHelper $accountPasswordHelper;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ \SP\Domain\Account\AccountServiceInterface $accountService,
+ AccountPasswordHelper $accountPasswordHelper,
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountService = $accountService;
+ $this->accountPasswordHelper = $accountPasswordHelper;
+ }
+
+ /**
+ * Copy account's password
+ *
+ * @param int $id Account's ID
+ *
+ * @return bool
+ * @throws \Defuse\Crypto\Exception\BadFormatException
+ * @throws \Defuse\Crypto\Exception\CryptoException
+ * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
+ * @throws \Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException
+ * @throws \JsonException
+ * @throws \SP\Core\Exceptions\ConstraintException
+ * @throws \SP\Core\Exceptions\QueryException
+ * @throws \SP\Modules\Web\Controllers\Helpers\HelperException
+ * @throws \SP\Infrastructure\Common\Repositories\NoSuchItemException
+ * @throws \SP\Domain\Common\Services\ServiceException
+ */
+ public function copyPassAction(int $id): bool
+ {
+ $account = $this->accountService->getPasswordForId($id);
+
+ $data = [
+ 'accpass' => $this->accountPasswordHelper->getPasswordClear($account),
+ ];
+
+ $this->eventDispatcher->notifyEvent(
+ 'copy.account.pass',
+ new Event(
+ $this, EventMessage::factory()
+ ->addDescription(__u('Password copied'))
+ ->addDetail(__u('Account'), $account->getName())
+ )
+ );
+
+ return $this->returnJsonResponseData($data);
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/CopyPassHistoryController.php b/app/modules/web/Controllers/Account/CopyPassHistoryController.php
new file mode 100644
index 00000000..f0c0596e
--- /dev/null
+++ b/app/modules/web/Controllers/Account/CopyPassHistoryController.php
@@ -0,0 +1,93 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Core\Events\EventMessage;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountPasswordHelper;
+use SP\Modules\Web\Controllers\Traits\JsonTrait;
+use SP\Mvc\Controller\WebControllerHelper;
+
+final class CopyPassHistoryController extends AccountControllerBase
+{
+ use JsonTrait;
+
+ private \SP\Domain\Account\AccountServiceInterface $accountService;
+ private AccountPasswordHelper $accountPasswordHelper;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ \SP\Domain\Account\AccountServiceInterface $accountService,
+ AccountPasswordHelper $accountPasswordHelper,
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountService = $accountService;
+ $this->accountPasswordHelper = $accountPasswordHelper;
+ }
+
+ /**
+ * Copy account's password
+ *
+ * @param int $id Account's ID
+ *
+ * @return bool
+ * @throws \Defuse\Crypto\Exception\BadFormatException
+ * @throws \Defuse\Crypto\Exception\CryptoException
+ * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
+ * @throws \Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException
+ * @throws \JsonException
+ * @throws \SP\Core\Exceptions\ConstraintException
+ * @throws \SP\Core\Exceptions\QueryException
+ * @throws \SP\Modules\Web\Controllers\Helpers\HelperException
+ * @throws \SP\Infrastructure\Common\Repositories\NoSuchItemException
+ * @throws \SP\Domain\Common\Services\ServiceException
+ */
+ public function copyPassHistoryAction(int $id): bool
+ {
+ $account = $this->accountService->getPasswordHistoryForId($id);
+
+ $data = [
+ 'accpass' => $this->accountPasswordHelper->getPasswordClear($account),
+ ];
+
+ $this->eventDispatcher->notifyEvent(
+ 'copy.account.pass.history',
+ new Event(
+ $this, EventMessage::factory()
+ ->addDescription(__u('Password copied'))
+ ->addDetail(__u('Account'), $account->getName())
+ )
+ );
+
+ return $this->returnJsonResponseData($data);
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/CreateController.php b/app/modules/web/Controllers/Account/CreateController.php
new file mode 100644
index 00000000..47add5ba
--- /dev/null
+++ b/app/modules/web/Controllers/Account/CreateController.php
@@ -0,0 +1,92 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Core\UI\ThemeIcons;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountHelper;
+use SP\Mvc\Controller\WebControllerHelper;
+use SP\Util\ErrorUtil;
+
+final class CreateController extends AccountControllerBase
+{
+ private AccountHelper $accountHelper;
+ private ThemeIcons $icons;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ AccountHelper $accountHelper
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountHelper = $accountHelper;
+ $this->icons = $this->theme->getIcons();
+ }
+
+ /**
+ * Create action
+ */
+ public function createAction(): void
+ {
+ try {
+ $this->accountHelper->setViewForBlank(ActionsInterface::ACCOUNT_CREATE);
+
+ $this->view->addTemplate('account');
+ $this->view->assign(
+ 'title',
+ [
+ 'class' => 'titleGreen',
+ 'name' => __('New Account'),
+ 'icon' => $this->icons->getIconAdd()->getIcon(),
+ ]
+ );
+ $this->view->assign('formRoute', 'account/saveCreate');
+
+ $this->eventDispatcher->notifyEvent('show.account.create', new Event($this));
+
+ if ($this->isAjax === false) {
+ $this->upgradeView();
+ }
+
+ $this->view();
+ } catch (Exception $e) {
+ processException($e);
+
+ if ($this->isAjax === false && !$this->view->isUpgraded()) {
+ $this->upgradeView();
+ }
+
+ ErrorUtil::showExceptionInView($this->view, $e, 'account');
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/DeleteController.php b/app/modules/web/Controllers/Account/DeleteController.php
new file mode 100644
index 00000000..33a96470
--- /dev/null
+++ b/app/modules/web/Controllers/Account/DeleteController.php
@@ -0,0 +1,109 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Core\UI\ThemeIcons;
+use SP\Domain\Account\AccountServiceInterface;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountHelper;
+use SP\Mvc\Controller\WebControllerHelper;
+use SP\Util\ErrorUtil;
+
+final class DeleteController extends AccountControllerBase
+{
+ private AccountHelper $accountHelper;
+ private ThemeIcons $icons;
+ private AccountServiceInterface $accountService;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ AccountHelper $accountHelper,
+ AccountServiceInterface $accountService
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountHelper = $accountHelper;
+ $this->accountService = $accountService;
+
+ $this->icons = $this->theme->getIcons();
+ }
+
+ /**
+ * Delete action
+ *
+ * @param int|null $id Account's ID
+ */
+ public function deleteAction(?int $id = null): void
+ {
+ try {
+ $accountDetailsResponse = $this->accountService->getById($id);
+ $this->accountService
+ ->withUsersById($accountDetailsResponse)
+ ->withUserGroupsById($accountDetailsResponse);
+
+ $this->accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_DELETE);
+
+ $this->view->addTemplate('account');
+ $this->view->assign(
+ 'title',
+ [
+ 'class' => 'titleRed',
+ 'name' => __('Remove Account'),
+ 'icon' => $this->icons->getIconDelete()->getIcon(),
+ ]
+ );
+ $this->view->assign('formRoute', 'account/saveDelete');
+
+ $this->eventDispatcher->notifyEvent('show.account.delete', new Event($this));
+
+ if ($this->isAjax === false) {
+ $this->upgradeView();
+ }
+
+ $this->view();
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent(
+ 'exception',
+ new Event($e)
+ );
+
+ if ($this->isAjax === false && !$this->view->isUpgraded()) {
+ $this->upgradeView();
+ }
+
+ ErrorUtil::showExceptionInView($this->view, $e, 'account');
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/EditController.php b/app/modules/web/Controllers/Account/EditController.php
new file mode 100644
index 00000000..95067425
--- /dev/null
+++ b/app/modules/web/Controllers/Account/EditController.php
@@ -0,0 +1,111 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Core\UI\ThemeIcons;
+use SP\Domain\Account\AccountServiceInterface;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountHelper;
+use SP\Mvc\Controller\WebControllerHelper;
+use SP\Util\ErrorUtil;
+
+final class EditController extends AccountControllerBase
+{
+ private AccountHelper $accountHelper;
+ private ThemeIcons $icons;
+ private AccountServiceInterface $accountService;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ AccountHelper $accountHelper,
+ \SP\Domain\Account\AccountServiceInterface $accountService
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountHelper = $accountHelper;
+ $this->accountService = $accountService;
+ $this->icons = $this->theme->getIcons();
+ }
+
+ /**
+ * Edit action
+ *
+ * @param int $id Account's ID
+ */
+ public function editAction(int $id): void
+ {
+ try {
+ $accountDetailsResponse = $this->accountService->getById($id);
+ $this->accountService
+ ->withUsersById($accountDetailsResponse)
+ ->withUserGroupsById($accountDetailsResponse)
+ ->withTagsById($accountDetailsResponse);
+
+ $this->accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_EDIT);
+
+ $this->view->addTemplate('account');
+ $this->view->assign(
+ 'title',
+ [
+ 'class' => 'titleOrange',
+ 'name' => __('Edit Account'),
+ 'icon' => $this->icons->getIconEdit()->getIcon(),
+ ]
+ );
+ $this->view->assign('formRoute', 'account/saveEdit');
+
+ $this->accountService->incrementViewCounter($id);
+
+ $this->eventDispatcher->notifyEvent('show.account.edit', new Event($this));
+
+ if ($this->isAjax === false) {
+ $this->upgradeView();
+ }
+
+ $this->view();
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent(
+ 'exception',
+ new Event($e)
+ );
+
+ if ($this->isAjax === false && !$this->view->isUpgraded()) {
+ $this->upgradeView();
+ }
+
+ ErrorUtil::showExceptionInView($this->view, $e, 'account');
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/EditPassController.php b/app/modules/web/Controllers/Account/EditPassController.php
new file mode 100644
index 00000000..29e3da85
--- /dev/null
+++ b/app/modules/web/Controllers/Account/EditPassController.php
@@ -0,0 +1,110 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use Psr\Container\ContainerExceptionInterface;
+use Psr\Container\NotFoundExceptionInterface;
+use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Core\UI\ThemeIcons;
+use SP\Domain\Account\AccountServiceInterface;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountHelper;
+use SP\Mvc\Controller\WebControllerHelper;
+use SP\Util\ErrorUtil;
+
+final class EditPassController extends AccountControllerBase
+{
+ private AccountHelper $accountHelper;
+ private ThemeIcons $icons;
+ private \SP\Domain\Account\AccountServiceInterface $accountService;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ AccountHelper $accountHelper,
+ AccountServiceInterface $accountService
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountHelper = $accountHelper;
+ $this->accountService = $accountService;
+ $this->icons = $this->theme->getIcons();
+ }
+
+ /**
+ * Obtener los datos para mostrar el interface para modificar la clave de cuenta
+ *
+ * @param int $id Account's ID
+ *
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ */
+ public function editPassAction(int $id): void
+ {
+ try {
+ $accountDetailsResponse = $this->accountService->getById($id);
+ $this->accountService
+ ->withUsersById($accountDetailsResponse)
+ ->withUserGroupsById($accountDetailsResponse);
+
+ $this->accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_EDIT_PASS);
+
+ $this->view->addTemplate('account-editpass');
+ $this->view->assign(
+ 'title',
+ [
+ 'class' => 'titleOrange',
+ 'name' => __('Edit Account Password'),
+ 'icon' => $this->icons->getIconEditPass()->getIcon(),
+ ]
+ );
+ $this->view->assign('formRoute', 'account/saveEditPass');
+
+ $this->eventDispatcher->notifyEvent('show.account.editpass', new Event($this));
+
+ if ($this->isAjax === false) {
+ $this->upgradeView();
+ }
+
+ $this->view();
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+
+ if ($this->isAjax === false && !$this->view->isUpgraded()) {
+ $this->upgradeView();
+ }
+
+ ErrorUtil::showExceptionInView($this->view, $e, 'account-editpass');
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/IndexController.php b/app/modules/web/Controllers/Account/IndexController.php
new file mode 100644
index 00000000..587e4bd1
--- /dev/null
+++ b/app/modules/web/Controllers/Account/IndexController.php
@@ -0,0 +1,73 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountSearchHelper;
+use SP\Mvc\Controller\WebControllerHelper;
+use SP\Util\ErrorUtil;
+
+final class IndexController extends AccountControllerBase
+{
+ private AccountSearchHelper $accountSearchHelper;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ AccountSearchHelper $accountSearchHelper
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountSearchHelper = $accountSearchHelper;
+ }
+
+ /**
+ * Index action
+ *
+ */
+ public function indexAction(): void
+ {
+ try {
+ $this->accountSearchHelper->getSearchBox();
+ $this->accountSearchHelper->getAccountSearch();
+
+ $this->eventDispatcher->notifyEvent('show.account.search', new Event($this));
+
+ $this->view();
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+
+ ErrorUtil::showExceptionInView($this->view, $e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/RequestAccessController.php b/app/modules/web/Controllers/Account/RequestAccessController.php
new file mode 100644
index 00000000..7de72efe
--- /dev/null
+++ b/app/modules/web/Controllers/Account/RequestAccessController.php
@@ -0,0 +1,94 @@
+.
+ */
+
+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\Helpers\Account\AccountHelper;
+use SP\Mvc\Controller\WebControllerHelper;
+use SP\Util\ErrorUtil;
+
+final class RequestAccessController extends AccountControllerBase
+{
+ private AccountHelper $accountHelper;
+ private AccountServiceInterface $accountService;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ AccountHelper $accountHelper,
+ AccountServiceInterface $accountService
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountHelper = $accountHelper;
+ $this->accountService = $accountService;
+ }
+
+ /**
+ * Obtener los datos para mostrar el interface de solicitud de cambios en una cuenta
+ *
+ * @param int $id Account's ID
+ *
+ */
+ public function requestAccessAction(int $id): void
+ {
+ try {
+ $this->accountHelper->setIsView(true);
+ $this->accountHelper->setViewForRequest(
+ $this->accountService->getById($id),
+ ActionsInterface::ACCOUNT_REQUEST
+ );
+
+ $this->view->addTemplate('account-request');
+ $this->view->assign('formRoute', 'account/saveRequest');
+
+ $this->eventDispatcher->notifyEvent('show.account.request', new Event($this));
+
+ if ($this->isAjax === false) {
+ $this->upgradeView();
+ }
+
+ $this->view();
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+
+ if ($this->isAjax === false && !$this->view->isUpgraded()) {
+ $this->upgradeView();
+ }
+
+ ErrorUtil::showExceptionInView($this->view, $e, 'account-request');
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/SaveCopyController.php b/app/modules/web/Controllers/Account/SaveCopyController.php
new file mode 100644
index 00000000..795c6402
--- /dev/null
+++ b/app/modules/web/Controllers/Account/SaveCopyController.php
@@ -0,0 +1,116 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Acl\Acl;
+use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Core\Events\EventMessage;
+use SP\Core\Exceptions\ValidationException;
+use SP\Domain\Account\AccountServiceInterface;
+use SP\Domain\CustomField\CustomFieldServiceInterface;
+use SP\Http\JsonResponse;
+use SP\Modules\Web\Controllers\Traits\JsonTrait;
+use SP\Modules\Web\Forms\AccountForm;
+use SP\Mvc\Controller\ItemTrait;
+use SP\Mvc\Controller\WebControllerHelper;
+
+final class SaveCopyController extends AccountControllerBase
+{
+ use JsonTrait, ItemTrait;
+
+ private AccountServiceInterface $accountService;
+ private AccountForm $accountForm;
+ private CustomFieldServiceInterface $customFieldService;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ AccountServiceInterface $accountService,
+ \SP\Domain\Account\AccountPresetServiceInterface $accountPresetService,
+ CustomFieldServiceInterface $customFieldService
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountService = $accountService;
+ $this->customFieldService = $customFieldService;
+ $this->accountForm = new AccountForm($application, $this->request, $accountPresetService);
+ }
+
+ /**
+ * @return bool
+ * @throws \JsonException
+ */
+ public function saveCopyAction(): ?bool
+ {
+ try {
+ $this->accountForm->validate(ActionsInterface::ACCOUNT_CREATE);
+
+ $accountId = $this->accountService->create($this->accountForm->getItemData());
+
+ $accountDetails = $this->accountService->getById($accountId)->getAccountVData();
+
+ $this->eventDispatcher->notifyEvent(
+ 'create.account',
+ new Event(
+ $this, EventMessage::factory()
+ ->addDescription(__u('Account created'))
+ ->addDetail(__u('Account'), $accountDetails->getName())
+ ->addDetail(__u('Client'), $accountDetails->getClientName())
+ )
+ );
+
+ $this->addCustomFieldsForItem(
+ ActionsInterface::ACCOUNT,
+ $accountId,
+ $this->request,
+ $this->customFieldService
+ );
+
+ return $this->returnJsonResponseData(
+ [
+ 'itemId' => $accountId,
+ 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT),
+ ],
+ JsonResponse::JSON_SUCCESS,
+ __u('Account created')
+ );
+ } catch (ValidationException $e) {
+ return $this->returnJsonResponseException($e);
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+
+ return $this->returnJsonResponseException($e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/SaveCreateController.php b/app/modules/web/Controllers/Account/SaveCreateController.php
new file mode 100644
index 00000000..6f9ecfea
--- /dev/null
+++ b/app/modules/web/Controllers/Account/SaveCreateController.php
@@ -0,0 +1,117 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Acl\Acl;
+use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Core\Events\EventMessage;
+use SP\Core\Exceptions\ValidationException;
+use SP\Domain\Account\AccountPresetServiceInterface;
+use SP\Domain\Account\AccountServiceInterface;
+use SP\Domain\CustomField\CustomFieldServiceInterface;
+use SP\Http\JsonResponse;
+use SP\Modules\Web\Controllers\Traits\JsonTrait;
+use SP\Modules\Web\Forms\AccountForm;
+use SP\Mvc\Controller\ItemTrait;
+use SP\Mvc\Controller\WebControllerHelper;
+
+final class SaveCreateController extends AccountControllerBase
+{
+ use JsonTrait, ItemTrait;
+
+ private AccountServiceInterface $accountService;
+ private AccountForm $accountForm;
+ private CustomFieldServiceInterface $customFieldService;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ AccountServiceInterface $accountService,
+ AccountPresetServiceInterface $accountPresetService,
+ CustomFieldServiceInterface $customFieldService
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountService = $accountService;
+ $this->customFieldService = $customFieldService;
+ $this->accountForm = new AccountForm($application, $this->request, $accountPresetService);
+ }
+
+ /**
+ * @return bool
+ * @throws \JsonException
+ */
+ public function saveCreateAction(): ?bool
+ {
+ try {
+ $this->accountForm->validate(ActionsInterface::ACCOUNT_CREATE);
+
+ $accountId = $this->accountService->create($this->accountForm->getItemData());
+
+ $accountDetails = $this->accountService->getById($accountId)->getAccountVData();
+
+ $this->eventDispatcher->notifyEvent(
+ 'create.account',
+ new Event(
+ $this, EventMessage::factory()
+ ->addDescription(__u('Account created'))
+ ->addDetail(__u('Account'), $accountDetails->getName())
+ ->addDetail(__u('Client'), $accountDetails->getClientName())
+ )
+ );
+
+ $this->addCustomFieldsForItem(
+ ActionsInterface::ACCOUNT,
+ $accountId,
+ $this->request,
+ $this->customFieldService
+ );
+
+ return $this->returnJsonResponseData(
+ [
+ 'itemId' => $accountId,
+ 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT),
+ ],
+ JsonResponse::JSON_SUCCESS,
+ __u('Account created')
+ );
+ } catch (ValidationException $e) {
+ return $this->returnJsonResponseException($e);
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+
+ return $this->returnJsonResponseException($e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/SaveDeleteController.php b/app/modules/web/Controllers/Account/SaveDeleteController.php
new file mode 100644
index 00000000..e3252cca
--- /dev/null
+++ b/app/modules/web/Controllers/Account/SaveDeleteController.php
@@ -0,0 +1,98 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Core\Events\EventMessage;
+use SP\Domain\Account\AccountServiceInterface;
+use SP\Domain\CustomField\CustomFieldServiceInterface;
+use SP\Http\JsonResponse;
+use SP\Modules\Web\Controllers\Traits\JsonTrait;
+use SP\Mvc\Controller\ItemTrait;
+use SP\Mvc\Controller\WebControllerHelper;
+
+final class SaveDeleteController extends AccountControllerBase
+{
+ use JsonTrait, ItemTrait;
+
+ private \SP\Domain\Account\AccountServiceInterface $accountService;
+ private CustomFieldServiceInterface $customFieldService;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ AccountServiceInterface $accountService,
+ CustomFieldServiceInterface $customFieldService
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountService = $accountService;
+ $this->customFieldService = $customFieldService;
+ }
+
+ /**
+ * Saves delete action
+ *
+ * @param int $id Account's ID
+ *
+ * @return bool
+ * @throws \JsonException
+ */
+ public function saveDeleteAction(int $id): bool
+ {
+ try {
+ $accountDetails = $this->accountService->getById($id)->getAccountVData();
+
+ $this->accountService->delete($id);
+
+ $this->eventDispatcher->notifyEvent(
+ 'delete.account',
+ new Event(
+ $this, EventMessage::factory()
+ ->addDescription(__u('Account removed'))
+ ->addDetail(__u('Account'), $accountDetails->getName())
+ ->addDetail(__u('Client'), $accountDetails->getClientName())
+ )
+ );
+
+ $this->deleteCustomFieldsForItem(ActionsInterface::ACCOUNT, $id, $this->customFieldService);
+
+ return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Account removed'));
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+
+ return $this->returnJsonResponseException($e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/SaveEditController.php b/app/modules/web/Controllers/Account/SaveEditController.php
new file mode 100644
index 00000000..38303be1
--- /dev/null
+++ b/app/modules/web/Controllers/Account/SaveEditController.php
@@ -0,0 +1,123 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Acl\Acl;
+use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Core\Events\EventMessage;
+use SP\Core\Exceptions\ValidationException;
+use SP\Domain\Account\AccountPresetServiceInterface;
+use SP\Domain\CustomField\CustomFieldServiceInterface;
+use SP\Http\JsonResponse;
+use SP\Modules\Web\Controllers\Traits\JsonTrait;
+use SP\Modules\Web\Forms\AccountForm;
+use SP\Mvc\Controller\ItemTrait;
+use SP\Mvc\Controller\WebControllerHelper;
+
+final class SaveEditController extends AccountControllerBase
+{
+ use JsonTrait, ItemTrait;
+
+ private \SP\Domain\Account\AccountServiceInterface $accountService;
+ private AccountForm $accountForm;
+ private CustomFieldServiceInterface $customFieldService;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ \SP\Domain\Account\AccountServiceInterface $accountService,
+ AccountPresetServiceInterface $accountPresetService,
+ CustomFieldServiceInterface $customFieldService
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountService = $accountService;
+ $this->customFieldService = $customFieldService;
+ $this->accountForm = new AccountForm($application, $this->request, $accountPresetService);
+ }
+
+ /**
+ * Saves edit action
+ *
+ * @param int $id Account's ID
+ *
+ * @return bool
+ * @throws \JsonException
+ */
+ public function saveEditAction(int $id): ?bool
+ {
+ try {
+ $this->accountForm->setItemId($id);
+ $this->accountForm->validate(ActionsInterface::ACCOUNT_EDIT);
+
+ $itemData = $this->accountForm->getItemData();
+
+ $this->accountService->update($itemData);
+
+ $accountDetails = $this->accountService->getById($id)->getAccountVData();
+
+ $this->eventDispatcher->notifyEvent(
+ 'edit.account',
+ new Event(
+ $this, EventMessage::factory()
+ ->addDescription(__u('Account updated'))
+ ->addDetail(__u('Account'), $accountDetails->getName())
+ ->addDetail(__u('Client'), $accountDetails->getClientName())
+ )
+ );
+
+ $this->updateCustomFieldsForItem(
+ ActionsInterface::ACCOUNT,
+ $id,
+ $this->request,
+ $this->customFieldService
+ );
+
+ return $this->returnJsonResponseData(
+ [
+ 'itemId' => $id,
+ 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW),
+ ],
+ JsonResponse::JSON_SUCCESS,
+ __u('Account updated')
+ );
+ } catch (ValidationException $e) {
+ return $this->returnJsonResponseException($e);
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+
+ return $this->returnJsonResponseException($e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/SaveEditPassController.php b/app/modules/web/Controllers/Account/SaveEditPassController.php
new file mode 100644
index 00000000..32a733d0
--- /dev/null
+++ b/app/modules/web/Controllers/Account/SaveEditPassController.php
@@ -0,0 +1,110 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Acl\Acl;
+use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Core\Events\EventMessage;
+use SP\Core\Exceptions\ValidationException;
+use SP\Domain\Account\AccountPresetServiceInterface;
+use SP\Domain\Account\AccountServiceInterface;
+use SP\Http\JsonResponse;
+use SP\Modules\Web\Controllers\Traits\JsonTrait;
+use SP\Modules\Web\Forms\AccountForm;
+use SP\Mvc\Controller\WebControllerHelper;
+
+final class SaveEditPassController extends AccountControllerBase
+{
+ use JsonTrait;
+
+ private AccountServiceInterface $accountService;
+ private AccountForm $accountForm;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ AccountServiceInterface $accountService,
+ AccountPresetServiceInterface $accountPresetService
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountService = $accountService;
+ $this->accountForm = new AccountForm($application, $this->request, $accountPresetService);
+ }
+
+ /**
+ * Saves edit action
+ *
+ * @param int $id Account's ID
+ *
+ * @return bool
+ * @throws \JsonException
+ */
+ public function saveEditPassAction(int $id): bool
+ {
+ try {
+ $this->accountForm->setItemId($id);
+ $this->accountForm->validate(ActionsInterface::ACCOUNT_EDIT_PASS);
+
+ $this->accountService->editPassword($this->accountForm->getItemData());
+
+ $accountDetails = $this->accountService->getById($id)->getAccountVData();
+
+ $this->eventDispatcher->notifyEvent(
+ 'edit.account.pass',
+ new Event(
+ $this, EventMessage::factory()
+ ->addDescription(__u('Password updated'))
+ ->addDetail(__u('Account'), $accountDetails->getName())
+ ->addDetail(__u('Client'), $accountDetails->getClientName())
+ )
+ );
+
+ return $this->returnJsonResponseData(
+ [
+ 'itemId' => $id,
+ 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW),
+ ],
+ JsonResponse::JSON_SUCCESS,
+ __u('Password updated')
+ );
+ } catch (ValidationException $e) {
+ return $this->returnJsonResponseException($e);
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+
+ return $this->returnJsonResponseException($e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/SaveEditRestoreController.php b/app/modules/web/Controllers/Account/SaveEditRestoreController.php
new file mode 100644
index 00000000..e9a84a43
--- /dev/null
+++ b/app/modules/web/Controllers/Account/SaveEditRestoreController.php
@@ -0,0 +1,100 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Acl\Acl;
+use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Core\Events\EventMessage;
+use SP\Domain\Account\AccountServiceInterface;
+use SP\Http\JsonResponse;
+use SP\Modules\Web\Controllers\Traits\JsonTrait;
+use SP\Mvc\Controller\WebControllerHelper;
+
+final class SaveEditRestoreController extends AccountControllerBase
+{
+ use JsonTrait;
+
+ private AccountServiceInterface $accountService;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ \SP\Domain\Account\AccountServiceInterface $accountService
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountService = $accountService;
+ }
+
+ /**
+ * Saves restore action
+ *
+ * @param int $historyId Account's history ID
+ * @param int $id Account's ID
+ *
+ * @return bool
+ * @throws \JsonException
+ */
+ public function saveEditRestoreAction(int $historyId, int $id): bool
+ {
+ try {
+ $this->accountService->editRestore($historyId, $id);
+
+ $accountDetails = $this->accountService->getById($id)->getAccountVData();
+
+ $this->eventDispatcher->notifyEvent(
+ 'edit.account.restore',
+ new Event(
+ $this, EventMessage::factory()
+ ->addDescription(__u('Account restored'))
+ ->addDetail(__u('Account'), $accountDetails->getName())
+ ->addDetail(__u('Client'), $accountDetails->getClientName())
+ )
+ );
+
+ return $this->returnJsonResponseData(
+ [
+ 'itemId' => $id,
+ 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW),
+ ],
+ JsonResponse::JSON_SUCCESS,
+ __u('Account restored')
+ );
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+
+ return $this->returnJsonResponseException($e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/SaveRequestController.php b/app/modules/web/Controllers/Account/SaveRequestController.php
new file mode 100644
index 00000000..a8cc6744
--- /dev/null
+++ b/app/modules/web/Controllers/Account/SaveRequestController.php
@@ -0,0 +1,135 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Acl\Acl;
+use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
+use SP\Core\Bootstrap\BootstrapBase;
+use SP\Core\Events\Event;
+use SP\Core\Events\EventMessage;
+use SP\Core\Exceptions\ValidationException;
+use SP\Domain\User\UserServiceInterface;
+use SP\Http\JsonResponse;
+use SP\Http\Uri;
+use SP\Modules\Web\Controllers\Traits\JsonTrait;
+use SP\Mvc\Controller\ItemTrait;
+use SP\Mvc\Controller\WebControllerHelper;
+
+final class SaveRequestController extends AccountControllerBase
+{
+ use JsonTrait, ItemTrait;
+
+ private \SP\Domain\Account\AccountServiceInterface $accountService;
+ private UserServiceInterface $userService;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ \SP\Domain\Account\AccountServiceInterface $accountService,
+ UserServiceInterface $userService
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountService = $accountService;
+ $this->userService = $userService;
+ }
+
+ /**
+ * Saves a request action
+ *
+ * @param int $id Account's ID
+ *
+ * @return bool
+ * @throws \JsonException
+ */
+ public function saveRequestAction(int $id): bool
+ {
+ try {
+ $description = $this->request->analyzeString('description');
+
+ if (empty($description)) {
+ throw new ValidationException(__u('A description is needed'));
+ }
+
+ $accountDetails = $this->accountService->getById($id)->getAccountVData();
+
+ $baseUrl = ($this->configData->getApplicationUrl() ?: BootstrapBase::$WEBURI).BootstrapBase::$SUBURI;
+
+ $deepLink = new Uri($baseUrl);
+ $deepLink->addParam('r', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW).'/'.$id);
+
+ $usersId = [$accountDetails->userId, $accountDetails->userEditId];
+
+ $this->eventDispatcher->notifyEvent(
+ 'request.account',
+ new Event(
+ $this, EventMessage::factory()
+ ->addDescription(__u('Request'))
+ ->addDetail(
+ __u('Requester'),
+ sprintf('%s (%s)', $this->userData->getName(), $this->userData->getLogin())
+ )
+ ->addDetail(__u('Account'), $accountDetails->getName())
+ ->addDetail(__u('Client'), $accountDetails->getClientName())
+ ->addDetail(__u('Description'), $description)
+ ->addDetail(__u('Link'), $deepLink->getUriSigned($this->configData->getPasswordSalt()))
+ ->addExtra('accountId', $id)
+ ->addExtra('whoId', $this->userData->getId())
+ ->setExtra('userId', $usersId)
+ ->setExtra(
+ 'email',
+ array_map(
+ static fn($value) => $value->email,
+ $this->userService->getUserEmailById($usersId)
+ )
+ )
+ )
+ );
+
+ return $this->returnJsonResponseData(
+ [
+ 'itemId' => $id,
+ 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT),
+ ],
+ JsonResponse::JSON_SUCCESS,
+ __u('Request done')
+ );
+ } catch (ValidationException $e) {
+ return $this->returnJsonResponseException($e);
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+
+ return $this->returnJsonResponseException($e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/SearchController.php b/app/modules/web/Controllers/Account/SearchController.php
new file mode 100644
index 00000000..79b664b3
--- /dev/null
+++ b/app/modules/web/Controllers/Account/SearchController.php
@@ -0,0 +1,76 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountSearchHelper;
+use SP\Modules\Web\Controllers\Traits\JsonTrait;
+use SP\Mvc\Controller\WebControllerHelper;
+
+final class SearchController extends AccountControllerBase
+{
+ use JsonTrait;
+
+ private AccountSearchHelper $accountSearchHelper;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ AccountSearchHelper $accountSearchHelper
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountSearchHelper = $accountSearchHelper;
+ }
+
+ /**
+ * @return bool
+ * @throws \JsonException
+ */
+ public function searchAction(): ?bool
+ {
+ try {
+ $this->accountSearchHelper->getAccountSearch();
+
+ $this->eventDispatcher->notifyEvent('show.account.search', new Event($this));
+
+ return $this->returnJsonResponseData([
+ 'html' => $this->render(),
+ ]);
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+
+ return $this->returnJsonResponseException($e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/ViewController.php b/app/modules/web/Controllers/Account/ViewController.php
new file mode 100644
index 00000000..2a18547a
--- /dev/null
+++ b/app/modules/web/Controllers/Account/ViewController.php
@@ -0,0 +1,109 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Core\UI\ThemeIcons;
+use SP\Domain\Account\AccountServiceInterface;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountHelper;
+use SP\Mvc\Controller\WebControllerHelper;
+use SP\Util\ErrorUtil;
+
+final class ViewController extends AccountControllerBase
+{
+ private \SP\Domain\Account\AccountServiceInterface $accountService;
+ private AccountHelper $accountHelper;
+ private ThemeIcons $icons;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ AccountServiceInterface $accountService,
+ AccountHelper $accountHelper
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountService = $accountService;
+ $this->accountHelper = $accountHelper;
+ $this->icons = $this->theme->getIcons();
+ }
+
+ /**
+ * View action
+ *
+ * @param int $id Account's ID
+ */
+ public function viewAction(int $id): void
+ {
+ try {
+ $this->view->addTemplate('account');
+
+ $accountDetailsResponse = $this->accountService->getById($id);
+ $this->accountService
+ ->withUsersById($accountDetailsResponse)
+ ->withUserGroupsById($accountDetailsResponse)
+ ->withTagsById($accountDetailsResponse);
+
+ $this->accountHelper->setIsView(true);
+ $this->accountHelper->setViewForAccount($accountDetailsResponse, ActionsInterface::ACCOUNT_VIEW);
+
+ $this->view->assign(
+ 'title',
+ [
+ 'class' => 'titleNormal',
+ 'name' => __('Account Details'),
+ 'icon' => $this->icons->getIconView()->getIcon(),
+ ]
+ );
+
+ $this->accountService->incrementViewCounter($id);
+
+ $this->eventDispatcher->notifyEvent('show.account', new Event($this));
+
+ if ($this->isAjax === false) {
+ $this->upgradeView();
+ }
+
+ $this->view();
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+
+ if ($this->isAjax === false && !$this->view->isUpgraded()) {
+ $this->upgradeView();
+ }
+
+ ErrorUtil::showExceptionInView($this->view, $e, 'account');
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/ViewHistoryController.php b/app/modules/web/Controllers/Account/ViewHistoryController.php
new file mode 100644
index 00000000..f1411817
--- /dev/null
+++ b/app/modules/web/Controllers/Account/ViewHistoryController.php
@@ -0,0 +1,101 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountHistoryHelper;
+use SP\Mvc\Controller\WebControllerHelper;
+use SP\Util\ErrorUtil;
+
+final class ViewHistoryController extends AccountControllerBase
+{
+ private \SP\Domain\Account\AccountHistoryServiceInterface $accountHistoryService;
+ private AccountHistoryHelper $accountHistoryHelper;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ \SP\Domain\Account\AccountHistoryServiceInterface $accountHistoryService,
+ AccountHistoryHelper $accountHistoryHelper
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountHistoryService = $accountHistoryService;
+ $this->accountHistoryHelper = $accountHistoryHelper;
+ }
+
+ /**
+ * Obtener los datos para mostrar el interface para ver cuenta en fecha concreta
+ *
+ * @param int $id Account's ID
+ */
+ public function viewHistoryAction(int $id): void
+ {
+ try {
+ $accountHistoryData = $this->accountHistoryService->getById($id);
+
+ $this->accountHistoryHelper->setView($accountHistoryData, ActionsInterface::ACCOUNT_HISTORY_VIEW);
+
+ $this->view->addTemplate('account-history');
+
+ $this->view->assign(
+ 'title',
+ [
+ 'class' => 'titleNormal',
+ 'name' => __('Account Details'),
+ 'icon' => 'access_time',
+ ]
+ );
+
+ $this->view->assign('formRoute', 'account/saveRestore');
+
+ $this->eventDispatcher->notifyEvent('show.account.history', new Event($this));
+
+ if ($this->isAjax === false) {
+ $this->upgradeView();
+ }
+
+ $this->view();
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+
+ if ($this->isAjax === false && !$this->view->isUpgraded()) {
+ $this->upgradeView();
+ }
+
+ ErrorUtil::showExceptionInView($this->view, $e, 'account-history');
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/ViewLinkController.php b/app/modules/web/Controllers/Account/ViewLinkController.php
new file mode 100644
index 00000000..b6b0f40d
--- /dev/null
+++ b/app/modules/web/Controllers/Account/ViewLinkController.php
@@ -0,0 +1,173 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Acl\Acl;
+use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
+use SP\Core\Bootstrap\BootstrapBase;
+use SP\Core\Crypt\Vault;
+use SP\Core\Events\Event;
+use SP\Core\Events\EventMessage;
+use SP\Core\UI\ThemeIcons;
+use SP\DataModel\AccountExtData;
+use SP\Domain\Account\PublicLinkServiceInterface;
+use SP\Domain\Account\Services\PublicLinkService;
+use SP\Http\Uri;
+use SP\Mvc\Controller\WebControllerHelper;
+use SP\Util\ErrorUtil;
+use SP\Util\ImageUtil;
+use SP\Util\Util;
+
+final class ViewLinkController extends AccountControllerBase
+{
+ private \SP\Domain\Account\AccountServiceInterface $accountService;
+ private ThemeIcons $icons;
+ private PublicLinkService $publicLinkService;
+ private ImageUtil $imageUtil;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ \SP\Domain\Account\AccountServiceInterface $accountService,
+ PublicLinkServiceInterface $publicLinkService,
+ ImageUtil $imageUtil
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountService = $accountService;
+ $this->publicLinkService = $publicLinkService;
+ $this->imageUtil = $imageUtil;
+
+ $this->icons = $this->theme->getIcons();
+ }
+
+ /**
+ * View public link action
+ *
+ * @param string $hash Link's hash
+ */
+ public function viewLinkAction(string $hash): void
+ {
+ try {
+ $this->layoutHelper->getPublicLayout('account-link', 'account');
+
+ $publicLinkData = $this->publicLinkService->getByHash($hash);
+
+ if (time() < $publicLinkData->getDateExpire()
+ && $publicLinkData->getCountViews() < $publicLinkData->getMaxCountViews()
+ ) {
+ $this->publicLinkService->addLinkView($publicLinkData);
+
+ $this->accountService->incrementViewCounter($publicLinkData->getItemId());
+ $this->accountService->incrementDecryptCounter($publicLinkData->getItemId());
+
+ /** @var Vault $vault */
+ $vault = unserialize($publicLinkData->getData(), ['allowed_classes' => [Vault::class]]);
+
+ /** @var AccountExtData $accountData */
+ $accountData = Util::unserialize(
+ AccountExtData::class,
+ $vault->getData($this->publicLinkService->getPublicLinkKey($publicLinkData->getHash())->getKey())
+ );
+
+ $this->view->assign(
+ 'title',
+ [
+ 'class' => 'titleNormal',
+ 'name' => __('Account Details'),
+ 'icon' => $this->icons->getIconView()->getIcon(),
+ ]
+ );
+
+ $this->view->assign('isView', true);
+ $this->view->assign(
+ 'useImage',
+ $this->configData->isPublinksImageEnabled()
+ || $this->configData->isAccountPassToImage()
+ );
+
+ if ($this->view->useImage) {
+ $this->view->assign(
+ 'accountPassImage',
+ $this->imageUtil->convertText($accountData->getPass())
+ );
+ } else {
+ $this->view->assign(
+ 'copyPassRoute',
+ Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW_PASS)
+ );
+ }
+
+ $this->view->assign('accountData', $accountData);
+
+ $clientAddress = $this->configData->isDemoEnabled()
+ ? '***'
+ : $this->request->getClientAddress(true);
+
+ $baseUrl = ($this->configData->getApplicationUrl() ?: BootstrapBase::$WEBURI).BootstrapBase::$SUBURI;
+
+ $deepLink = new Uri($baseUrl);
+ $deepLink->addParam('r', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW).'/'.$accountData->getId());
+
+ $this->eventDispatcher->notifyEvent(
+ 'show.account.link',
+ new Event(
+ $this, EventMessage::factory()
+ ->addDescription(__u('Link viewed'))
+ ->addDetail(__u('Account'), $accountData->getName())
+ ->addDetail(__u('Client'), $accountData->getClientName())
+ ->addDetail(__u('Agent'), $this->request->getHeader('User-Agent'))
+ ->addDetail(__u('HTTPS'), $this->request->isHttps() ? __u('ON') : __u('OFF'))
+ ->addDetail(__u('IP'), $clientAddress)
+ ->addDetail(__u('Link'), $deepLink->getUriSigned($this->configData->getPasswordSalt()))
+ ->addExtra('userId', $publicLinkData->getUserId())
+ ->addExtra('notify', $publicLinkData->isNotify())
+ )
+ );
+ } else {
+ ErrorUtil::showErrorInView(
+ $this->view,
+ ErrorUtil::ERR_PAGE_NO_PERMISSION,
+ true,
+ 'account-link'
+ );
+ }
+
+ $this->view();
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+
+ ErrorUtil::showExceptionInView($this->view, $e, 'account-link');
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/ViewPassController.php b/app/modules/web/Controllers/Account/ViewPassController.php
new file mode 100644
index 00000000..c2a531e9
--- /dev/null
+++ b/app/modules/web/Controllers/Account/ViewPassController.php
@@ -0,0 +1,124 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Core\Events\EventMessage;
+use SP\DataModel\ItemPreset\Password;
+use SP\Domain\Account\AccountServiceInterface;
+use SP\Domain\ItemPreset\ItemPresetInterface;
+use SP\Domain\ItemPreset\ItemPresetServiceInterface;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountPasswordHelper;
+use SP\Modules\Web\Controllers\Traits\JsonTrait;
+use SP\Mvc\Controller\WebControllerHelper;
+
+final class ViewPassController extends AccountControllerBase
+{
+ use JsonTrait;
+
+ private AccountServiceInterface $accountService;
+ private AccountPasswordHelper $accountPasswordHelper;
+ private ItemPresetServiceInterface $itemPresetService;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ AccountServiceInterface $accountService,
+ AccountPasswordHelper $accountPasswordHelper,
+ ItemPresetServiceInterface $itemPresetService
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountService = $accountService;
+ $this->accountPasswordHelper = $accountPasswordHelper;
+ $this->itemPresetService = $itemPresetService;
+ }
+
+ /**
+ * Display account's password
+ *
+ * @param int $id Account's ID
+ * @param int $parentId
+ *
+ * @return bool
+ * @throws \JsonException
+ */
+ public function viewPassAction(int $id, int $parentId = 0): ?bool
+ {
+ try {
+ $account = $this->accountService->getPasswordForId($id);
+
+ $passwordPreset = $this->getPasswordPreset();
+ $useImage = $this->configData->isAccountPassToImage()
+ || ($passwordPreset !== null && $passwordPreset->isUseImage());
+
+ $this->view->assign('isLinked', $parentId > 0);
+
+ $data = $this->accountPasswordHelper->getPasswordView($account, $useImage);
+
+ $this->accountService->incrementDecryptCounter($id);
+
+ $this->eventDispatcher->notifyEvent(
+ 'show.account.pass',
+ new Event(
+ $this, EventMessage::factory()
+ ->addDescription(__u('Password viewed'))
+ ->addDetail(__u('Account'), $account->getName())
+ )
+ );
+
+ return $this->returnJsonResponseData($data);
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+
+ return $this->returnJsonResponseException($e);
+ }
+ }
+
+ /**
+ * @return Password
+ * @throws \SP\Core\Exceptions\ConstraintException
+ * @throws \SP\Core\Exceptions\NoSuchPropertyException
+ * @throws \SP\Core\Exceptions\QueryException
+ */
+ private function getPasswordPreset(): ?Password
+ {
+ $itemPreset = $this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PASSWORD);
+
+ if ($itemPreset !== null && $itemPreset->getFixed() === 1) {
+ return $itemPreset->hydrate(Password::class);
+ }
+
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Account/ViewPassHistoryController.php b/app/modules/web/Controllers/Account/ViewPassHistoryController.php
new file mode 100644
index 00000000..d361821f
--- /dev/null
+++ b/app/modules/web/Controllers/Account/ViewPassHistoryController.php
@@ -0,0 +1,121 @@
+.
+ */
+
+namespace SP\Modules\Web\Controllers\Account;
+
+
+use Exception;
+use SP\Core\Application;
+use SP\Core\Events\Event;
+use SP\Core\Events\EventMessage;
+use SP\DataModel\ItemPreset\Password;
+use SP\Domain\Account\AccountServiceInterface;
+use SP\Domain\ItemPreset\ItemPresetInterface;
+use SP\Domain\ItemPreset\ItemPresetServiceInterface;
+use SP\Modules\Web\Controllers\Helpers\Account\AccountPasswordHelper;
+use SP\Modules\Web\Controllers\Traits\JsonTrait;
+use SP\Mvc\Controller\WebControllerHelper;
+
+final class ViewPassHistoryController extends AccountControllerBase
+{
+ use JsonTrait;
+
+ private AccountServiceInterface $accountService;
+ private AccountPasswordHelper $accountPasswordHelper;
+ private ItemPresetServiceInterface $itemPresetService;
+
+ public function __construct(
+ Application $application,
+ WebControllerHelper $webControllerHelper,
+ AccountServiceInterface $accountService,
+ AccountPasswordHelper $accountPasswordHelper,
+ ItemPresetServiceInterface $itemPresetService
+ ) {
+ parent::__construct(
+ $application,
+ $webControllerHelper
+ );
+
+ $this->accountService = $accountService;
+ $this->accountPasswordHelper = $accountPasswordHelper;
+ $this->itemPresetService = $itemPresetService;
+ }
+
+ /**
+ * Display account's password
+ *
+ * @param int $id Account's ID
+ *
+ * @return bool
+ * @throws \JsonException
+ */
+ public function viewPassHistoryAction(int $id): ?bool
+ {
+ try {
+ $account = $this->accountService->getPasswordHistoryForId($id);
+
+ $passwordPreset = $this->getPasswordPreset();
+ $useImage = $this->configData->isAccountPassToImage()
+ || ($passwordPreset !== null && $passwordPreset->isUseImage());
+
+ $this->view->assign('isLinked', 0);
+
+ $data = $this->accountPasswordHelper->getPasswordView($account, $useImage);
+
+ $this->eventDispatcher->notifyEvent(
+ 'show.account.pass.history',
+ new Event(
+ $this, EventMessage::factory()
+ ->addDescription(__u('Password viewed'))
+ ->addDetail(__u('Account'), $account->getName())
+ )
+ );
+
+ return $this->returnJsonResponseData($data);
+ } catch (Exception $e) {
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+
+ return $this->returnJsonResponseException($e);
+ }
+ }
+
+ /**
+ * @return Password
+ * @throws \SP\Core\Exceptions\ConstraintException
+ * @throws \SP\Core\Exceptions\NoSuchPropertyException
+ * @throws \SP\Core\Exceptions\QueryException
+ */
+ private function getPasswordPreset(): ?Password
+ {
+ $itemPreset = $this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PASSWORD);
+
+ if ($itemPreset !== null && $itemPreset->getFixed() === 1) {
+ return $itemPreset->hydrate(Password::class);
+ }
+
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/AccountController.php b/app/modules/web/Controllers/AccountController.php
deleted file mode 100644
index 1f2a2580..00000000
--- a/app/modules/web/Controllers/AccountController.php
+++ /dev/null
@@ -1,1316 +0,0 @@
-.
- */
-
-namespace SP\Modules\Web\Controllers;
-
-use Defuse\Crypto\Exception\CryptoException;
-use DI\DependencyException;
-use DI\NotFoundException;
-use Exception;
-use Psr\Container\ContainerExceptionInterface;
-use Psr\Container\NotFoundExceptionInterface;
-use SP\Core\Acl\Acl;
-use SP\Core\Acl\ActionsInterface;
-use SP\Core\Bootstrap\BootstrapBase;
-use SP\Core\Context\ContextBase;
-use SP\Core\Crypt\Vault;
-use SP\Core\Events\Event;
-use SP\Core\Events\EventMessage;
-use SP\Core\Exceptions\ConstraintException;
-use SP\Core\Exceptions\NoSuchPropertyException;
-use SP\Core\Exceptions\QueryException;
-use SP\Core\Exceptions\SessionTimeout;
-use SP\Core\Exceptions\SPException;
-use SP\Core\Exceptions\ValidationException;
-use SP\Core\UI\ThemeIcons;
-use SP\DataModel\AccountExtData;
-use SP\DataModel\ItemPreset\Password;
-use SP\Http\JsonResponse;
-use SP\Http\Uri;
-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\JsonTrait;
-use SP\Modules\Web\Forms\AccountForm;
-use SP\Mvc\Controller\CrudControllerInterface;
-use SP\Mvc\Controller\ItemTrait;
-use SP\Repositories\NoSuchItemException;
-use SP\Services\Account\AccountAclService;
-use SP\Services\Account\AccountHistoryService;
-use SP\Services\Account\AccountService;
-use SP\Services\Auth\AuthException;
-use SP\Services\ItemPreset\ItemPresetInterface;
-use SP\Services\ItemPreset\ItemPresetService;
-use SP\Services\PublicLink\PublicLinkService;
-use SP\Services\ServiceException;
-use SP\Services\User\UserService;
-use SP\Util\ErrorUtil;
-use SP\Util\ImageUtil;
-use SP\Util\Util;
-
-/**
- * Class AccountController
- *
- * @package SP\Modules\Web\Controllers
- */
-final class AccountController extends ControllerBase implements CrudControllerInterface
-{
- use JsonTrait, ItemTrait;
-
- protected ?AccountService $accountService = null;
- protected ?ThemeIcons $icons = null;
-
- /**
- * Index action
- *
- * @throws ContainerExceptionInterface
- */
- public function indexAction(): void
- {
- try {
- $accountSearchHelper = $this->dic->get(AccountSearchHelper::class);
- $accountSearchHelper->getSearchBox();
- $accountSearchHelper->getAccountSearch();
-
- $this->eventDispatcher->notifyEvent(
- 'show.account.search',
- new Event($this)
- );
-
- $this->view();
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- ErrorUtil::showExceptionInView($this->view, $e);
- }
- }
-
- /**
- * @return bool
- * @throws DependencyException
- * @throws NotFoundException
- * @throws \JsonException
- */
- public function searchAction(): ?bool
- {
- try {
- $accountSearchHelper = $this->dic->get(AccountSearchHelper::class);
- $accountSearchHelper->getAccountSearch();
-
- $this->eventDispatcher->notifyEvent(
- 'show.account.search',
- new Event($this)
- );
-
- return $this->returnJsonResponseData([
- 'html' => $this->render(),
- ]);
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- return $this->returnJsonResponseException($e);
- }
- }
-
- /**
- * View action
- *
- * @param int $id Account's ID
- *
- * @throws ContainerExceptionInterface
- * @throws NotFoundExceptionInterface
- */
- public function viewAction(int $id): void
- {
- try {
- $this->view->addTemplate('account');
-
- $accountDetailsResponse = $this->accountService->getById($id);
- $this->accountService
- ->withUsersById($accountDetailsResponse)
- ->withUserGroupsById($accountDetailsResponse)
- ->withTagsById($accountDetailsResponse);
-
- $accountHelper = $this->dic->get(AccountHelper::class);
- $accountHelper->setIsView(true);
- $accountHelper->setViewForAccount(
- $accountDetailsResponse,
- ActionsInterface::ACCOUNT_VIEW
- );
-
- $this->view->assign(
- 'title',
- [
- 'class' => 'titleNormal',
- 'name' => __('Account Details'),
- 'icon' => $this->icons->getIconView()->getIcon(),
- ]
- );
-
- $this->accountService->incrementViewCounter($id);
-
- $this->eventDispatcher->notifyEvent(
- 'show.account',
- new Event($this)
- );
-
- if ($this->isAjax === false) {
- $this->upgradeView();
- }
-
- $this->view();
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- if ($this->isAjax === false
- && !$this->view->isUpgraded()
- ) {
- $this->upgradeView();
- }
-
- ErrorUtil::showExceptionInView($this->view, $e, 'account');
- }
- }
-
- /**
- * View public link action
- *
- * @param string $hash Link's hash
- *
- * @throws ContainerExceptionInterface
- * @throws NotFoundExceptionInterface
- */
- public function viewLinkAction(string $hash): void
- {
- try {
- $layoutHelper = $this->dic->get(LayoutHelper::class);
- $layoutHelper->getPublicLayout('account-link', 'account');
-
- $publicLinkService = $this->dic->get(PublicLinkService::class);
- $publicLinkData = $publicLinkService->getByHash($hash);
-
- if (time() < $publicLinkData->getDateExpire()
- && $publicLinkData->getCountViews() < $publicLinkData->getMaxCountViews()
- ) {
- $publicLinkService->addLinkView($publicLinkData);
-
- $this->accountService->incrementViewCounter($publicLinkData->getItemId());
- $this->accountService->incrementDecryptCounter($publicLinkData->getItemId());
-
- /** @var Vault $vault */
- $vault = unserialize(
- $publicLinkData->getData(),
- ['allowed_classes' => [Vault::class]]
- );
-
- /** @var AccountExtData $accountData */
- $accountData = Util::unserialize(
- AccountExtData::class,
- $vault->getData($publicLinkService->getPublicLinkKey($publicLinkData->getHash())->getKey())
- );
-
- $this->view->assign(
- 'title',
- [
- 'class' => 'titleNormal',
- 'name' => __('Account Details'),
- 'icon' => $this->icons->getIconView()->getIcon(),
- ]
- );
-
- $this->view->assign('isView', true);
- $this->view->assign(
- 'useImage',
- $this->configData->isPublinksImageEnabled()
- || $this->configData->isAccountPassToImage()
- );
-
- if ($this->view->useImage) {
- $imageUtil = $this->dic->get(ImageUtil::class);
- $this->view->assign(
- 'accountPassImage',
- $imageUtil->convertText($accountData->getPass())
- );
- } else {
- $this->view->assign(
- 'copyPassRoute',
- Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW_PASS)
- );
- }
-
- $this->view->assign('accountData', $accountData);
-
- $clientAddress = $this->configData->isDemoEnabled()
- ? '***'
- : $this->request->getClientAddress(true);
-
- $baseUrl = ($this->configData->getApplicationUrl() ?: BootstrapBase::$WEBURI).BootstrapBase::$SUBURI;
-
- $deepLink = new Uri($baseUrl);
- $deepLink->addParam('r', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW).'/'.$accountData->getId());
-
- $this->eventDispatcher->notifyEvent(
- 'show.account.link',
- new Event(
- $this, EventMessage::factory()
- ->addDescription(__u('Link viewed'))
- ->addDetail(__u('Account'), $accountData->getName())
- ->addDetail(__u('Client'), $accountData->getClientName())
- ->addDetail(__u('Agent'), $this->request->getHeader('User-Agent'))
- ->addDetail(__u('HTTPS'), $this->request->isHttps() ? __u('ON') : __u('OFF'))
- ->addDetail(__u('IP'), $clientAddress)
- ->addDetail(__u('Link'), $deepLink->getUriSigned($this->configData->getPasswordSalt()))
- ->addExtra('userId', $publicLinkData->getUserId())
- ->addExtra('notify', $publicLinkData->isNotify())
- )
- );
- } else {
- ErrorUtil::showErrorInView(
- $this->view,
- ErrorUtil::ERR_PAGE_NO_PERMISSION,
- true,
- 'account-link'
- );
- }
-
- $this->view();
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- ErrorUtil::showExceptionInView($this->view, $e, 'account-link');
- }
- }
-
- /**
- * Create action
- */
- public function createAction(): void
- {
- try {
- $accountHelper = $this->dic->get(AccountHelper::class);
- $accountHelper->setViewForBlank(ActionsInterface::ACCOUNT_CREATE);
-
- $this->view->addTemplate('account');
- $this->view->assign(
- 'title',
- [
- 'class' => 'titleGreen',
- 'name' => __('New Account'),
- 'icon' => $this->icons->getIconAdd()->getIcon(),
- ]
- );
- $this->view->assign('formRoute', 'account/saveCreate');
-
- $this->eventDispatcher->notifyEvent(
- 'show.account.create',
- new Event($this)
- );
-
- if ($this->isAjax === false) {
- $this->upgradeView();
- }
-
- $this->view();
- } catch (Exception $e) {
- processException($e);
-
- if ($this->isAjax === false
- && !$this->view->isUpgraded()
- ) {
- $this->upgradeView();
- }
-
- ErrorUtil::showExceptionInView($this->view, $e, 'account');
- }
- }
-
- /**
- * Copy action
- *
- * @param int $id Account's ID
- *
- * @throws ContainerExceptionInterface
- * @throws NotFoundExceptionInterface
- */
- public function copyAction(int $id): void
- {
- try {
- $accountDetailsResponse = $this->accountService->getById($id);
- $this->accountService
- ->withUsersById($accountDetailsResponse)
- ->withUserGroupsById($accountDetailsResponse)
- ->withTagsById($accountDetailsResponse);
-
- $accountHelper = $this->dic->get(AccountHelper::class);
- $accountHelper->setViewForAccount(
- $accountDetailsResponse,
- ActionsInterface::ACCOUNT_COPY
- );
-
- $this->view->addTemplate('account');
- $this->view->assign(
- 'title',
- [
- 'class' => 'titleGreen',
- 'name' => __('New Account'),
- 'icon' => $this->icons->getIconAdd()->getIcon(),
- ]
- );
- $this->view->assign('formRoute', 'account/saveCopy');
-
- $this->eventDispatcher->notifyEvent(
- 'show.account.copy',
- new Event($this)
- );
-
- if ($this->isAjax === false) {
- $this->upgradeView();
- }
-
- $this->view();
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- if ($this->isAjax === false
- && !$this->view->isUpgraded()
- ) {
- $this->upgradeView();
- }
-
- ErrorUtil::showExceptionInView($this->view, $e, 'account');
- }
- }
-
- /**
- * Edit action
- *
- * @param int $id Account's ID
- *
- * @throws ContainerExceptionInterface
- * @throws NotFoundExceptionInterface
- */
- public function editAction(int $id): void
- {
- try {
- $accountDetailsResponse = $this->accountService->getById($id);
- $this->accountService
- ->withUsersById($accountDetailsResponse)
- ->withUserGroupsById($accountDetailsResponse)
- ->withTagsById($accountDetailsResponse);
-
- $accountHelper = $this->dic->get(AccountHelper::class);
- $accountHelper->setViewForAccount(
- $accountDetailsResponse,
- ActionsInterface::ACCOUNT_EDIT
- );
-
- $this->view->addTemplate('account');
- $this->view->assign(
- 'title',
- [
- 'class' => 'titleOrange',
- 'name' => __('Edit Account'),
- 'icon' => $this->icons->getIconEdit()->getIcon(),
- ]
- );
- $this->view->assign('formRoute', 'account/saveEdit');
-
- $this->accountService->incrementViewCounter($id);
-
- $this->eventDispatcher->notifyEvent(
- 'show.account.edit',
- new Event($this)
- );
-
- if ($this->isAjax === false) {
- $this->upgradeView();
- }
-
- $this->view();
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- if ($this->isAjax === false
- && !$this->view->isUpgraded()
- ) {
- $this->upgradeView();
- }
-
- ErrorUtil::showExceptionInView($this->view, $e, 'account');
- }
- }
-
- /**
- * Delete action
- *
- * @param int|null $id Account's ID
- *
- */
- public function deleteAction(?int $id = null): void
- {
- try {
- $accountDetailsResponse = $this->accountService->getById($id);
- $this->accountService
- ->withUsersById($accountDetailsResponse)
- ->withUserGroupsById($accountDetailsResponse);
-
- $accountHelper = $this->dic->get(AccountHelper::class);
- $accountHelper->setViewForAccount(
- $accountDetailsResponse,
- ActionsInterface::ACCOUNT_DELETE
- );
-
- $this->view->addTemplate('account');
- $this->view->assign(
- 'title',
- [
- 'class' => 'titleRed',
- 'name' => __('Remove Account'),
- 'icon' => $this->icons->getIconDelete()->getIcon(),
- ]
- );
- $this->view->assign('formRoute', 'account/saveDelete');
-
- $this->eventDispatcher->notifyEvent(
- 'show.account.delete',
- new Event($this)
- );
-
- if ($this->isAjax === false) {
- $this->upgradeView();
- }
-
- $this->view();
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- if ($this->isAjax === false
- && !$this->view->isUpgraded()
- ) {
- $this->upgradeView();
- }
-
- ErrorUtil::showExceptionInView($this->view, $e, 'account');
- }
- }
-
- /**
- * Obtener los datos para mostrar el interface para modificar la clave de cuenta
- *
- * @param int $id Account's ID
- *
- * @throws ContainerExceptionInterface
- * @throws NotFoundExceptionInterface
- */
- public function editPassAction(int $id): void
- {
- try {
- $accountDetailsResponse = $this->accountService->getById($id);
- $this->accountService
- ->withUsersById($accountDetailsResponse)
- ->withUserGroupsById($accountDetailsResponse);
-
- $accountHelper = $this->dic->get(AccountHelper::class);
- $accountHelper->setViewForAccount(
- $accountDetailsResponse,
- ActionsInterface::ACCOUNT_EDIT_PASS
- );
-
- $this->view->addTemplate('account-editpass');
- $this->view->assign(
- 'title',
- [
- 'class' => 'titleOrange',
- 'name' => __('Edit Account Password'),
- 'icon' => $this->icons->getIconEditPass()->getIcon(),
- ]
- );
- $this->view->assign('formRoute', 'account/saveEditPass');
-
- $this->eventDispatcher->notifyEvent(
- 'show.account.editpass',
- new Event($this)
- );
-
- if ($this->isAjax === false) {
- $this->upgradeView();
- }
-
- $this->view();
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- if ($this->isAjax === false
- && !$this->view->isUpgraded()
- ) {
- $this->upgradeView();
- }
-
- ErrorUtil::showExceptionInView(
- $this->view,
- $e,
- 'account-editpass'
- );
- }
- }
-
- /**
- * Obtener los datos para mostrar el interface para ver cuenta en fecha concreta
- *
- * @param int $id Account's ID
- *
- * @throws ContainerExceptionInterface
- * @throws NotFoundExceptionInterface
- */
- public function viewHistoryAction(int $id): void
- {
- try {
- $accountHistoryService = $this->dic->get(AccountHistoryService::class);
- $accountHistoryData = $accountHistoryService->getById($id);
-
- $accountHistoryHelper = $this->dic->get(AccountHistoryHelper::class);
- $accountHistoryHelper->setView(
- $accountHistoryData,
- ActionsInterface::ACCOUNT_HISTORY_VIEW
- );
-
- $this->view->addTemplate('account-history');
-
- $this->view->assign(
- 'title',
- [
- 'class' => 'titleNormal',
- 'name' => __('Account Details'),
- 'icon' => 'access_time',
- ]
- );
-
- $this->view->assign('formRoute', 'account/saveRestore');
-
- $this->eventDispatcher->notifyEvent(
- 'show.account.history',
- new Event($this)
- );
-
- if ($this->isAjax === false) {
- $this->upgradeView();
- }
-
- $this->view();
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- if ($this->isAjax === false
- && !$this->view->isUpgraded()
- ) {
- $this->upgradeView();
- }
-
- ErrorUtil::showExceptionInView(
- $this->view,
- $e,
- 'account-history'
- );
- }
- }
-
- /**
- * Obtener los datos para mostrar el interface de solicitud de cambios en una cuenta
- *
- * @param int $id Account's ID
- *
- * @throws ContainerExceptionInterface
- * @throws NotFoundExceptionInterface
- */
- public function requestAccessAction(int $id): void
- {
- try {
- $accountHelper = $this->dic->get(AccountHelper::class);
- $accountHelper->setIsView(true);
- $accountHelper->setViewForRequest(
- $this->accountService->getById($id),
- ActionsInterface::ACCOUNT_REQUEST
- );
-
- $this->view->addTemplate('account-request');
- $this->view->assign('formRoute', 'account/saveRequest');
-
- $this->eventDispatcher->notifyEvent(
- 'show.account.request',
- new Event($this)
- );
-
- if ($this->isAjax === false) {
- $this->upgradeView();
- }
-
- $this->view();
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- if ($this->isAjax === false
- && !$this->view->isUpgraded()
- ) {
- $this->upgradeView();
- }
-
- ErrorUtil::showExceptionInView(
- $this->view,
- $e,
- 'account-request'
- );
- }
- }
-
- /**
- * Display account's password
- *
- * @param int $id Account's ID
- * @param int $parentId
- *
- * @return bool
- * @throws \DI\DependencyException
- * @throws \DI\NotFoundException
- * @throws \JsonException
- */
- public function viewPassAction(int $id, int $parentId = 0): ?bool
- {
- try {
- $accountPassHelper = $this->dic->get(AccountPasswordHelper::class);
-
- $account = $this->accountService->getPasswordForId($id);
-
- $passwordPreset = $this->getPasswordPreset();
- $useImage = $this->configData->isAccountPassToImage()
- || ($passwordPreset !== null && $passwordPreset->isUseImage());
-
- $this->view->assign('isLinked', $parentId > 0);
-
- $data = $accountPassHelper->getPasswordView($account, $useImage);
-
- $this->accountService->incrementDecryptCounter($id);
-
- $this->eventDispatcher->notifyEvent(
- 'show.account.pass',
- new Event(
- $this, EventMessage::factory()
- ->addDescription(__u('Password viewed'))
- ->addDetail(__u('Account'), $account->getName())
- )
- );
-
- return $this->returnJsonResponseData($data);
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- return $this->returnJsonResponseException($e);
- }
- }
-
- /**
- * @return Password
- * @throws DependencyException
- * @throws NotFoundException
- * @throws ConstraintException
- * @throws NoSuchPropertyException
- * @throws QueryException
- */
- private function getPasswordPreset(): ?Password
- {
- $itemPreset = $this->dic->get(ItemPresetService::class)
- ->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PASSWORD);
-
- if ($itemPreset !== null && $itemPreset->getFixed() === 1) {
- return $itemPreset->hydrate(Password::class);
- }
-
- return null;
- }
-
- /**
- * Display account's password
- *
- * @param int $id Account's ID
- *
- * @return bool
- * @throws \DI\DependencyException
- * @throws \DI\NotFoundException
- * @throws \JsonException
- */
- public function viewPassHistoryAction(int $id): ?bool
- {
- try {
- $accountPassHelper = $this->dic->get(AccountPasswordHelper::class);
-
- $account = $this->accountService->getPasswordHistoryForId($id);
-
- $passwordPreset = $this->getPasswordPreset();
- $useImage = $this->configData->isAccountPassToImage()
- || ($passwordPreset !== null && $passwordPreset->isUseImage());
-
- $this->view->assign('isLinked', 0);
-
- $data = $accountPassHelper->getPasswordView($account, $useImage);
-
- $this->eventDispatcher->notifyEvent(
- 'show.account.pass.history',
- new Event(
- $this, EventMessage::factory()
- ->addDescription(__u('Password viewed'))
- ->addDetail(__u('Account'), $account->getName())
- )
- );
-
- return $this->returnJsonResponseData($data);
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- return $this->returnJsonResponseException($e);
- }
- }
-
- /**
- * Copy account's password
- *
- * @param int $id Account's ID
- *
- * @return bool
- * @throws Helpers\HelperException
- * @throws DependencyException
- * @throws NotFoundException
- * @throws CryptoException
- * @throws ConstraintException
- * @throws QueryException
- * @throws NoSuchItemException
- * @throws ServiceException
- * @throws SPException
- */
- public function copyPassAction(int $id): bool
- {
- $accountPassHelper = $this->dic->get(AccountPasswordHelper::class);
-
- $account = $this->accountService->getPasswordForId($id);
-
- $data = [
- 'accpass' => $accountPassHelper->getPasswordClear($account),
- ];
-
- $this->eventDispatcher->notifyEvent(
- 'copy.account.pass',
- new Event(
- $this, EventMessage::factory()
- ->addDescription(__u('Password copied'))
- ->addDetail(__u('Account'), $account->getName())
- )
- );
-
- return $this->returnJsonResponseData($data);
- }
-
- /**
- * Copy account's password
- *
- * @param int $id Account's ID
- *
- * @return bool
- * @throws Helpers\HelperException
- * @throws DependencyException
- * @throws NotFoundException
- * @throws CryptoException
- * @throws ConstraintException
- * @throws QueryException
- * @throws NoSuchItemException
- * @throws ServiceException
- * @throws SPException
- */
- public function copyPassHistoryAction(int $id): bool
- {
- $accountPassHelper = $this->dic->get(AccountPasswordHelper::class);
-
- $account = $this->accountService->getPasswordHistoryForId($id);
-
- $data = [
- 'accpass' => $accountPassHelper->getPasswordClear($account),
- ];
-
- $this->eventDispatcher->notifyEvent(
- 'copy.account.pass.history',
- new Event(
- $this, EventMessage::factory()
- ->addDescription(__u('Password copied'))
- ->addDetail(__u('Account'), $account->getName())
- )
- );
-
- return $this->returnJsonResponseData($data);
- }
-
- /**
- * @throws DependencyException
- * @throws NotFoundException
- * @throws \JsonException
- */
- public function saveCopyAction(): void
- {
- $this->saveCreateAction();
- }
-
- /**
- * @return bool
- * @throws \DI\DependencyException
- * @throws \DI\NotFoundException
- * @throws \JsonException
- */
- public function saveCreateAction(): ?bool
- {
- try {
- $form = new AccountForm($this->dic);
- $form->validate(ActionsInterface::ACCOUNT_CREATE);
-
- $accountId = $this->accountService->create($form->getItemData());
-
- $accountDetails = $this->accountService
- ->getById($accountId)
- ->getAccountVData();
-
- $this->eventDispatcher->notifyEvent(
- 'create.account',
- new Event(
- $this, EventMessage::factory()
- ->addDescription(__u('Account created'))
- ->addDetail(__u('Account'), $accountDetails->getName())
- ->addDetail(__u('Client'), $accountDetails->getClientName())
- )
- );
-
- $this->addCustomFieldsForItem(
- ActionsInterface::ACCOUNT,
- $accountId,
- $this->request
- );
-
- return $this->returnJsonResponseData(
- [
- 'itemId' => $accountId,
- 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_EDIT),
- ],
- JsonResponse::JSON_SUCCESS,
- __u('Account created')
- );
- } catch (ValidationException $e) {
- return $this->returnJsonResponseException($e);
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- return $this->returnJsonResponseException($e);
- }
- }
-
- /**
- * Saves edit action
- *
- * @param int $id Account's ID
- *
- * @return bool
- * @throws DependencyException
- * @throws NotFoundException
- * @throws \JsonException
- */
- public function saveEditAction(int $id): ?bool
- {
- try {
- $form = new AccountForm($this->dic, $id);
- $form->validate(ActionsInterface::ACCOUNT_EDIT);
-
- $itemData = $form->getItemData();
-
- $this->accountService->update($itemData);
-
- $accountDetails = $this->accountService
- ->getById($id)
- ->getAccountVData();
-
- $this->eventDispatcher->notifyEvent(
- 'edit.account',
- new Event(
- $this, EventMessage::factory()
- ->addDescription(__u('Account updated'))
- ->addDetail(__u('Account'), $accountDetails->getName())
- ->addDetail(__u('Client'), $accountDetails->getClientName())
- )
- );
-
- $this->updateCustomFieldsForItem(
- ActionsInterface::ACCOUNT,
- $id,
- $this->request
- );
-
- return $this->returnJsonResponseData(
- [
- 'itemId' => $id,
- 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW),
- ],
- JsonResponse::JSON_SUCCESS,
- __u('Account updated')
- );
- } catch (ValidationException $e) {
- return $this->returnJsonResponseException($e);
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- return $this->returnJsonResponseException($e);
- }
- }
-
- /**
- * Saves edit action
- *
- * @param int $id Account's ID
- *
- * @return bool
- * @throws \DI\DependencyException
- * @throws \DI\NotFoundException
- * @throws \JsonException
- */
- public function saveEditPassAction(int $id): bool
- {
- try {
- $form = new AccountForm($this->dic, $id);
- $form->validate(ActionsInterface::ACCOUNT_EDIT_PASS);
-
- $this->accountService->editPassword($form->getItemData());
-
- $accountDetails = $this->accountService
- ->getById($id)
- ->getAccountVData();
-
- $this->eventDispatcher->notifyEvent(
- 'edit.account.pass',
- new Event(
- $this, EventMessage::factory()
- ->addDescription(__u('Password updated'))
- ->addDetail(__u('Account'), $accountDetails->getName())
- ->addDetail(__u('Client'), $accountDetails->getClientName())
- )
- );
-
- return $this->returnJsonResponseData(
- [
- 'itemId' => $id,
- 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW),
- ],
- JsonResponse::JSON_SUCCESS,
- __u('Password updated')
- );
- } catch (ValidationException $e) {
- return $this->returnJsonResponseException($e);
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- return $this->returnJsonResponseException($e);
- }
- }
-
- /**
- * Saves restore action
- *
- * @param int $historyId Account's history ID
- * @param int $id Account's ID
- *
- * @return bool
- * @throws \DI\DependencyException
- * @throws \DI\NotFoundException
- * @throws \JsonException
- */
- public function saveEditRestoreAction(int $historyId, int $id): bool
- {
- try {
- $this->accountService->editRestore($historyId, $id);
-
- $accountDetails = $this->accountService
- ->getById($id)
- ->getAccountVData();
-
- $this->eventDispatcher->notifyEvent(
- 'edit.account.restore',
- new Event(
- $this, EventMessage::factory()
- ->addDescription(__u('Account restored'))
- ->addDetail(__u('Account'), $accountDetails->getName())
- ->addDetail(__u('Client'), $accountDetails->getClientName())
- )
- );
-
- return $this->returnJsonResponseData(
- [
- 'itemId' => $id,
- 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW),
- ],
- JsonResponse::JSON_SUCCESS,
- __u('Account restored')
- );
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- return $this->returnJsonResponseException($e);
- }
- }
-
- /**
- * Saves delete action
- *
- * @param int $id Account's ID
- *
- * @return bool
- * @throws \DI\DependencyException
- * @throws \DI\NotFoundException
- * @throws \JsonException
- */
- public function saveDeleteAction(int $id): bool
- {
- try {
- $accountDetails = $this->accountService
- ->getById($id)
- ->getAccountVData();
-
- $this->accountService->delete($id);
-
- $this->eventDispatcher->notifyEvent(
- 'delete.account',
- new Event(
- $this, EventMessage::factory()
- ->addDescription(__u('Account removed'))
- ->addDetail(__u('Account'), $accountDetails->getName())
- ->addDetail(__u('Client'), $accountDetails->getClientName())
- )
- );
-
- $this->deleteCustomFieldsForItem(ActionsInterface::ACCOUNT, $id);
-
- return $this->returnJsonResponse(
- JsonResponse::JSON_SUCCESS,
- __u('Account removed')
- );
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- return $this->returnJsonResponseException($e);
- }
- }
-
- /**
- * Saves a request action
- *
- * @param int $id Account's ID
- *
- * @return bool
- * @throws \DI\DependencyException
- * @throws \DI\NotFoundException
- * @throws \JsonException
- */
- public function saveRequestAction(int $id): bool
- {
- try {
- $description = $this->request->analyzeString('description');
-
- if (empty($description)) {
- throw new ValidationException(__u('A description is needed'));
- }
-
- $accountDetails = $this->accountService->getById($id)->getAccountVData();
-
- $baseUrl = ($this->configData->getApplicationUrl() ?: BootstrapBase::$WEBURI).BootstrapBase::$SUBURI;
-
- $deepLink = new Uri($baseUrl);
- $deepLink->addParam('r', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW).'/'.$id);
-
- $usersId = [$accountDetails->userId, $accountDetails->userEditId];
-
- $userService = $this->dic->get(UserService::class);
-
- $this->eventDispatcher->notifyEvent(
- 'request.account',
- new Event(
- $this, EventMessage::factory()
- ->addDescription(__u('Request'))
- ->addDetail(
- __u('Requester'),
- sprintf('%s (%s)', $this->userData->getName(), $this->userData->getLogin())
- )
- ->addDetail(__u('Account'), $accountDetails->getName())
- ->addDetail(__u('Client'), $accountDetails->getClientName())
- ->addDetail(__u('Description'), $description)
- ->addDetail(__u('Link'), $deepLink->getUriSigned($this->configData->getPasswordSalt()))
- ->addExtra('accountId', $id)
- ->addExtra('whoId', $this->userData->getId())
- ->setExtra('userId', $usersId)
- ->setExtra(
- 'email',
- array_map(
- static function ($value) {
- return $value->email;
- },
- $userService->getUserEmailById($usersId)
- )
- )
- )
- );
-
- return $this->returnJsonResponseData(
- [
- 'itemId' => $id,
- 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT),
- ],
- JsonResponse::JSON_SUCCESS,
- __u('Request done')
- );
- } catch (ValidationException $e) {
- return $this->returnJsonResponseException($e);
- } catch (Exception $e) {
- processException($e);
-
- $this->eventDispatcher->notifyEvent(
- 'exception',
- new Event($e)
- );
-
- return $this->returnJsonResponseException($e);
- }
- }
-
- /**
- * Initialize class
- *
- * @throws ContainerExceptionInterface
- * @throws NotFoundExceptionInterface
- * @throws AuthException
- * @throws SessionTimeout
- */
- protected function initialize(): void
- {
- if ($this->actionName !== 'viewLinkAction') {
- $this->checkLoggedIn();
- }
-
- if (DEBUG === true
- && $this->session->getAppStatus() === ContextBase::APP_STATUS_RELOADED
- ) {
- $this->session->resetAppStatus();
-
- // Reset de los datos de ACL de cuentas
- AccountAclService::clearAcl($this->session->getUserData()->getId());
- }
-
- $this->accountService = $this->dic->get(AccountService::class);
- $this->icons = $this->theme->getIcons();
- }
-}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/AccountFavoriteController.php b/app/modules/web/Controllers/AccountFavoriteController.php
index 9941ebeb..737f4909 100644
--- a/app/modules/web/Controllers/AccountFavoriteController.php
+++ b/app/modules/web/Controllers/AccountFavoriteController.php
@@ -29,9 +29,9 @@ use DI\NotFoundException;
use Exception;
use SP\Core\Events\Event;
use SP\Core\Exceptions\SessionTimeout;
+use SP\Domain\Account\Services\AccountToFavoriteService;
use SP\Http\JsonResponse;
use SP\Modules\Web\Controllers\Traits\JsonTrait;
-use SP\Services\Account\AccountToFavoriteService;
/**
* Class AccountFavoriteController
diff --git a/app/modules/web/Controllers/AccountFileController.php b/app/modules/web/Controllers/AccountFileController.php
index d9f3005b..a7579c5f 100644
--- a/app/modules/web/Controllers/AccountFileController.php
+++ b/app/modules/web/Controllers/AccountFileController.php
@@ -24,32 +24,34 @@
namespace SP\Modules\Web\Controllers;
-use DI\DependencyException;
-use DI\NotFoundException;
use Exception;
-use Psr\Container\ContainerExceptionInterface;
+use Klein\Klein;
use RuntimeException;
use SP\Core\Acl\Acl;
use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
-use SP\Core\Exceptions\ConstraintException;
-use SP\Core\Exceptions\QueryException;
-use SP\Core\Exceptions\SessionTimeout;
use SP\Core\Exceptions\SPException;
+use SP\Core\PhpExtensionChecker;
+use SP\Core\UI\ThemeInterface;
use SP\DataModel\FileData;
+use SP\Domain\Account\AccountFileServiceInterface;
+use SP\Domain\Account\AccountServiceInterface;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\Html;
use SP\Http\JsonResponse;
+use SP\Http\RequestInterface;
+use SP\Infrastructure\File\FileException;
+use SP\Infrastructure\File\FileHandler;
+use SP\Infrastructure\File\FileHandlerInterface;
use SP\Modules\Web\Controllers\Helpers\Grid\FileGrid;
+use SP\Modules\Web\Controllers\Helpers\LayoutHelper;
use SP\Modules\Web\Controllers\Traits\JsonTrait;
use SP\Mvc\Controller\CrudControllerInterface;
use SP\Mvc\Controller\ItemTrait;
-use SP\Services\Account\AccountFileService;
-use SP\Services\Account\AccountService;
-use SP\Services\Auth\AuthException;
-use SP\Storage\File\FileException;
-use SP\Storage\File\FileHandler;
+use SP\Mvc\View\TemplateInterface;
+use SP\Providers\Auth\Browser\BrowserAuthInterface;
use SP\Util\ErrorUtil;
use SP\Util\FileUtil;
@@ -64,16 +66,43 @@ final class AccountFileController extends ControllerBase implements CrudControll
use JsonTrait, ItemTrait;
- protected ?AccountFileService $accountFileService = null;
+ private AccountFileServiceInterface $accountFileService;
+ private AccountServiceInterface $accountService;
+ private FileGrid $fileGrid;
+
+ public function __construct(
+ Application $application,
+ ThemeInterface $theme,
+ Klein $router,
+ Acl $acl,
+ RequestInterface $request,
+ PhpExtensionChecker $extensionChecker,
+ TemplateInterface $template,
+ BrowserAuthInterface $browser,
+ LayoutHelper $layoutHelper
+ ) {
+ parent::__construct(
+ $application,
+ $theme,
+ $router,
+ $acl,
+ $request,
+ $extensionChecker,
+ $template,
+ $browser,
+ $layoutHelper
+ );
+
+ $this->checkLoggedIn();
+ }
+
/**
* View action
*
- * @param int $id
+ * @param int $id
*
* @return bool
- * @throws \DI\DependencyException
- * @throws \DI\NotFoundException
* @throws \JsonException
*/
public function viewAction(int $id): bool
@@ -92,10 +121,12 @@ final class AccountFileController extends ControllerBase implements CrudControll
$this->eventDispatcher->notifyEvent(
'show.accountFile',
- new Event($this,
+ new Event(
+ $this,
EventMessage::factory()
->addDescription(__u('File viewed'))
- ->addDetail(__u('File'), $fileData->getName()))
+ ->addDetail(__u('File'), $fileData->getName())
+ )
);
return $this->returnJsonResponseData(['html' => $this->render()]);
@@ -109,10 +140,12 @@ final class AccountFileController extends ControllerBase implements CrudControll
$this->eventDispatcher->notifyEvent(
'show.accountFile',
- new Event($this,
+ new Event(
+ $this,
EventMessage::factory()
->addDescription(__u('File viewed'))
- ->addDetail(__u('File'), $fileData->getName()))
+ ->addDetail(__u('File'), $fileData->getName())
+ )
);
return $this->returnJsonResponseData(['html' => $this->render()]);
@@ -137,7 +170,7 @@ final class AccountFileController extends ControllerBase implements CrudControll
/**
* Download action
*
- * @param int $id
+ * @param int $id
*
* @return string
*/
@@ -150,9 +183,11 @@ final class AccountFileController extends ControllerBase implements CrudControll
$this->eventDispatcher->notifyEvent(
'download.accountFile',
- new Event($this, EventMessage::factory()
+ new Event(
+ $this, EventMessage::factory()
->addDescription(__u('File downloaded'))
- ->addDetail(__u('File'), $fileData->getName()))
+ ->addDetail(__u('File'), $fileData->getName())
+ )
);
$response = $this->router->response();
@@ -196,11 +231,9 @@ final class AccountFileController extends ControllerBase implements CrudControll
/**
* Upload action
*
- * @param int $accountId
+ * @param int $accountId
*
* @return bool
- * @throws \DI\DependencyException
- * @throws \DI\NotFoundException
* @throws \JsonException
*/
public function uploadAction(int $accountId): bool
@@ -257,20 +290,19 @@ final class AccountFileController extends ControllerBase implements CrudControll
$this->accountFileService->create($fileData);
- $account = $this->dic->get(AccountService::class)
- ->getById($accountId)
- ->getAccountVData();
+ $account = $this->accountService->getById($accountId)->getAccountVData();
$this->eventDispatcher->notifyEvent(
'upload.accountFile',
- new Event($this,
+ new Event(
+ $this,
EventMessage::factory()
->addDescription(__u('File saved'))
->addDetail(__u('File'), $fileData->getName())
->addDetail(__u('Account'), $account->getName())
->addDetail(__u('Client'), $account->getClientName())
->addDetail(__u('Type'), $fileData->getType())
- ->addDetail(__u('Size'), $fileData->getRoundSize() . 'KB')
+ ->addDetail(__u('Size'), $fileData->getRoundSize().'KB')
)
);
@@ -301,15 +333,14 @@ final class AccountFileController extends ControllerBase implements CrudControll
}
/**
- * @param FileData $fileData
- *
- * @param FileHandler $fileHandler
+ * @param FileData $fileData
+ * @param FileHandlerInterface $fileHandler
*
* @return string
* @throws SPException
* @throws FileException
*/
- private function checkAllowedMimeType(FileData $fileData, FileHandler $fileHandler): string
+ private function checkAllowedMimeType(FileData $fileData, FileHandlerInterface $fileHandler): string
{
if (in_array($fileData->getType(), $this->configData->getFilesAllowedMime(), true)) {
return $fileData->getType();
@@ -330,12 +361,9 @@ final class AccountFileController extends ControllerBase implements CrudControll
* Search action
*
* @return bool
- * @throws DependencyException
- * @throws NotFoundException
- * @throws ConstraintException
- * @throws QueryException
- * @throws SPException
* @throws \JsonException
+ * @throws \SP\Core\Exceptions\ConstraintException
+ * @throws \SP\Core\Exceptions\QueryException
*/
public function searchAction(): bool
{
@@ -359,10 +387,9 @@ final class AccountFileController extends ControllerBase implements CrudControll
/**
* getSearchGrid
*
- * @throws DependencyException
- * @throws NotFoundException
- * @throws ConstraintException
- * @throws QueryException
+ * @return \SP\Html\DataGrid\DataGridInterface
+ * @throws \SP\Core\Exceptions\ConstraintException
+ * @throws \SP\Core\Exceptions\QueryException
*/
protected function getSearchGrid(): DataGridInterface
{
@@ -371,10 +398,8 @@ final class AccountFileController extends ControllerBase implements CrudControll
$this->request
);
- $fileGrid = $this->dic->get(FileGrid::class);
-
- return $fileGrid->updatePager(
- $fileGrid->getGrid($this->accountFileService->search($itemSearchData)),
+ return $this->fileGrid->updatePager(
+ $this->fileGrid->getGrid($this->accountFileService->search($itemSearchData)),
$itemSearchData
);
}
@@ -400,11 +425,9 @@ final class AccountFileController extends ControllerBase implements CrudControll
/**
* Delete action
*
- * @param int|null $id
+ * @param int|null $id
*
* @return bool
- * @throws \DI\DependencyException
- * @throws \DI\NotFoundException
* @throws \JsonException
*/
public function deleteAction(?int $id = null): bool
@@ -415,8 +438,10 @@ final class AccountFileController extends ControllerBase implements CrudControll
$this->eventDispatcher->notifyEvent(
'delete.accountFile.selection',
- new Event($this, EventMessage::factory()
- ->addDescription(__u('Files deleted')))
+ new Event(
+ $this,
+ EventMessage::factory()->addDescription(__u('Files deleted'))
+ )
);
return $this->returnJsonResponse(0, __u('Files deleted'));
@@ -424,9 +449,10 @@ final class AccountFileController extends ControllerBase implements CrudControll
$this->eventDispatcher->notifyEvent(
'delete.accountFile',
- new Event($this, EventMessage::factory()
- ->addDescription(__u('File deleted'))
- ->addDetail(__u('File'), $id))
+ new Event(
+ $this,
+ EventMessage::factory()->addDescription(__u('File deleted'))->addDetail(__u('File'), $id)
+ )
);
$this->accountFileService->delete($id);
@@ -465,14 +491,13 @@ final class AccountFileController extends ControllerBase implements CrudControll
/**
* Obtener los datos para la vista de archivos de una cuenta
*
- * @param int $accountId Account's ID
- *
- * @throws ContainerExceptionInterface
+ * @param int $accountId Account's ID
*/
public function listAction(int $accountId): void
{
if (!$this->configData->isFilesEnabled()) {
echo __('Files management disabled');
+
return;
}
@@ -480,7 +505,7 @@ final class AccountFileController extends ControllerBase implements CrudControll
$this->view->addTemplate('files-list', 'account');
$this->view->assign('deleteEnabled', $this->request->analyzeInt('del', false));
- $this->view->assign('files', $this->dic->get(AccountFileService::class)->getByAccountId($accountId));
+ $this->view->assign('files', $this->accountFileService->getByAccountId($accountId));
$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));
@@ -519,19 +544,4 @@ final class AccountFileController extends ControllerBase implements CrudControll
$this->view();
}
-
- /**
- * Initialize class
- *
- * @throws AuthException
- * @throws DependencyException
- * @throws NotFoundException
- * @throws SessionTimeout
- */
- protected function initialize(): void
- {
- $this->checkLoggedIn();
-
- $this->accountFileService = $this->dic->get(AccountFileService::class);
- }
}
diff --git a/app/modules/web/Controllers/AccountHistoryManagerController.php b/app/modules/web/Controllers/AccountHistoryManagerController.php
index 3c96bcef..4a61fc6a 100644
--- a/app/modules/web/Controllers/AccountHistoryManagerController.php
+++ b/app/modules/web/Controllers/AccountHistoryManagerController.php
@@ -24,23 +24,28 @@
namespace SP\Modules\Web\Controllers;
-use DI\DependencyException;
-use DI\NotFoundException;
use Exception;
+use Klein\Klein;
+use SP\Core\Acl\Acl;
use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
use SP\Core\Exceptions\ConstraintException;
use SP\Core\Exceptions\QueryException;
-use SP\Core\Exceptions\SessionTimeout;
+use SP\Core\PhpExtensionChecker;
+use SP\Core\UI\ThemeInterface;
+use SP\Domain\Account\AccountHistoryServiceInterface;
+use SP\Domain\Account\AccountServiceInterface;
use SP\Html\DataGrid\DataGridInterface;
use SP\Http\JsonResponse;
+use SP\Http\RequestInterface;
use SP\Modules\Web\Controllers\Helpers\Grid\AccountHistoryGrid;
+use SP\Modules\Web\Controllers\Helpers\LayoutHelper;
use SP\Modules\Web\Controllers\Traits\JsonTrait;
use SP\Mvc\Controller\ItemTrait;
-use SP\Services\Account\AccountHistoryService;
-use SP\Services\Account\AccountService;
-use SP\Services\Auth\AuthException;
+use SP\Mvc\View\TemplateInterface;
+use SP\Providers\Auth\Browser\BrowserAuthInterface;
/**
* Class AccountHistoryManagerController
@@ -51,12 +56,46 @@ final class AccountHistoryManagerController extends ControllerBase
{
use JsonTrait, ItemTrait;
- protected ?AccountHistoryService $accountHistoryService = null;
+ private AccountHistoryServiceInterface $accountHistoryService;
+ private AccountHistoryGrid $accountHistoryGrid;
+ private AccountServiceInterface $accountService;
+
+ public function __construct(
+ Application $application,
+ ThemeInterface $theme,
+ Klein $router,
+ Acl $acl,
+ RequestInterface $request,
+ PhpExtensionChecker $extensionChecker,
+ TemplateInterface $template,
+ BrowserAuthInterface $browser,
+ LayoutHelper $layoutHelper,
+ AccountHistoryServiceInterface $accountHistoryService,
+ Helpers\Grid\AccountHistoryGrid $accountHistoryGrid,
+ AccountServiceInterface $accountService
+ ) {
+ $this->accountHistoryService = $accountHistoryService;
+ $this->accountHistoryGrid = $accountHistoryGrid;
+ $this->accountService = $accountService;
+
+ parent::__construct(
+ $application,
+ $theme,
+ $router,
+ $acl,
+ $request,
+ $extensionChecker,
+ $template,
+ $browser,
+ $layoutHelper
+ );
+
+ $this->checkLoggedIn();
+ }
+
/**
* @return bool
- * @throws \DI\DependencyException
- * @throws \DI\NotFoundException
* @throws \JsonException
* @throws \SP\Core\Exceptions\ConstraintException
* @throws \SP\Core\Exceptions\QueryException
@@ -80,8 +119,6 @@ final class AccountHistoryManagerController extends ControllerBase
/**
* getSearchGrid
*
- * @throws DependencyException
- * @throws NotFoundException
* @throws ConstraintException
* @throws QueryException
*/
@@ -92,10 +129,8 @@ final class AccountHistoryManagerController extends ControllerBase
$this->request
);
- $historyGrid = $this->dic->get(AccountHistoryGrid::class);
-
- return $historyGrid->updatePager(
- $historyGrid->getGrid($this->accountHistoryService->search($itemSearchData)),
+ return $this->accountHistoryGrid->updatePager(
+ $this->accountHistoryGrid->getGrid($this->accountHistoryService->search($itemSearchData)),
$itemSearchData
);
}
@@ -103,11 +138,9 @@ final class AccountHistoryManagerController extends ControllerBase
/**
* Delete action
*
- * @param int|null $id
+ * @param int|null $id
*
* @return bool
- * @throws \DI\DependencyException
- * @throws \DI\NotFoundException
* @throws \JsonException
*/
public function deleteAction(?int $id = null): bool
@@ -164,11 +197,9 @@ final class AccountHistoryManagerController extends ControllerBase
/**
* Saves restore action
*
- * @param int $id Account's history ID
+ * @param int $id Account's history ID
*
* @return bool
- * @throws \DI\DependencyException
- * @throws \DI\NotFoundException
* @throws \JsonException
*/
public function restoreAction(int $id): bool
@@ -176,12 +207,10 @@ final class AccountHistoryManagerController extends ControllerBase
try {
$accountDetails = $this->accountHistoryService->getById($id);
- $accountService = $this->dic->get(AccountService::class);
-
if ($accountDetails->isModify) {
- $accountService->editRestore($id, $accountDetails->getAccountId());
+ $this->accountService->editRestore($id, $accountDetails->getAccountId());
} else {
- $accountService->createFromHistory($accountDetails);
+ $this->accountService->createFromHistory($accountDetails);
}
$this->eventDispatcher->notifyEvent(
@@ -210,19 +239,4 @@ final class AccountHistoryManagerController extends ControllerBase
return $this->returnJsonResponseException($e);
}
}
-
- /**
- * Initialize class
- *
- * @throws AuthException
- * @throws DependencyException
- * @throws NotFoundException
- * @throws SessionTimeout
- */
- protected function initialize(): void
- {
- $this->checkLoggedIn();
-
- $this->accountHistoryService = $this->dic->get(AccountHistoryService::class);
- }
}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/AccountManagerController.php b/app/modules/web/Controllers/AccountManagerController.php
index 8c626173..fd832c1e 100644
--- a/app/modules/web/Controllers/AccountManagerController.php
+++ b/app/modules/web/Controllers/AccountManagerController.php
@@ -24,35 +24,37 @@
namespace SP\Modules\Web\Controllers;
-use DI\DependencyException;
-use DI\NotFoundException;
use Exception;
+use Klein\Klein;
use SP\Core\Acl\Acl;
use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
-use SP\Core\Exceptions\ConstraintException;
-use SP\Core\Exceptions\QueryException;
-use SP\Core\Exceptions\SessionTimeout;
-use SP\Core\Exceptions\SPException;
+use SP\Core\PhpExtensionChecker;
+use SP\Core\UI\ThemeInterface;
+use SP\Domain\Account\AccountHistoryServiceInterface;
+use SP\Domain\Account\AccountSearchServiceInterface;
+use SP\Domain\Account\AccountServiceInterface;
+use SP\Domain\Account\Services\AccountBulkRequest;
+use SP\Domain\Account\Services\AccountSearchFilter;
+use SP\Domain\Category\Services\CategoryService;
+use SP\Domain\Client\Services\ClientService;
+use SP\Domain\CustomField\CustomFieldServiceInterface;
+use SP\Domain\Tag\Services\TagService;
+use SP\Domain\User\Services\UserGroupService;
+use SP\Domain\User\Services\UserService;
use SP\Html\DataGrid\DataGridInterface;
use SP\Http\JsonResponse;
+use SP\Http\RequestInterface;
use SP\Modules\Web\Controllers\Helpers\Grid\AccountGrid;
+use SP\Modules\Web\Controllers\Helpers\LayoutHelper;
use SP\Modules\Web\Controllers\Traits\JsonTrait;
use SP\Modules\Web\Forms\AccountForm;
use SP\Mvc\Controller\ItemTrait;
use SP\Mvc\View\Components\SelectItemAdapter;
-use SP\Services\Account\AccountBulkRequest;
-use SP\Services\Account\AccountHistoryService;
-use SP\Services\Account\AccountSearchFilter;
-use SP\Services\Account\AccountSearchService;
-use SP\Services\Account\AccountService;
-use SP\Services\Auth\AuthException;
-use SP\Services\Category\CategoryService;
-use SP\Services\Client\ClientService;
-use SP\Services\Tag\TagService;
-use SP\Services\User\UserService;
-use SP\Services\UserGroup\UserGroupService;
+use SP\Mvc\View\TemplateInterface;
+use SP\Providers\Auth\Browser\BrowserAuthInterface;
use SP\Util\Util;
/**
@@ -64,17 +66,55 @@ final class AccountManagerController extends ControllerBase
{
use JsonTrait, ItemTrait;
- protected ?AccountService $accountService = null;
- protected ?AccountSearchService $accountSearchService = null;
+ private AccountServiceInterface $accountService;
+ private AccountSearchServiceInterface $accountSearchService;
+ private AccountHistoryServiceInterface $accountHistoryService;
+ private AccountGrid $accountGrid;
+ private CustomFieldServiceInterface $customFieldService;
+
+ public function __construct(
+ Application $application,
+ ThemeInterface $theme,
+ Klein $router,
+ Acl $acl,
+ RequestInterface $request,
+ PhpExtensionChecker $extensionChecker,
+ TemplateInterface $template,
+ BrowserAuthInterface $browser,
+ LayoutHelper $layoutHelper,
+ AccountServiceInterface $accountService,
+ AccountSearchServiceInterface $accountSearchService,
+ AccountHistoryServiceInterface $accountHistoryService,
+ Helpers\Grid\AccountGrid $accountGrid,
+ CustomFieldServiceInterface $customFieldService
+ ) {
+ $this->accountService = $accountService;
+ $this->accountSearchService = $accountSearchService;
+ $this->accountHistoryService = $accountHistoryService;
+ $this->accountGrid = $accountGrid;
+ $this->customFieldService = $customFieldService;
+
+ parent::__construct(
+ $application,
+ $theme,
+ $router,
+ $acl,
+ $request,
+ $extensionChecker,
+ $template,
+ $browser,
+ $layoutHelper
+ );
+
+ $this->checkLoggedIn();
+ }
/**
* @return bool
- * @throws DependencyException
- * @throws NotFoundException
- * @throws ConstraintException
- * @throws QueryException
- * @throws SPException
* @throws \JsonException
+ * @throws \SP\Core\Exceptions\ConstraintException
+ * @throws \SP\Core\Exceptions\QueryException
+ * @throws \SP\Core\Exceptions\SPException
*/
public function searchAction(): bool
{
@@ -95,11 +135,10 @@ final class AccountManagerController extends ControllerBase
/**
* getSearchGrid
*
- * @throws DependencyException
- * @throws NotFoundException
- * @throws ConstraintException
- * @throws QueryException
- * @throws SPException
+ * @return \SP\Html\DataGrid\DataGridInterface
+ * @throws \SP\Core\Exceptions\ConstraintException
+ * @throws \SP\Core\Exceptions\QueryException
+ * @throws \SP\Core\Exceptions\SPException
*/
protected function getSearchGrid(): DataGridInterface
{
@@ -108,31 +147,31 @@ final class AccountManagerController extends ControllerBase
$this->request
);
- $accountGrid = $this->dic->get(AccountGrid::class);
-
$filter = new AccountSearchFilter();
$filter->setLimitCount($itemSearchData->getLimitCount());
$filter->setLimitStart($itemSearchData->getLimitStart());
if (!empty($itemSearchData->getSeachString())) {
- $filter->setStringFilters($this->accountSearchService->analyzeQueryFilters($itemSearchData->getSeachString()));
+ $filter->setStringFilters(
+ $this->accountSearchService->analyzeQueryFilters($itemSearchData->getSeachString())
+ );
$filter->setCleanTxtSearch($this->accountSearchService->getCleanString());
}
- return $accountGrid->updatePager(
- $accountGrid->getGrid(
- $this->accountService->getByFilter($filter)),
- $itemSearchData);
+ return $this->accountGrid->updatePager(
+ $this->accountGrid->getGrid(
+ $this->accountService->getByFilter($filter)
+ ),
+ $itemSearchData
+ );
}
/**
* Delete action
*
- * @param int|null $id
+ * @param int|null $id
*
* @return bool
- * @throws \DI\DependencyException
- * @throws \DI\NotFoundException
* @throws \JsonException
*/
public function deleteAction(?int $id = null): bool
@@ -141,7 +180,7 @@ final class AccountManagerController extends ControllerBase
if ($id === null) {
$this->accountService->deleteByIdBatch($this->getItemsIdFromRequest($this->request));
- $this->deleteCustomFieldsForItem(ActionsInterface::ACCOUNT, $id);
+ $this->deleteCustomFieldsForItem(ActionsInterface::ACCOUNT, $id, $this->customFieldService);
$this->eventDispatcher->notifyEvent(
'delete.account.selection',
@@ -164,7 +203,7 @@ final class AccountManagerController extends ControllerBase
$this->accountService->delete($id);
- $this->deleteCustomFieldsForItem(ActionsInterface::ACCOUNT, $id);
+ $this->deleteCustomFieldsForItem(ActionsInterface::ACCOUNT, $id, $this->customFieldService);
$this->eventDispatcher->notifyEvent(
'delete.account',
@@ -192,8 +231,6 @@ final class AccountManagerController extends ControllerBase
* saveBulkEditAction
*
* @return bool
- * @throws DependencyException
- * @throws NotFoundException
* @throws \JsonException
*/
public function saveBulkEditAction(): bool
@@ -204,12 +241,12 @@ final class AccountManagerController extends ControllerBase
$request = new AccountBulkRequest(
Util::itemsIdAdapter($this->request->analyzeString('itemsId')),
- $form->getItemData());
+ $form->getItemData()
+ );
$request->setDeleteHistory($this->request->analyzeBool('delete_history', false));
if ($request->isDeleteHistory()) {
- $accountHistoryService = $this->dic->get(AccountHistoryService::class);
- $accountHistoryService->deleteByAccountIdBatch($request->getItemsId());
+ $this->accountHistoryService->deleteByAccountIdBatch($request->getItemsId());
}
$this->accountService->updateBulk($request);
@@ -238,8 +275,6 @@ final class AccountManagerController extends ControllerBase
* bulkEditAction
*
* @return bool
- * @throws \DI\DependencyException
- * @throws \DI\NotFoundException
* @throws \JsonException
*/
public function bulkEditAction(): bool
@@ -279,12 +314,12 @@ final class AccountManagerController extends ControllerBase
{
$this->view->addTemplate('account_bulkedit', 'itemshow');
- $this->view->assign('nextAction', Acl::getActionRoute(Acl::ITEMS_MANAGE));
+ $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE));
+ // FIXME: Use IoC
$clients = SelectItemAdapter::factory(ClientService::getItemsBasic())->getItemsFromModel();
$categories = SelectItemAdapter::factory(CategoryService::getItemsBasic())->getItemsFromModel();
$tags = SelectItemAdapter::factory(TagService::getItemsBasic())->getItemsFromModel();
-
$users = SelectItemAdapter::factory(UserService::getItemsBasic())->getItemsFromModel();
$userGroups = SelectItemAdapter::factory(UserGroupService::getItemsBasic())->getItemsFromModel();
@@ -303,20 +338,4 @@ final class AccountManagerController extends ControllerBase
$this->view->assign('readonly', false);
}
}
-
- /**
- * Initialize class
- *
- * @throws AuthException
- * @throws DependencyException
- * @throws NotFoundException
- * @throws SessionTimeout
- */
- protected function initialize(): void
- {
- $this->checkLoggedIn();
-
- $this->accountService = $this->dic->get(AccountService::class);
- $this->accountSearchService = $this->dic->get(AccountSearchService::class);
- }
}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/AuthTokenController.php b/app/modules/web/Controllers/AuthTokenController.php
index 641cf82c..5c957031 100644
--- a/app/modules/web/Controllers/AuthTokenController.php
+++ b/app/modules/web/Controllers/AuthTokenController.php
@@ -37,6 +37,10 @@ use SP\Core\Exceptions\SessionTimeout;
use SP\Core\Exceptions\SPException;
use SP\Core\Exceptions\ValidationException;
use SP\DataModel\AuthTokenData;
+use SP\Domain\Auth\Services\AuthException;
+use SP\Domain\Auth\Services\AuthTokenService;
+use SP\Domain\Common\Services\ServiceException;
+use SP\Domain\User\Services\UserService;
use SP\Html\DataGrid\DataGridInterface;
use SP\Http\JsonResponse;
use SP\Modules\Web\Controllers\Helpers\Grid\AuthTokenGrid;
@@ -45,10 +49,6 @@ use SP\Modules\Web\Forms\AuthTokenForm;
use SP\Mvc\Controller\CrudControllerInterface;
use SP\Mvc\Controller\ItemTrait;
use SP\Mvc\View\Components\SelectItemAdapter;
-use SP\Services\Auth\AuthException;
-use SP\Services\AuthToken\AuthTokenService;
-use SP\Services\ServiceException;
-use SP\Services\User\UserService;
/**
* Class AuthTokenController
@@ -164,7 +164,7 @@ final class AuthTokenController extends ControllerBase implements CrudController
* @throws NotFoundException
* @throws QueryException
* @throws SPException
- * @throws ServiceException
+ * @throws \SP\Domain\Common\Services\ServiceException
*/
protected function setViewData(?int $authTokenId = null): void
{
diff --git a/app/modules/web/Controllers/BootstrapController.php b/app/modules/web/Controllers/Bootstrap/GetEnvironmentController.php
similarity index 83%
rename from app/modules/web/Controllers/BootstrapController.php
rename to app/modules/web/Controllers/Bootstrap/GetEnvironmentController.php
index e0c27585..6714de59 100644
--- a/app/modules/web/Controllers/BootstrapController.php
+++ b/app/modules/web/Controllers/Bootstrap/GetEnvironmentController.php
@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
- * @copyright 2012-2021, Rubén Domínguez nuxsmin@$syspass.org
+ * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -22,7 +22,7 @@
* along with sysPass. If not, see
'
- . __('Please, restart the session for update it')
+ .'
'
+ .__('Please, restart the session for update it')
);
}
@@ -145,13 +158,4 @@ final class AccountPasswordHelper extends HelperBase
)
);
}
-
- /**
- * @throws DependencyException
- * @throws NotFoundException
- */
- protected function initialize(): void
- {
- $this->acl = $this->dic->get(Acl::class);
- }
}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php
index 6662ed33..b86e0049 100644
--- a/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php
+++ b/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php
@@ -28,9 +28,17 @@ use DI\DependencyException;
use DI\NotFoundException;
use SP\Core\Acl\Acl;
use SP\Core\Acl\ActionsInterface;
+use SP\Core\Application;
use SP\Core\Exceptions\ConstraintException;
use SP\Core\Exceptions\QueryException;
use SP\Core\Exceptions\SPException;
+use SP\DataModel\ProfileData;
+use SP\DataModel\UserPreferencesData;
+use SP\Domain\Account\Services\AccountSearchFilter;
+use SP\Domain\Account\Services\AccountSearchItem;
+use SP\Domain\Category\Services\CategoryService;
+use SP\Domain\Client\ClientServiceInterface;
+use SP\Domain\Tag\Services\TagService;
use SP\Html\DataGrid\Action\DataGridAction;
use SP\Html\DataGrid\Action\DataGridActionSearch;
use SP\Html\DataGrid\DataGrid;
@@ -38,14 +46,10 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridSort;
use SP\Html\DataGrid\Layout\DataGridHeaderSort;
use SP\Html\DataGrid\Layout\DataGridPager;
+use SP\Http\RequestInterface;
use SP\Modules\Web\Controllers\Helpers\HelperBase;
use SP\Mvc\View\Components\SelectItemAdapter;
-use SP\Services\Account\AccountSearchFilter;
-use SP\Services\Account\AccountSearchItem;
-use SP\Services\Account\AccountSearchService;
-use SP\Services\Category\CategoryService;
-use SP\Services\Client\ClientService;
-use SP\Services\Tag\TagService;
+use SP\Mvc\View\TemplateInterface;
/**
* Class AccountSearch
@@ -57,19 +61,35 @@ 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 ?AccountSearchFilter $accountSearchFilter = null;
+ private bool $filterOn = false;
+ private int $queryTimeStart = 0;
+ private bool $isAjax = false;
+ private bool $isIndex = false;
+ private ?AccountSearchFilter $accountSearchFilter = null;
+ private ClientServiceInterface $clientService;
+ private \SP\Domain\Account\AccountSearchServiceInterface $accountSearchService;
+ private AccountActionsHelper $accountActionsHelper;
+
+ public function __construct(
+ Application $application,
+ TemplateInterface $template,
+ RequestInterface $request,
+ ClientServiceInterface $clientService,
+ \SP\Domain\Account\AccountSearchServiceInterface $accountSearchService,
+ AccountActionsHelper $accountActionsHelper
+ ) {
+ parent::__construct($application, $template, $request);
+
+ $this->clientService = $clientService;
+ $this->accountSearchService = $accountSearchService;
+ $this->accountActionsHelper = $accountActionsHelper;
+ }
/**
* Obtener los datos para la caja de búsqueda
*
- * @throws DependencyException
- * @throws NotFoundException
- * @throws ConstraintException
- * @throws QueryException
+ * @throws \SP\Core\Exceptions\ConstraintException
+ * @throws \SP\Core\Exceptions\QueryException
*/
public function getSearchBox(): void
{
@@ -77,20 +97,19 @@ final class AccountSearchHelper extends HelperBase
$this->view->assign(
'clients',
- SelectItemAdapter::factory(
- $this->dic->get(ClientService::class)
- ->getAllForUser())->getItemsFromModelSelected([$this->accountSearchFilter->getClientId()])
+ SelectItemAdapter::factory($this->clientService->getAllForUser())
+ ->getItemsFromModelSelected(
+ [$this->accountSearchFilter->getClientId()]
+ )
);
$this->view->assign(
'categories',
- SelectItemAdapter::factory(
- CategoryService::getItemsBasic())
+ SelectItemAdapter::factory(CategoryService::getItemsBasic())
->getItemsFromModelSelected([$this->accountSearchFilter->getCategoryId()])
);
$this->view->assign(
'tags',
- SelectItemAdapter::factory(
- TagService::getItemsBasic())
+ SelectItemAdapter::factory(TagService::getItemsBasic())
->getItemsFromModelSelected($this->accountSearchFilter->getTagsId())
);
}
@@ -111,14 +130,14 @@ final class AccountSearchHelper extends HelperBase
$this->view->assign('isAjax', $this->isAjax);
$this->filterOn = ($this->accountSearchFilter->getSortKey() > 1
- || $this->accountSearchFilter->getClientId()
- || $this->accountSearchFilter->getCategoryId()
- || $this->accountSearchFilter->getTagsId()
- || $this->accountSearchFilter->getTxtSearch()
- || $this->accountSearchFilter->isSearchFavorites()
- || $this->accountSearchFilter->isSortViews());
+ || $this->accountSearchFilter->getClientId()
+ || $this->accountSearchFilter->getCategoryId()
+ || $this->accountSearchFilter->getTagsId()
+ || $this->accountSearchFilter->getTxtSearch()
+ || $this->accountSearchFilter->isSearchFavorites()
+ || $this->accountSearchFilter->isSortViews());
- $userPreferences = $this->context->getUserData()->getPreferences();
+ $userPreferences = $this->context->getUserData()->getPreferences() ?? new UserPreferencesData();
AccountSearchItem::$accountLink = $userPreferences->isAccountLink();
AccountSearchItem::$topNavbar = $userPreferences->isTopNavbar();
@@ -147,15 +166,11 @@ final class AccountSearchHelper extends HelperBase
);
}
- $accountSearchService = $this->dic->get(AccountSearchService::class);
-
$dataGrid = $this->getGrid();
- $dataGrid->getData()
- ->setData($accountSearchService->processSearchResults($this->accountSearchFilter));
+ $dataGrid->getData()->setData($this->accountSearchService->processSearchResults($this->accountSearchFilter));
$dataGrid->updatePager();
$dataGrid->setTime(round(getElapsedTime($this->queryTimeStart), 5));
-
// Establecer el filtro de búsqueda en la sesión como un objeto
$this->context->setSearchFilters($this->accountSearchFilter);
@@ -197,13 +212,11 @@ final class AccountSearchHelper extends HelperBase
$gridPager->setFilterOn($this->filterOn);
$gridPager->setSourceAction(new DataGridActionSearch(ActionsInterface::ACCOUNT_SEARCH));
- $userPreferences = $this->context->getUserData()->getPreferences();
+ $userPreferences = $this->context->getUserData()->getPreferences() ?? new UserPreferencesData();
$showOptionalActions = $userPreferences->isOptionalActions()
- || $userPreferences->isResultsAsCards()
- || ($userPreferences->getUserId() === 0
- && $this->configData->isResultsAsCards());
-
- $actions = $this->dic->get(AccountActionsHelper::class);
+ || $userPreferences->isResultsAsCards()
+ || ($userPreferences->getUserId() === 0
+ && $this->configData->isResultsAsCards());
$dataGrid = new DataGrid($this->view->getTheme());
$dataGrid->setId('gridSearch');
@@ -217,22 +230,22 @@ final class AccountSearchHelper extends HelperBase
'grid'
);
$dataGrid->setHeader($this->getHeaderSort());
- $dataGrid->addDataAction($actions->getViewAction());
- $dataGrid->addDataAction($actions->getViewPassAction());
- $dataGrid->addDataAction($actions->getCopyPassAction());
+ $dataGrid->addDataAction($this->accountActionsHelper->getViewAction());
+ $dataGrid->addDataAction($this->accountActionsHelper->getViewPassAction());
+ $dataGrid->addDataAction($this->accountActionsHelper->getCopyPassAction());
$dataGrid->addDataAction(
- $actions->getEditAction(),
+ $this->accountActionsHelper->getEditAction(),
!$showOptionalActions
);
$dataGrid->addDataAction(
- $actions->getCopyAction(),
+ $this->accountActionsHelper->getCopyAction(),
!$showOptionalActions
);
$dataGrid->addDataAction(
- $actions->getDeleteAction(),
+ $this->accountActionsHelper->getDeleteAction(),
!$showOptionalActions
);
- $dataGrid->addDataAction($actions->getRequestAction());
+ $dataGrid->addDataAction($this->accountActionsHelper->getRequestAction());
$dataGrid->setPager($gridPager);
$dataGrid->setData(new DataGridData());
@@ -306,59 +319,31 @@ final class AccountSearchHelper extends HelperBase
/**
* Establecer las variables necesarias para las plantillas
*/
- private function setVars()
+ private function setVars(): void
{
$userData = $this->context->getUserData();
- $this->view->assign('isAdmin',
- $userData->getIsAdminApp()
- || $userData->getIsAdminAcc());
- $this->view->assign('showGlobalSearch',
- $this->configData->isGlobalSearch()
- && $this->context->getUserProfile()->isAccGlobalSearch());
+ $this->view->assign('isAdmin', $userData->getIsAdminApp() || $userData->getIsAdminAcc());
+
+ $profileData = $this->context->getUserProfile() ?? new ProfileData();
+
+ $this->view->assign(
+ 'showGlobalSearch',
+ $this->configData->isGlobalSearch() && $profileData->isAccGlobalSearch()
+ );
$this->accountSearchFilter = $this->getFilters();
- $this->view->assign(
- 'searchCustomer',
- $this->accountSearchFilter->getClientId()
- );
- $this->view->assign(
- 'searchCategory',
- $this->accountSearchFilter->getCategoryId()
- );
- $this->view->assign(
- 'searchTags',
- $this->accountSearchFilter->getTagsId()
- );
- $this->view->assign(
- 'searchTxt',
- $this->accountSearchFilter->getTxtSearch()
- );
- $this->view->assign(
- 'searchGlobal',
- $this->accountSearchFilter->getGlobalSearch()
- );
- $this->view->assign(
- 'searchFavorites',
- $this->accountSearchFilter->isSearchFavorites()
- );
- $this->view->assign(
- 'searchRoute',
- Acl::getActionRoute(ActionsInterface::ACCOUNT_SEARCH)
- );
- $this->view->assign(
- 'favoriteRouteOn',
- Acl::getActionRoute(ActionsInterface::ACCOUNT_FAVORITE_ADD)
- );
- $this->view->assign(
- 'favoriteRouteOff',
- Acl::getActionRoute(ActionsInterface::ACCOUNT_FAVORITE_DELETE)
- );
- $this->view->assign(
- 'viewAccountRoute',
- Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW)
- );
+ $this->view->assign('searchCustomer', $this->accountSearchFilter->getClientId());
+ $this->view->assign('searchCategory', $this->accountSearchFilter->getCategoryId());
+ $this->view->assign('searchTags', $this->accountSearchFilter->getTagsId());
+ $this->view->assign('searchTxt', $this->accountSearchFilter->getTxtSearch());
+ $this->view->assign('searchGlobal', $this->accountSearchFilter->getGlobalSearch());
+ $this->view->assign('searchFavorites', $this->accountSearchFilter->isSearchFavorites());
+ $this->view->assign('searchRoute', Acl::getActionRoute(ActionsInterface::ACCOUNT_SEARCH));
+ $this->view->assign('favoriteRouteOn', Acl::getActionRoute(ActionsInterface::ACCOUNT_FAVORITE_ADD));
+ $this->view->assign('favoriteRouteOff', Acl::getActionRoute(ActionsInterface::ACCOUNT_FAVORITE_DELETE));
+ $this->view->assign('viewAccountRoute', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW));
}
/**
@@ -375,7 +360,7 @@ final class AccountSearchHelper extends HelperBase
return $accountSearchFilter;
}
- $userPreferences = $this->context->getUserData()->getPreferences();
+ $userPreferences = $this->context->getUserData()->getPreferences() ?? new UserPreferencesData();
$limitCount = $userPreferences->getResultsPerPage() > 0
? $userPreferences->getResultsPerPage()
: $this->configData->getAccountCount();
diff --git a/app/modules/web/Controllers/Helpers/Grid/AccountGrid.php b/app/modules/web/Controllers/Helpers/Grid/AccountGrid.php
index b38ebbcf..08fac702 100644
--- a/app/modules/web/Controllers/Helpers/Grid/AccountGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/AccountGrid.php
@@ -34,7 +34,7 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Html\DataGrid\Layout\DataGridHeader;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
* Class AccountGrid
diff --git a/app/modules/web/Controllers/Helpers/Grid/AccountHistoryGrid.php b/app/modules/web/Controllers/Helpers/Grid/AccountHistoryGrid.php
index 76830c54..67011041 100644
--- a/app/modules/web/Controllers/Helpers/Grid/AccountHistoryGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/AccountHistoryGrid.php
@@ -33,7 +33,7 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Html\DataGrid\Layout\DataGridHeader;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
* Class AccountHistoryGrid
diff --git a/app/modules/web/Controllers/Helpers/Grid/AuthTokenGrid.php b/app/modules/web/Controllers/Helpers/Grid/AuthTokenGrid.php
index 9f15e761..39a87f52 100644
--- a/app/modules/web/Controllers/Helpers/Grid/AuthTokenGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/AuthTokenGrid.php
@@ -34,7 +34,7 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Html\DataGrid\Layout\DataGridHeader;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
* Class AuthTokenGrid
diff --git a/app/modules/web/Controllers/Helpers/Grid/CategoryGrid.php b/app/modules/web/Controllers/Helpers/Grid/CategoryGrid.php
index 1f7652cb..71988f90 100644
--- a/app/modules/web/Controllers/Helpers/Grid/CategoryGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/CategoryGrid.php
@@ -34,7 +34,7 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Html\DataGrid\Layout\DataGridHeader;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
* Class CategoryGrid
diff --git a/app/modules/web/Controllers/Helpers/Grid/ClientGrid.php b/app/modules/web/Controllers/Helpers/Grid/ClientGrid.php
index e01b6659..72d2c130 100644
--- a/app/modules/web/Controllers/Helpers/Grid/ClientGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/ClientGrid.php
@@ -33,7 +33,7 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Html\DataGrid\Layout\DataGridHeader;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
* Class ClientGrid
diff --git a/app/modules/web/Controllers/Helpers/Grid/CustomFieldGrid.php b/app/modules/web/Controllers/Helpers/Grid/CustomFieldGrid.php
index b82269c1..3651011c 100644
--- a/app/modules/web/Controllers/Helpers/Grid/CustomFieldGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/CustomFieldGrid.php
@@ -26,6 +26,7 @@ namespace SP\Modules\Web\Controllers\Helpers\Grid;
use SP\Core\Acl\Acl;
use SP\Core\Acl\ActionsInterface;
+use SP\Domain\CustomField\Services\CustomFieldDefService;
use SP\Html\DataGrid\Action\DataGridAction;
use SP\Html\DataGrid\Action\DataGridActionSearch;
use SP\Html\DataGrid\Action\DataGridActionType;
@@ -33,8 +34,7 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Html\DataGrid\Layout\DataGridHeader;
-use SP\Services\CustomField\CustomFieldDefService;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
* Class CustomFieldGrid
diff --git a/app/modules/web/Controllers/Helpers/Grid/EventlogGrid.php b/app/modules/web/Controllers/Helpers/Grid/EventlogGrid.php
index 405bd7d3..2540f142 100644
--- a/app/modules/web/Controllers/Helpers/Grid/EventlogGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/EventlogGrid.php
@@ -34,7 +34,7 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Html\DataGrid\Layout\DataGridHeader;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
* Class EventlogGrid
diff --git a/app/modules/web/Controllers/Helpers/Grid/FileGrid.php b/app/modules/web/Controllers/Helpers/Grid/FileGrid.php
index fc78540c..81ce525c 100644
--- a/app/modules/web/Controllers/Helpers/Grid/FileGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/FileGrid.php
@@ -33,7 +33,7 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Html\DataGrid\Layout\DataGridHeader;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
* Class FileGrid
diff --git a/app/modules/web/Controllers/Helpers/Grid/GridInterface.php b/app/modules/web/Controllers/Helpers/Grid/GridInterface.php
index affc4c9b..2eeed70f 100644
--- a/app/modules/web/Controllers/Helpers/Grid/GridInterface.php
+++ b/app/modules/web/Controllers/Helpers/Grid/GridInterface.php
@@ -25,7 +25,7 @@
namespace SP\Modules\Web\Controllers\Helpers\Grid;
use SP\Html\DataGrid\DataGridInterface;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
diff --git a/app/modules/web/Controllers/Helpers/Grid/ItemPresetGrid.php b/app/modules/web/Controllers/Helpers/Grid/ItemPresetGrid.php
index f0c4e1f2..01982df5 100644
--- a/app/modules/web/Controllers/Helpers/Grid/ItemPresetGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/ItemPresetGrid.php
@@ -26,6 +26,7 @@ namespace SP\Modules\Web\Controllers\Helpers\Grid;
use SP\Core\Acl\Acl;
use SP\Core\Acl\ActionsInterface;
+use SP\Domain\ItemPreset\ItemPresetInterface;
use SP\Html\DataGrid\Action\DataGridAction;
use SP\Html\DataGrid\Action\DataGridActionSearch;
use SP\Html\DataGrid\Action\DataGridActionType;
@@ -33,8 +34,7 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Html\DataGrid\Layout\DataGridHeader;
-use SP\Services\ItemPreset\ItemPresetInterface;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
* Class AccountDefaultPermissionGrid
diff --git a/app/modules/web/Controllers/Helpers/Grid/NotificationGrid.php b/app/modules/web/Controllers/Helpers/Grid/NotificationGrid.php
index ac7eeb93..c8dc85fa 100644
--- a/app/modules/web/Controllers/Helpers/Grid/NotificationGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/NotificationGrid.php
@@ -36,7 +36,7 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\Layout\DataGridHeader;
use SP\Html\Html;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
use SP\Util\DateUtil;
/**
diff --git a/app/modules/web/Controllers/Helpers/Grid/PluginGrid.php b/app/modules/web/Controllers/Helpers/Grid/PluginGrid.php
index 6656393d..af93c127 100644
--- a/app/modules/web/Controllers/Helpers/Grid/PluginGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/PluginGrid.php
@@ -34,7 +34,7 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Html\DataGrid\Layout\DataGridHeader;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
* Class PluginGrid
diff --git a/app/modules/web/Controllers/Helpers/Grid/PublicLinkGrid.php b/app/modules/web/Controllers/Helpers/Grid/PublicLinkGrid.php
index 0a99c43d..b12ed6c8 100644
--- a/app/modules/web/Controllers/Helpers/Grid/PublicLinkGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/PublicLinkGrid.php
@@ -34,7 +34,7 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Html\DataGrid\Layout\DataGridHeader;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
* Class PublicLinkGrid
diff --git a/app/modules/web/Controllers/Helpers/Grid/TagGrid.php b/app/modules/web/Controllers/Helpers/Grid/TagGrid.php
index a2d46e2c..95c6d068 100644
--- a/app/modules/web/Controllers/Helpers/Grid/TagGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/TagGrid.php
@@ -34,7 +34,7 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Html\DataGrid\Layout\DataGridHeader;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
* Class TagGrid
diff --git a/app/modules/web/Controllers/Helpers/Grid/TrackGrid.php b/app/modules/web/Controllers/Helpers/Grid/TrackGrid.php
index 9b736efa..b343e09e 100644
--- a/app/modules/web/Controllers/Helpers/Grid/TrackGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/TrackGrid.php
@@ -34,7 +34,7 @@ use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Html\DataGrid\Layout\DataGridHeader;
use SP\Http\Address;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
* Class TrackGrid
diff --git a/app/modules/web/Controllers/Helpers/Grid/UserGrid.php b/app/modules/web/Controllers/Helpers/Grid/UserGrid.php
index 4e29033a..89af2144 100644
--- a/app/modules/web/Controllers/Helpers/Grid/UserGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/UserGrid.php
@@ -34,7 +34,7 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Html\DataGrid\Layout\DataGridHeader;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
* Class UserGrid
diff --git a/app/modules/web/Controllers/Helpers/Grid/UserGroupGrid.php b/app/modules/web/Controllers/Helpers/Grid/UserGroupGrid.php
index 0fd9bdde..d2697b11 100644
--- a/app/modules/web/Controllers/Helpers/Grid/UserGroupGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/UserGroupGrid.php
@@ -34,7 +34,7 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Html\DataGrid\Layout\DataGridHeader;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
* Class UserGroupGrid
diff --git a/app/modules/web/Controllers/Helpers/Grid/UserProfileGrid.php b/app/modules/web/Controllers/Helpers/Grid/UserProfileGrid.php
index b16890bf..30efa33e 100644
--- a/app/modules/web/Controllers/Helpers/Grid/UserProfileGrid.php
+++ b/app/modules/web/Controllers/Helpers/Grid/UserProfileGrid.php
@@ -34,7 +34,7 @@ use SP\Html\DataGrid\DataGridData;
use SP\Html\DataGrid\DataGridInterface;
use SP\Html\DataGrid\DataGridTab;
use SP\Html\DataGrid\Layout\DataGridHeader;
-use SP\Storage\Database\QueryResult;
+use SP\Infrastructure\Database\QueryResult;
/**
* Class UserProfileGrid
diff --git a/app/modules/web/Controllers/Helpers/HelperBase.php b/app/modules/web/Controllers/Helpers/HelperBase.php
index 62a54821..7a8596b6 100644
--- a/app/modules/web/Controllers/Helpers/HelperBase.php
+++ b/app/modules/web/Controllers/Helpers/HelperBase.php
@@ -24,16 +24,14 @@
namespace SP\Modules\Web\Controllers\Helpers;
-use DI\Container;
-use DI\DependencyException;
-use DI\NotFoundException;
-use Psr\Container\ContainerInterface;
-use SP\Config\Config;
-use SP\Config\ConfigDataInterface;
+use SP\Core\Application;
use SP\Core\Context\ContextInterface;
use SP\Core\Events\EventDispatcher;
+use SP\Domain\Config\In\ConfigDataInterface;
+use SP\Domain\Config\Services\ConfigFileService;
use SP\Http\Request;
-use SP\Mvc\View\Template;
+use SP\Http\RequestInterface;
+use SP\Mvc\View\TemplateInterface;
/**
* Class HelperBase
@@ -42,34 +40,31 @@ use SP\Mvc\View\Template;
*/
abstract class HelperBase
{
- protected Template $view;
+ protected TemplateInterface $view;
protected ConfigDataInterface $configData;
- protected ContextInterface $context;
- protected EventDispatcher $eventDispatcher;
- protected Config $config;
- protected ContainerInterface $dic;
- protected Request $request;
+ protected ContextInterface $context;
+ protected EventDispatcher $eventDispatcher;
+ protected ConfigFileService $config;
+ protected Request $request;
/**
* Constructor
*
- * @throws DependencyException
- * @throws NotFoundException
+ * @param \SP\Core\Application $application
+ * @param \SP\Mvc\View\TemplateInterface $template
+ * @param \SP\Http\RequestInterface $request
*/
- final public function __construct(
- Template $template,
- Config $config,
- ContextInterface $context,
- EventDispatcher $eventDispatcher,
- Container $container)
- {
- $this->dic = $container;
- $this->request = $this->dic->get(Request::class);
+ public function __construct(
+ Application $application,
+ TemplateInterface $template,
+ RequestInterface $request
+ ) {
+ $this->config = $application->getConfig();
+ $this->context = $application->getContext();
+ $this->eventDispatcher = $application->getEventDispatcher();
+ $this->request = $request;
+ $this->configData = $this->config->getConfigData();
$this->view = $template;
- $this->config = $config;
- $this->configData = $config->getConfigData();
- $this->context = $context;
- $this->eventDispatcher = $eventDispatcher;
if (method_exists($this, 'initialize')) {
$this->initialize();
diff --git a/app/modules/web/Controllers/Helpers/ItemPresetHelper.php b/app/modules/web/Controllers/Helpers/ItemPresetHelper.php
index a96ba4ae..72f8ee5a 100644
--- a/app/modules/web/Controllers/Helpers/ItemPresetHelper.php
+++ b/app/modules/web/Controllers/Helpers/ItemPresetHelper.php
@@ -31,10 +31,10 @@ use SP\DataModel\ItemPreset\AccountPrivate;
use SP\DataModel\ItemPreset\Password;
use SP\DataModel\ItemPreset\SessionTimeout;
use SP\DataModel\ItemPresetData;
+use SP\Domain\User\Services\UserGroupService;
+use SP\Domain\User\Services\UserProfileService;
+use SP\Domain\User\Services\UserService;
use SP\Mvc\View\Components\SelectItemAdapter;
-use SP\Services\User\UserService;
-use SP\Services\UserGroup\UserGroupService;
-use SP\Services\UserProfile\UserProfileService;
/**
* Class ItemPresetHelper
diff --git a/app/modules/web/Controllers/Helpers/LayoutHelper.php b/app/modules/web/Controllers/Helpers/LayoutHelper.php
index bf9d7a51..25e029a3 100644
--- a/app/modules/web/Controllers/Helpers/LayoutHelper.php
+++ b/app/modules/web/Controllers/Helpers/LayoutHelper.php
@@ -24,20 +24,21 @@
namespace SP\Modules\Web\Controllers\Helpers;
-use Psr\Container\ContainerExceptionInterface;
-use Psr\Container\NotFoundExceptionInterface;
use SP\Core\Acl\Acl;
use SP\Core\Acl\ActionsInterface;
use SP\Core\AppInfoInterface;
+use SP\Core\Application;
use SP\Core\Bootstrap\BootstrapBase;
use SP\Core\Crypt\CryptPKI;
use SP\Core\Exceptions\SPException;
use SP\Core\Language;
use SP\Core\UI\ThemeInterface;
+use SP\Domain\Install\Services\Installer;
use SP\Html\DataGrid\Action\DataGridAction;
+use SP\Http\RequestInterface;
use SP\Http\Uri;
+use SP\Mvc\View\TemplateInterface;
use SP\Plugin\PluginManager;
-use SP\Services\Install\Installer;
use SP\Util\VersionUtil;
/**
@@ -47,8 +48,29 @@ use SP\Util\VersionUtil;
*/
final class LayoutHelper extends HelperBase
{
- protected ?bool $loggedIn = null;
- protected ?ThemeInterface $theme = null;
+ private ThemeInterface $theme;
+ private CryptPKI $cryptPKI;
+ private PluginManager $pluginManager;
+ private bool $loggedIn;
+
+ public function __construct(
+ Application $application,
+ TemplateInterface $template,
+ RequestInterface $request,
+ ThemeInterface $theme,
+ CryptPKI $cryptPKI,
+ PluginManager $pluginManager
+ ) {
+ parent::__construct($application, $template, $request);
+
+ $this->theme = $theme;
+ $this->cryptPKI = $cryptPKI;
+ $this->pluginManager = $pluginManager;
+ $this->loggedIn = $this->context->isLoggedIn();
+
+ $this->view->assign('loggedIn', $this->loggedIn);
+ }
+
/**
* Sets a full layout page
@@ -113,7 +135,7 @@ final class LayoutHelper extends HelperBase
try {
// Cargar la clave pública en la sesión
- $this->context->setPublicKey($this->dic->get(CryptPKI::class)->getPublicKey());
+ $this->context->setPublicKey($this->cryptPKI->getPublicKey());
} catch (SPException $e) {
processException($e);
}
@@ -199,7 +221,7 @@ final class LayoutHelper extends HelperBase
}
// Cargar los recursos de los plugins
- $loadedPlugins = $this->dic->get(PluginManager::class)->getLoadedPlugins();
+ $loadedPlugins = $this->pluginManager->getLoadedPlugins();
foreach ($loadedPlugins as $plugin) {
$base = str_replace(APP_ROOT, '', $plugin->getBase());
@@ -418,10 +440,8 @@ final class LayoutHelper extends HelperBase
*
* @return LayoutHelper
*/
- public function getCustomLayout(
- string $template,
- string $page = ''
- ): LayoutHelper {
+ public function getCustomLayout(string $template, string $page = ''): LayoutHelper
+ {
$this->view->addTemplate('main', '_layouts');
$this->view->addContentTemplate($template);
@@ -430,17 +450,4 @@ final class LayoutHelper extends HelperBase
return $this;
}
-
- /**
- * @throws ContainerExceptionInterface
- * @throws NotFoundExceptionInterface
- */
- protected function initialize(): void
- {
- $this->theme = $this->dic->get(ThemeInterface::class);
-
- $this->loggedIn = $this->context->isLoggedIn();
-
- $this->view->assign('loggedIn', $this->loggedIn);
- }
}
\ No newline at end of file
diff --git a/app/modules/web/Controllers/IndexController.php b/app/modules/web/Controllers/Index/IndexController.php
similarity index 67%
rename from app/modules/web/Controllers/IndexController.php
rename to app/modules/web/Controllers/Index/IndexController.php
index 0cce608b..d1ff0518 100644
--- a/app/modules/web/Controllers/IndexController.php
+++ b/app/modules/web/Controllers/Index/IndexController.php
@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
- * @copyright 2012-2021, Rubén Domínguez nuxsmin@$syspass.org
+ * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -22,11 +22,11 @@
* along with sysPass. If not, see