mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-06 16:36:59 +01:00
chore(tests): UT for ItemPreset
Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -36,7 +36,7 @@ use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\NoSuchPropertyException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetService;
|
||||
use SP\Modules\Web\Controllers\Helpers\Account\AccountPasswordHelper;
|
||||
use SP\Modules\Web\Controllers\Traits\JsonTrait;
|
||||
use SP\Mvc\Controller\WebControllerHelper;
|
||||
@@ -50,14 +50,14 @@ final class ViewPassController extends AccountControllerBase
|
||||
|
||||
private AccountService $accountService;
|
||||
private AccountPasswordHelper $accountPasswordHelper;
|
||||
private ItemPresetServiceInterface $itemPresetService;
|
||||
private ItemPresetService $itemPresetService;
|
||||
|
||||
public function __construct(
|
||||
Application $application,
|
||||
WebControllerHelper $webControllerHelper,
|
||||
AccountService $accountService,
|
||||
AccountPasswordHelper $accountPasswordHelper,
|
||||
ItemPresetServiceInterface $itemPresetService
|
||||
ItemPresetService $itemPresetService
|
||||
) {
|
||||
parent::__construct(
|
||||
$application,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -36,7 +36,7 @@ use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\NoSuchPropertyException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetService;
|
||||
use SP\Modules\Web\Controllers\Helpers\Account\AccountPasswordHelper;
|
||||
use SP\Modules\Web\Controllers\Traits\JsonTrait;
|
||||
use SP\Mvc\Controller\WebControllerHelper;
|
||||
@@ -50,14 +50,14 @@ final class ViewPassHistoryController extends AccountControllerBase
|
||||
|
||||
private AccountService $accountService;
|
||||
private AccountPasswordHelper $accountPasswordHelper;
|
||||
private ItemPresetServiceInterface $itemPresetService;
|
||||
private ItemPresetService $itemPresetService;
|
||||
|
||||
public function __construct(
|
||||
Application $application,
|
||||
WebControllerHelper $webControllerHelper,
|
||||
AccountService $accountService,
|
||||
AccountPasswordHelper $accountPasswordHelper,
|
||||
ItemPresetServiceInterface $itemPresetService
|
||||
ItemPresetService $itemPresetService
|
||||
) {
|
||||
parent::__construct(
|
||||
$application,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -29,7 +29,7 @@ use JsonException;
|
||||
use SP\Core\Application;
|
||||
use SP\Core\Events\Event;
|
||||
use SP\Core\Events\EventMessage;
|
||||
use SP\DataModel\FileData;
|
||||
use SP\DataModel\FileItemWithIdAndName;
|
||||
use SP\Domain\Account\Ports\AccountFileService;
|
||||
use SP\Domain\Account\Ports\AccountService;
|
||||
use SP\Domain\Core\Exceptions\SPException;
|
||||
@@ -92,7 +92,7 @@ final class UploadController extends ControllerBase
|
||||
try {
|
||||
$fileHandler = new FileHandler($file['tmp_name']);
|
||||
|
||||
$fileData = new FileData();
|
||||
$fileData = new FileItemWithIdAndName();
|
||||
$fileData->setAccountId($accountId);
|
||||
$fileData->setName(htmlspecialchars($file['name'], ENT_QUOTES));
|
||||
$fileData->setSize($file['size']);
|
||||
@@ -161,14 +161,14 @@ final class UploadController extends ControllerBase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FileData $fileData
|
||||
* @param FileItemWithIdAndName $fileData
|
||||
* @param FileHandlerInterface $fileHandler
|
||||
*
|
||||
* @return string
|
||||
* @throws SPException
|
||||
* @throws FileException
|
||||
*/
|
||||
private function checkAllowedMimeType(FileData $fileData, FileHandlerInterface $fileHandler): string
|
||||
private function checkAllowedMimeType(FileItemWithIdAndName $fileData, FileHandlerInterface $fileHandler): string
|
||||
{
|
||||
if (in_array($fileData->getType(), $this->configData->getFilesAllowedMime(), true)) {
|
||||
return $fileData->getType();
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace SP\Modules\Web\Controllers\Helpers\Account;
|
||||
use SP\Core\Acl\Acl;
|
||||
use SP\Core\Application;
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\DataModel\ItemPreset\AccountPermission;
|
||||
use SP\DataModel\ItemPreset\AccountPermission as AccountPermissionPreset;
|
||||
use SP\DataModel\ItemPreset\AccountPrivate;
|
||||
use SP\DataModel\ProfileData;
|
||||
use SP\Domain\Account\Adapters\AccountPermission;
|
||||
@@ -53,7 +53,7 @@ use SP\Domain\Crypt\Ports\MasterPassService;
|
||||
use SP\Domain\CustomField\Ports\CustomFieldDataService;
|
||||
use SP\Domain\Http\RequestInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetService;
|
||||
use SP\Domain\Tag\Ports\TagServiceInterface;
|
||||
use SP\Domain\User\Ports\UserGroupServiceInterface;
|
||||
use SP\Domain\User\Ports\UserServiceInterface;
|
||||
@@ -73,39 +73,39 @@ final class AccountHelper extends AccountHelperBase
|
||||
{
|
||||
use ItemTrait;
|
||||
|
||||
private AccountService $accountService;
|
||||
private AccountHistoryService $accountHistoryService;
|
||||
private PublicLinkService $publicLinkService;
|
||||
private ItemPresetServiceInterface $itemPresetService;
|
||||
private MasterPassService $masterPassService;
|
||||
private AccountAclService $accountAclService;
|
||||
private CategoryService $categoryService;
|
||||
private ClientService $clientService;
|
||||
private CustomFieldDataService $customFieldService;
|
||||
private ?AccountPermission $accountAcl = null;
|
||||
private ?int $accountId = null;
|
||||
private UserServiceInterface $userService;
|
||||
private UserGroupServiceInterface $userGroupService;
|
||||
private TagServiceInterface $tagService;
|
||||
private AccountService $accountService;
|
||||
private AccountHistoryService $accountHistoryService;
|
||||
private PublicLinkService $publicLinkService;
|
||||
private ItemPresetService $itemPresetService;
|
||||
private MasterPassService $masterPassService;
|
||||
private AccountAclService $accountAclService;
|
||||
private CategoryService $categoryService;
|
||||
private ClientService $clientService;
|
||||
private CustomFieldDataService $customFieldService;
|
||||
private ?AccountPermission $accountAcl = null;
|
||||
private ?int $accountId = null;
|
||||
private UserServiceInterface $userService;
|
||||
private UserGroupServiceInterface $userGroupService;
|
||||
private TagServiceInterface $tagService;
|
||||
|
||||
public function __construct(
|
||||
Application $application,
|
||||
TemplateInterface $template,
|
||||
RequestInterface $request,
|
||||
AclInterface $acl,
|
||||
AccountService $accountService,
|
||||
AccountHistoryService $accountHistoryService,
|
||||
PublicLinkService $publicLinkService,
|
||||
ItemPresetServiceInterface $itemPresetService,
|
||||
MasterPassService $masterPassService,
|
||||
AccountActionsHelper $accountActionsHelper,
|
||||
AccountAclService $accountAclService,
|
||||
CategoryService $categoryService,
|
||||
ClientService $clientService,
|
||||
CustomFieldDataService $customFieldService,
|
||||
UserServiceInterface $userService,
|
||||
UserGroupServiceInterface $userGroupService,
|
||||
TagServiceInterface $tagService
|
||||
Application $application,
|
||||
TemplateInterface $template,
|
||||
RequestInterface $request,
|
||||
AclInterface $acl,
|
||||
AccountService $accountService,
|
||||
AccountHistoryService $accountHistoryService,
|
||||
PublicLinkService $publicLinkService,
|
||||
ItemPresetService $itemPresetService,
|
||||
MasterPassService $masterPassService,
|
||||
AccountActionsHelper $accountActionsHelper,
|
||||
AccountAclService $accountAclService,
|
||||
CategoryService $categoryService,
|
||||
ClientService $clientService,
|
||||
CustomFieldDataService $customFieldService,
|
||||
UserServiceInterface $userService,
|
||||
UserGroupServiceInterface $userGroupService,
|
||||
TagServiceInterface $tagService
|
||||
) {
|
||||
parent::__construct($application, $template, $request, $acl, $accountActionsHelper, $masterPassService);
|
||||
|
||||
@@ -130,7 +130,7 @@ final class AccountHelper extends AccountHelperBase
|
||||
* Sets account's view variables
|
||||
*
|
||||
* @param AccountEnrichedDto $accountDetailsResponse
|
||||
* @param int $actionId
|
||||
* @param int $actionId
|
||||
*
|
||||
* @throws AccountPermissionException
|
||||
* @throws UnauthorizedPageException
|
||||
@@ -205,8 +205,12 @@ final class AccountHelper extends AccountHelperBase
|
||||
);
|
||||
$this->view->assign(
|
||||
'historyData',
|
||||
SelectItemAdapter::factory(AccountHistoryHelper::mapHistoryForDateSelect($this->accountHistoryService->getHistoryForAccount($this->accountId)))
|
||||
->getItemsFromArray()
|
||||
SelectItemAdapter::factory(
|
||||
AccountHistoryHelper::mapHistoryForDateSelect(
|
||||
$this->accountHistoryService->getHistoryForAccount($this->accountId)
|
||||
)
|
||||
)
|
||||
->getItemsFromArray()
|
||||
);
|
||||
$this->view->assign('isModified', strtotime($accountData->getDateEdit()) !== false);
|
||||
$this->view->assign('maxFileSize', round($this->configData->getFilesAllowedSize() / 1024, 1));
|
||||
@@ -218,7 +222,7 @@ final class AccountHelper extends AccountHelperBase
|
||||
$accountActionsDto->setPublicLinkId($publicLinkData->getId());
|
||||
$accountActionsDto->setPublicLinkCreatorId($publicLinkData->getUserId());
|
||||
|
||||
$baseUrl = ($this->configData->getApplicationUrl() ?: BootstrapBase::$WEBURI).BootstrapBase::$SUBURI;
|
||||
$baseUrl = ($this->configData->getApplicationUrl() ?: BootstrapBase::$WEBURI) . BootstrapBase::$SUBURI;
|
||||
|
||||
$this->view->assign(
|
||||
'publicLinkUrl',
|
||||
@@ -381,7 +385,7 @@ final class AccountHelper extends AccountHelperBase
|
||||
/**
|
||||
* Sets account's view for a blank form
|
||||
*
|
||||
* @param int $actionId
|
||||
* @param int $actionId
|
||||
*
|
||||
* @return void
|
||||
* @throws UnauthorizedPageException
|
||||
@@ -412,15 +416,17 @@ final class AccountHelper extends AccountHelperBase
|
||||
$accountPrivate = new AccountPrivate();
|
||||
|
||||
if ($itemPresetPrivate =
|
||||
$this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PRIVATE)) {
|
||||
$accountPrivate = $itemPresetPrivate->hydrate(AccountPrivate::class) ?: $accountPrivate;
|
||||
$this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PRIVATE)
|
||||
) {
|
||||
$accountPrivate = $itemPresetPrivate->hydrate(AccountPrivate::class) ?? $accountPrivate;
|
||||
}
|
||||
|
||||
$accountPermission = new AccountPermission();
|
||||
$accountPermission = new AccountPermissionPreset();
|
||||
|
||||
if ($itemPresetPermission =
|
||||
$this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PERMISSION)) {
|
||||
$accountPermission = $itemPresetPermission->hydrate(AccountPermission::class) ?: $accountPermission;
|
||||
$this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PERMISSION)
|
||||
) {
|
||||
$accountPermission = $itemPresetPermission->hydrate(AccountPermissionPreset::class) ?? $accountPermission;
|
||||
}
|
||||
|
||||
$selectUsers = SelectItemAdapter::factory($this->userService->getAll());
|
||||
|
||||
@@ -32,7 +32,7 @@ use SP\Core\Acl\Acl;
|
||||
use SP\Core\Application;
|
||||
use SP\Core\Crypt\Crypt;
|
||||
use SP\Core\Crypt\Session as CryptSession;
|
||||
use SP\Domain\Account\Adapters\AccountPassData;
|
||||
use SP\Domain\Account\Adapters\AccountPassItemWithIdAndName;
|
||||
use SP\Domain\Common\Services\ServiceException;
|
||||
use SP\Domain\Core\Acl\AclActionsInterface;
|
||||
use SP\Domain\Core\Acl\AclInterface;
|
||||
@@ -73,7 +73,7 @@ final class AccountPasswordHelper extends HelperBase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccountPassData $accountData
|
||||
* @param AccountPassItemWithIdAndName $accountData
|
||||
*
|
||||
* @param bool $useImage
|
||||
*
|
||||
@@ -88,8 +88,8 @@ final class AccountPasswordHelper extends HelperBase
|
||||
* @throws ServiceException
|
||||
*/
|
||||
public function getPasswordView(
|
||||
AccountPassData $accountData,
|
||||
bool $useImage
|
||||
AccountPassItemWithIdAndName $accountData,
|
||||
bool $useImage
|
||||
): array {
|
||||
$this->checkActionAccess();
|
||||
|
||||
@@ -136,7 +136,7 @@ final class AccountPasswordHelper extends HelperBase
|
||||
/**
|
||||
* Returns account's password
|
||||
*
|
||||
* @param AccountPassData $accountData
|
||||
* @param AccountPassItemWithIdAndName $accountData
|
||||
*
|
||||
* @return string
|
||||
* @throws BadFormatException
|
||||
@@ -147,7 +147,7 @@ final class AccountPasswordHelper extends HelperBase
|
||||
* @throws NoSuchItemException
|
||||
* @throws ServiceException
|
||||
*/
|
||||
public function getPasswordClear(AccountPassData $accountData): string
|
||||
public function getPasswordClear(AccountPassItemWithIdAndName $accountData): string
|
||||
{
|
||||
$this->checkActionAccess();
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -29,12 +29,12 @@ use SP\DataModel\ItemPreset\AccountPermission;
|
||||
use SP\DataModel\ItemPreset\AccountPrivate;
|
||||
use SP\DataModel\ItemPreset\Password;
|
||||
use SP\DataModel\ItemPreset\SessionTimeout;
|
||||
use SP\Domain\Account\Models\ItemPreset;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\InvalidArgumentException;
|
||||
use SP\Domain\Core\Exceptions\NoSuchPropertyException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\Http\RequestInterface;
|
||||
use SP\Domain\ItemPreset\Models\ItemPreset;
|
||||
use SP\Domain\User\Ports\UserGroupServiceInterface;
|
||||
use SP\Domain\User\Ports\UserProfileServiceInterface;
|
||||
use SP\Domain\User\Ports\UserServiceInterface;
|
||||
|
||||
@@ -37,7 +37,7 @@ use SP\Domain\Core\Acl\AclActionsInterface;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\CustomField\Ports\CustomFieldDefinitionService;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetService;
|
||||
use SP\Domain\Tag\Ports\TagServiceInterface;
|
||||
use SP\Html\DataGrid\DataGridTab;
|
||||
use SP\Modules\Web\Controllers\ControllerBase;
|
||||
@@ -68,9 +68,9 @@ final class IndexController extends ControllerBase
|
||||
private CustomFieldDefinitionService $customFieldDefService;
|
||||
private AccountFileService $accountFileService;
|
||||
private AccountService $accountService;
|
||||
private AccountHistoryService $accountHistoryService;
|
||||
private ItemPresetServiceInterface $itemPresetService;
|
||||
private CategoryGrid $categoryGrid;
|
||||
private AccountHistoryService $accountHistoryService;
|
||||
private ItemPresetService $itemPresetService;
|
||||
private CategoryGrid $categoryGrid;
|
||||
private TagGrid $tagGrid;
|
||||
private ClientGrid $clientGrid;
|
||||
private CustomFieldGrid $customFieldGrid;
|
||||
@@ -90,7 +90,7 @@ final class IndexController extends ControllerBase
|
||||
AccountFileService $accountFileService,
|
||||
AccountService $accountService,
|
||||
AccountHistoryService $accountHistoryService,
|
||||
ItemPresetServiceInterface $itemPresetService,
|
||||
ItemPresetService $itemPresetService,
|
||||
Helpers\Grid\CategoryGrid $categoryGrid,
|
||||
Helpers\Grid\TagGrid $tagGrid,
|
||||
Helpers\Grid\ClientGrid $clientGrid,
|
||||
@@ -98,7 +98,7 @@ final class IndexController extends ControllerBase
|
||||
Helpers\Grid\FileGrid $fileGrid,
|
||||
Helpers\Grid\AccountGrid $accountGrid,
|
||||
Helpers\Grid\AccountHistoryGrid $accountHistoryGrid,
|
||||
Helpers\Grid\ItemPresetGrid $itemPresetGrid
|
||||
Helpers\Grid\ItemPresetGrid $itemPresetGrid
|
||||
) {
|
||||
$this->tabsGridHelper = $tabsGridHelper;
|
||||
$this->categoryService = $categoryService;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers\ItemPreset;
|
||||
|
||||
|
||||
use SP\Core\Application;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetService;
|
||||
use SP\Modules\Web\Controllers\ControllerBase;
|
||||
use SP\Modules\Web\Forms\ItemsPresetForm;
|
||||
use SP\Mvc\Controller\WebControllerHelper;
|
||||
@@ -36,13 +36,13 @@ use SP\Mvc\Controller\WebControllerHelper;
|
||||
*/
|
||||
abstract class ItemPresetSaveBase extends ControllerBase
|
||||
{
|
||||
protected \SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface $itemPresetService;
|
||||
protected ItemsPresetForm $form;
|
||||
protected ItemPresetService $itemPresetService;
|
||||
protected ItemsPresetForm $form;
|
||||
|
||||
public function __construct(
|
||||
Application $application,
|
||||
WebControllerHelper $webControllerHelper,
|
||||
ItemPresetServiceInterface $itemPresetService
|
||||
ItemPresetService $itemPresetService
|
||||
) {
|
||||
parent::__construct($application, $webControllerHelper);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -27,14 +27,14 @@ namespace SP\Modules\Web\Controllers\ItemPreset;
|
||||
|
||||
use SP\Core\Acl\Acl;
|
||||
use SP\Core\Application;
|
||||
use SP\Domain\Account\Models\ItemPreset;
|
||||
use SP\Domain\Core\Acl\AclActionsInterface;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\InvalidArgumentException;
|
||||
use SP\Domain\Core\Exceptions\NoSuchPropertyException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\ItemPreset\Models\ItemPreset;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetService;
|
||||
use SP\Infrastructure\Common\Repositories\NoSuchItemException;
|
||||
use SP\Modules\Web\Controllers\ControllerBase;
|
||||
use SP\Modules\Web\Controllers\Helpers\ItemPresetHelper;
|
||||
@@ -45,14 +45,14 @@ use SP\Mvc\Controller\WebControllerHelper;
|
||||
*/
|
||||
abstract class ItemPresetViewBase extends ControllerBase
|
||||
{
|
||||
private ItemPresetServiceInterface $itemPresetService;
|
||||
private ItemPresetHelper $itemPresetHelper;
|
||||
private ItemPresetService $itemPresetService;
|
||||
private ItemPresetHelper $itemPresetHelper;
|
||||
|
||||
public function __construct(
|
||||
Application $application,
|
||||
Application $application,
|
||||
WebControllerHelper $webControllerHelper,
|
||||
ItemPresetServiceInterface $itemPresetService,
|
||||
ItemPresetHelper $itemPresetHelper
|
||||
ItemPresetService $itemPresetService,
|
||||
ItemPresetHelper $itemPresetHelper
|
||||
) {
|
||||
parent::__construct($application, $webControllerHelper);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -67,7 +67,7 @@ final class SaveCreateController extends ItemPresetSaveBase
|
||||
$this,
|
||||
EventMessage::factory()
|
||||
->addDescription(__u('Value created'))
|
||||
->addDetail(__u('Type'), $itemData->getItemPresetData()->getType())
|
||||
->addDetail(__u('Type'), $itemData->getItemPreset()->getType())
|
||||
->addDetail(__u('ID'), $id)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -71,7 +71,7 @@ final class SaveEditController extends ItemPresetSaveBase
|
||||
$this,
|
||||
EventMessage::factory()
|
||||
->addDescription(__u('Value updated'))
|
||||
->addDetail(__u('Type'), $itemData->getItemPresetData()->getType())
|
||||
->addDetail(__u('Type'), $itemData->getItemPreset()->getType())
|
||||
->addDetail(__u('ID'), $id)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -30,7 +30,7 @@ use SP\Core\Application;
|
||||
use SP\Domain\Core\Acl\AclActionsInterface;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetService;
|
||||
use SP\Html\DataGrid\DataGridInterface;
|
||||
use SP\Http\JsonMessage;
|
||||
use SP\Modules\Web\Controllers\ControllerBase;
|
||||
@@ -47,14 +47,14 @@ final class SearchController extends ControllerBase
|
||||
use ItemTrait;
|
||||
use JsonTrait;
|
||||
|
||||
private ItemPresetServiceInterface $itemPresetService;
|
||||
private ItemPresetGrid $itemPresetGrid;
|
||||
private ItemPresetService $itemPresetService;
|
||||
private ItemPresetGrid $itemPresetGrid;
|
||||
|
||||
public function __construct(
|
||||
Application $application,
|
||||
Application $application,
|
||||
WebControllerHelper $webControllerHelper,
|
||||
ItemPresetServiceInterface $itemPresetService,
|
||||
ItemPresetGrid $itemPresetGrid
|
||||
ItemPresetService $itemPresetService,
|
||||
ItemPresetGrid $itemPresetGrid
|
||||
) {
|
||||
parent::__construct($application, $webControllerHelper);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SP\Modules\Web\Controllers\Items;
|
||||
|
||||
use SP\Core\Application;
|
||||
use SP\DataModel\NotificationData;
|
||||
use SP\DataModel\NotificationItemWithIdAndName;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\Core\Exceptions\SPException;
|
||||
@@ -65,7 +65,7 @@ final class NotificationsController extends SimpleControllerBase
|
||||
{
|
||||
$notifications = array_map(
|
||||
static function ($notification) {
|
||||
/** @@var $notification NotificationData */
|
||||
/** @@var $notification NotificationItemWithIdAndName */
|
||||
return sprintf(
|
||||
'(%s) - %s',
|
||||
$notification->getComponent(),
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -27,7 +27,7 @@ namespace SP\Modules\Web\Controllers\Notification;
|
||||
|
||||
use SP\Core\Acl\Acl;
|
||||
use SP\Core\Application;
|
||||
use SP\DataModel\NotificationData;
|
||||
use SP\DataModel\NotificationItemWithIdAndName;
|
||||
use SP\Domain\Core\Acl\AclActionsInterface;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
@@ -75,7 +75,7 @@ abstract class NotificationViewBase extends ControllerBase
|
||||
|
||||
$notification = $notificationId
|
||||
? $this->notificationService->getById($notificationId)
|
||||
: new NotificationData();
|
||||
: new NotificationItemWithIdAndName();
|
||||
|
||||
$this->view->assign('notification', $notification);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace SP\Modules\Web\Controllers\UserProfile;
|
||||
use SP\Core\Acl\Acl;
|
||||
use SP\Core\Application;
|
||||
use SP\DataModel\ProfileData;
|
||||
use SP\DataModel\UserProfileData;
|
||||
use SP\DataModel\UserProfileItemWithIdAndName;
|
||||
use SP\Domain\Common\Services\ServiceException;
|
||||
use SP\Domain\Core\Acl\AclActionsInterface;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
@@ -82,7 +82,7 @@ abstract class UserProfileViewBase extends ControllerBase
|
||||
|
||||
$profile = $profileId
|
||||
? $this->userProfileService->getById($profileId)
|
||||
: new UserProfileData();
|
||||
: new UserProfileItemWithIdAndName();
|
||||
|
||||
$this->view->assign('profile', $profile);
|
||||
$this->view->assign('profileData', $profile->getProfile() ?: new ProfileData());
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -28,10 +28,10 @@ use SP\DataModel\ItemPreset\AccountPermission;
|
||||
use SP\DataModel\ItemPreset\AccountPrivate;
|
||||
use SP\DataModel\ItemPreset\Password;
|
||||
use SP\DataModel\ItemPreset\SessionTimeout;
|
||||
use SP\Domain\Account\Models\ItemPreset;
|
||||
use SP\Domain\Core\Acl\AclActionsInterface;
|
||||
use SP\Domain\Core\Exceptions\InvalidArgumentException;
|
||||
use SP\Domain\Core\Exceptions\ValidationException;
|
||||
use SP\Domain\ItemPreset\Models\ItemPreset;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetInterface;
|
||||
use SP\Domain\ItemPreset\Services\ItemPresetRequest;
|
||||
use SP\Mvc\Controller\Validators\Validator;
|
||||
@@ -196,7 +196,7 @@ final class ItemsPresetForm extends FormBase implements FormInterface
|
||||
*/
|
||||
protected function checkCommon(): void
|
||||
{
|
||||
$itemPresetData = $this->itemPresetRequest->getItemPresetData();
|
||||
$itemPresetData = $this->itemPresetRequest->getItemPreset();
|
||||
|
||||
if (!$itemPresetData->getUserId()
|
||||
&& !$itemPresetData->getUserGroupId()
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SP\Modules\Web\Forms;
|
||||
|
||||
use SP\Core\Messages\NotificationMessage;
|
||||
use SP\DataModel\NotificationData;
|
||||
use SP\DataModel\NotificationItemWithIdAndName;
|
||||
use SP\Domain\Core\Acl\AclActionsInterface;
|
||||
use SP\Domain\Core\Exceptions\ValidationException;
|
||||
|
||||
@@ -36,7 +36,7 @@ use SP\Domain\Core\Exceptions\ValidationException;
|
||||
*/
|
||||
final class NotificationForm extends FormBase implements FormInterface
|
||||
{
|
||||
protected ?NotificationData $notificationData = null;
|
||||
protected ?NotificationItemWithIdAndName $notificationData = null;
|
||||
|
||||
/**
|
||||
* Validar el formulario
|
||||
@@ -71,7 +71,7 @@ final class NotificationForm extends FormBase implements FormInterface
|
||||
*/
|
||||
protected function analyzeRequestData(): void
|
||||
{
|
||||
$this->notificationData = new NotificationData();
|
||||
$this->notificationData = new NotificationItemWithIdAndName();
|
||||
$this->notificationData->setId($this->itemId);
|
||||
$this->notificationData->setType($this->request->analyzeString('notification_type'));
|
||||
$this->notificationData->setComponent($this->request->analyzeString('notification_component'));
|
||||
@@ -113,7 +113,7 @@ final class NotificationForm extends FormBase implements FormInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function getItemData(): ?NotificationData
|
||||
public function getItemData(): ?NotificationItemWithIdAndName
|
||||
{
|
||||
return $this->notificationData;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SP\Modules\Web\Forms;
|
||||
|
||||
use SP\DataModel\ProfileData;
|
||||
use SP\DataModel\UserProfileData;
|
||||
use SP\DataModel\UserProfileItemWithIdAndName;
|
||||
use SP\Domain\Core\Acl\AclActionsInterface;
|
||||
use SP\Domain\Core\Exceptions\SPException;
|
||||
use SP\Domain\Core\Exceptions\ValidationException;
|
||||
@@ -37,7 +37,7 @@ use SP\Domain\Core\Exceptions\ValidationException;
|
||||
*/
|
||||
final class UserProfileForm extends FormBase implements FormInterface
|
||||
{
|
||||
protected ?UserProfileData $userProfileData = null;
|
||||
protected ?UserProfileItemWithIdAndName $userProfileData = null;
|
||||
|
||||
/**
|
||||
* Validar el formulario
|
||||
@@ -74,7 +74,7 @@ final class UserProfileForm extends FormBase implements FormInterface
|
||||
{
|
||||
$profileData = $this->getProfileDataFromRequest();
|
||||
|
||||
$this->userProfileData = new UserProfileData();
|
||||
$this->userProfileData = new UserProfileItemWithIdAndName();
|
||||
$this->userProfileData->setName($this->request->analyzeString('profile_name'));
|
||||
$this->userProfileData->setId($this->itemId);
|
||||
$this->userProfileData->setProfile($profileData);
|
||||
@@ -133,7 +133,7 @@ final class UserProfileForm extends FormBase implements FormInterface
|
||||
/**
|
||||
* @throws SPException
|
||||
*/
|
||||
public function getItemData(): UserProfileData
|
||||
public function getItemData(): UserProfileItemWithIdAndName
|
||||
{
|
||||
if (null === $this->userProfileData) {
|
||||
throw new SPException(__u('Profile data not set'));
|
||||
|
||||
@@ -53,7 +53,7 @@ use SP\Domain\Crypt\Ports\SecureSessionService;
|
||||
use SP\Domain\Crypt\Services\SecureSession;
|
||||
use SP\Domain\Http\RequestInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetInterface;
|
||||
use SP\Domain\ItemPreset\Services\ItemPresetService;
|
||||
use SP\Domain\ItemPreset\Services\ItemPreset;
|
||||
use SP\Domain\Upgrade\Services\UpgradeAppService;
|
||||
use SP\Domain\Upgrade\Services\UpgradeDatabaseService;
|
||||
use SP\Domain\Upgrade\Services\UpgradeUtil;
|
||||
@@ -140,8 +140,8 @@ final class Init extends HttpModuleBase
|
||||
private Language $language;
|
||||
private SecureSession $secureSessionService;
|
||||
private PluginManager $pluginManager;
|
||||
private ItemPresetService $itemPresetService;
|
||||
private DatabaseUtil $databaseUtil;
|
||||
private ItemPreset $itemPresetService;
|
||||
private DatabaseUtil $databaseUtil;
|
||||
private UserProfileService $userProfileService;
|
||||
private bool $isIndex = false;
|
||||
|
||||
@@ -154,7 +154,7 @@ final class Init extends HttpModuleBase
|
||||
LanguageInterface $language,
|
||||
SecureSessionService $secureSessionService,
|
||||
PluginManager $pluginManager,
|
||||
ItemPresetService $itemPresetService,
|
||||
ItemPreset $itemPresetService,
|
||||
DatabaseUtil $databaseUtil,
|
||||
UserProfileServiceInterface $userProfileService,
|
||||
private readonly UriContextInterface $uriContext
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -23,13 +23,13 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var \SP\Domain\Core\UI\ThemeIconsInterface $icons
|
||||
* @var ThemeIconsInterface $icons
|
||||
* @var callable $_getvar
|
||||
* @var ConfigDataInterface $configData
|
||||
* @var FileData $file
|
||||
* @var FileItemWithIdAndName $file
|
||||
*/
|
||||
|
||||
use SP\DataModel\FileData;
|
||||
use SP\DataModel\FileItemWithIdAndName;
|
||||
use SP\Domain\Config\Ports\ConfigDataInterface;
|
||||
use SP\Domain\Core\UI\ThemeIconsInterface;
|
||||
use SP\Html\Html;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -23,14 +23,14 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var FileData $fileData
|
||||
* @var FileItemWithIdAndName $fileData
|
||||
* @var ThemeIconsInterface $icons
|
||||
* @var ConfigDataInterface $configData
|
||||
* @var callable $_getvar
|
||||
* @var TemplateInterface $this
|
||||
*/
|
||||
|
||||
use SP\DataModel\FileData;
|
||||
use SP\DataModel\FileItemWithIdAndName;
|
||||
use SP\Domain\Config\Ports\ConfigDataInterface;
|
||||
use SP\Domain\Core\UI\ThemeIconsInterface;
|
||||
use SP\Mvc\View\TemplateInterface;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -30,9 +30,9 @@
|
||||
* @var TemplateInterface $this
|
||||
*/
|
||||
|
||||
use SP\Domain\Account\Models\ItemPreset;
|
||||
use SP\Domain\Config\Ports\ConfigDataInterface;
|
||||
use SP\Domain\Core\UI\ThemeIconsInterface;
|
||||
use SP\Domain\ItemPreset\Models\ItemPreset;
|
||||
use SP\Mvc\View\Components\SelectItem;
|
||||
use SP\Mvc\View\TemplateInterface;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
/**
|
||||
* @var ProfileData $profileData
|
||||
* @var UserProfileData $profile
|
||||
* @var UserProfileItemWithIdAndName $profile
|
||||
* @var ThemeIconsInterface $icons
|
||||
* @var ConfigDataInterface $configData
|
||||
* @var callable $_getvar
|
||||
@@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
use SP\DataModel\ProfileData;
|
||||
use SP\DataModel\UserProfileData;
|
||||
use SP\DataModel\UserProfileItemWithIdAndName;
|
||||
use SP\Domain\Config\Ports\ConfigDataInterface;
|
||||
use SP\Domain\Core\UI\ThemeIconsInterface;
|
||||
use SP\Mvc\View\TemplateInterface;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -23,14 +23,14 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var NotificationData $notification
|
||||
* @var NotificationItemWithIdAndName $notification
|
||||
* @var ThemeIconsInterface $icons
|
||||
* @var ConfigDataInterface $configData
|
||||
* @var callable $_getvar
|
||||
* @var TemplateInterface $this
|
||||
*/
|
||||
|
||||
use SP\DataModel\NotificationData;
|
||||
use SP\DataModel\NotificationItemWithIdAndName;
|
||||
use SP\Domain\Config\Ports\ConfigDataInterface;
|
||||
use SP\Domain\Core\UI\ThemeIconsInterface;
|
||||
use SP\Mvc\View\Components\SelectItem;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\Core\Acl;
|
||||
|
||||
use SP\DataModel\ActionData;
|
||||
use SP\DataModel\ActionItemWithIdAndName;
|
||||
use SP\Domain\Core\Acl\ActionNotFoundException;
|
||||
use SP\Domain\Core\Acl\ActionsInterface;
|
||||
use SP\Domain\Storage\Ports\FileCacheService;
|
||||
@@ -49,7 +49,7 @@ class Actions implements ActionsInterface
|
||||
*/
|
||||
public const CACHE_EXPIRE = 86400;
|
||||
/**
|
||||
* @var ActionData[]|null
|
||||
* @var ActionItemWithIdAndName[]|null
|
||||
*/
|
||||
protected ?array $actions = null;
|
||||
|
||||
@@ -113,14 +113,14 @@ class Actions implements ActionsInterface
|
||||
$this->actions = [];
|
||||
|
||||
foreach ($this->load() as $a) {
|
||||
$this->actions[$a['id']] = new ActionData($a['id'], $a['name'], $a['text'], $a['route']);
|
||||
$this->actions[$a['id']] = new ActionItemWithIdAndName($a['id'], $a['name'], $a['text'], $a['route']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads actions from DB
|
||||
*
|
||||
* @return ActionData[]
|
||||
* @return ActionItemWithIdAndName[]
|
||||
* @throws FileException
|
||||
*/
|
||||
protected function load(): array
|
||||
@@ -147,7 +147,7 @@ class Actions implements ActionsInterface
|
||||
*
|
||||
* @throws ActionNotFoundException
|
||||
*/
|
||||
public function getActionById(int $id): ActionData
|
||||
public function getActionById(int $id): ActionItemWithIdAndName
|
||||
{
|
||||
if (!isset($this->actions[$id])) {
|
||||
throw new ActionNotFoundException(__u('Action not found'));
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,14 +24,14 @@
|
||||
|
||||
namespace SP\DataModel;
|
||||
|
||||
use SP\Domain\Common\Adapters\DataModelInterface;
|
||||
use SP\Domain\Common\Models\ItemWithIdAndNameModel;
|
||||
|
||||
/**
|
||||
* Class ActionData
|
||||
*
|
||||
* @package SP\DataModel
|
||||
*/
|
||||
class ActionData implements DataModelInterface
|
||||
class ActionItemWithIdAndName implements ItemWithIdAndNameModel
|
||||
{
|
||||
public function __construct(
|
||||
private readonly int $id,
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -29,7 +29,7 @@ namespace SP\DataModel;
|
||||
*
|
||||
* @package SP\DataModel
|
||||
*/
|
||||
class FileExtData extends FileData
|
||||
class FileExtData extends FileItemWithIdAndName
|
||||
{
|
||||
protected ?string $clientName = null;
|
||||
protected ?string $accountName = null;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\DataModel;
|
||||
|
||||
use SP\Domain\Common\Adapters\DataModelInterface;
|
||||
use SP\Domain\Common\Models\ItemWithIdAndNameModel;
|
||||
use SP\Domain\Common\Models\Model;
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ use SP\Domain\Common\Models\Model;
|
||||
*
|
||||
* @package SP\DataModel
|
||||
*/
|
||||
class FileData extends Model implements DataModelInterface
|
||||
class FileItemWithIdAndName extends Model implements ItemWithIdAndNameModel
|
||||
{
|
||||
protected ?int $id = null;
|
||||
protected ?int $accountId = null;
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\DataModel;
|
||||
|
||||
use SP\Domain\Common\Adapters\DataModelInterface;
|
||||
use SP\Domain\Common\Models\ItemWithIdAndNameModel;
|
||||
use SP\Domain\Common\Models\Model;
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ use SP\Domain\Common\Models\Model;
|
||||
*
|
||||
* @package SP\DataModel
|
||||
*/
|
||||
class ItemData extends Model implements DataModelInterface
|
||||
class ItemItemWithIdAndName extends Model implements ItemWithIdAndNameModel
|
||||
{
|
||||
protected ?int $id = null;
|
||||
protected ?string $name = null;
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -31,14 +31,10 @@ namespace SP\DataModel\ItemPreset;
|
||||
*/
|
||||
final class AccountPrivate
|
||||
{
|
||||
/**
|
||||
* @param bool|null $privateUser
|
||||
* @param bool|null $privateGroup
|
||||
*/
|
||||
public function __construct(private ?bool $privateUser = false, private ?bool $privateGroup = false)
|
||||
{
|
||||
$this->privateUser = $privateUser;
|
||||
$this->privateGroup = $privateGroup;
|
||||
public function __construct(
|
||||
private readonly ?bool $privateUser = false,
|
||||
private readonly ?bool $privateGroup = false
|
||||
) {
|
||||
}
|
||||
|
||||
public function isPrivateUser(): bool
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\DataModel;
|
||||
|
||||
use SP\Domain\Common\Adapters\DataModelInterface;
|
||||
use SP\Domain\Common\Models\ItemWithIdAndNameModel;
|
||||
use SP\Domain\Core\Messages\MessageInterface;
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ use SP\Domain\Core\Messages\MessageInterface;
|
||||
*
|
||||
* @package SP\DataModel
|
||||
*/
|
||||
class NotificationData implements DataModelInterface
|
||||
class NotificationItemWithIdAndName implements ItemWithIdAndNameModel
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
@@ -24,14 +24,14 @@
|
||||
|
||||
namespace SP\DataModel;
|
||||
|
||||
use SP\Domain\Common\Adapters\DataModelInterface;
|
||||
use SP\Domain\Common\Models\ItemWithIdAndNameModel;
|
||||
|
||||
/**
|
||||
* Class UserBasicData
|
||||
*
|
||||
* @package SP\DataModel
|
||||
*/
|
||||
class User extends UserPassData implements DataModelInterface
|
||||
class User extends UserPassData implements ItemWithIdAndNameModel
|
||||
{
|
||||
protected ?string $login = null;
|
||||
protected ?string $ssoLogin = null;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\DataModel;
|
||||
|
||||
use SP\Domain\Common\Adapters\DataModelInterface;
|
||||
use SP\Domain\Common\Models\ItemWithIdAndNameModel;
|
||||
use SP\Domain\Common\Models\Model;
|
||||
|
||||
defined('APP_ROOT') || die();
|
||||
@@ -34,7 +34,7 @@ defined('APP_ROOT') || die();
|
||||
*
|
||||
* @package SP\DataModel
|
||||
*/
|
||||
class UserProfileData extends Model implements DataModelInterface
|
||||
class UserProfileItemWithIdAndName extends Model implements ItemWithIdAndNameModel
|
||||
{
|
||||
protected ?int $id = null;
|
||||
protected ?string $name = null;
|
||||
@@ -57,7 +57,7 @@ class UserProfileData extends Model implements DataModelInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \SP\DataModel\ProfileData|null
|
||||
* @return ProfileData|null
|
||||
*/
|
||||
public function getProfile(): ?ProfileData
|
||||
{
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,13 +24,13 @@
|
||||
|
||||
namespace SP\Domain\Account\Adapters;
|
||||
|
||||
use SP\Domain\Common\Adapters\DataModelInterface;
|
||||
use SP\Domain\Common\Models\ItemWithIdAndNameModel;
|
||||
use SP\Domain\Common\Models\Model;
|
||||
|
||||
/**
|
||||
* Class AccountPassData
|
||||
*/
|
||||
class AccountPassData extends Model implements DataModelInterface
|
||||
class AccountPassItemWithIdAndName extends Model implements ItemWithIdAndNameModel
|
||||
{
|
||||
protected ?int $id = null;
|
||||
protected ?string $name = null;
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SP\Domain\Account\Adapters;
|
||||
|
||||
use SP\Core\Bootstrap\BootstrapBase;
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Account\Models\AccountSearchView;
|
||||
use SP\Domain\Account\Services\PublicLink;
|
||||
use SP\Domain\Common\Dtos\ItemDataTrait;
|
||||
@@ -246,7 +246,7 @@ final class AccountSearchItem
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ItemData[]
|
||||
* @return ItemItemWithIdAndName[]
|
||||
*/
|
||||
public function getTags(): array
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\Domain\Account\Dtos;
|
||||
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Account\Models\AccountSearchView;
|
||||
use SP\Domain\Common\Dtos\ItemDataTrait;
|
||||
|
||||
@@ -110,7 +110,7 @@ final class AccountAclDto
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ItemData[]
|
||||
* @return ItemItemWithIdAndName[]
|
||||
*/
|
||||
public function getUsersId(): array
|
||||
{
|
||||
@@ -118,7 +118,7 @@ final class AccountAclDto
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ItemData[]
|
||||
* @return ItemItemWithIdAndName[]
|
||||
*/
|
||||
public function getUserGroupsId(): array
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\Domain\Account\Dtos;
|
||||
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Account\Models\AccountView;
|
||||
use SP\Domain\Common\Dtos\ItemDataTrait;
|
||||
|
||||
@@ -37,15 +37,15 @@ class AccountEnrichedDto
|
||||
|
||||
private readonly int $id;
|
||||
/**
|
||||
* @var ItemData[] Los usuarios secundarios de la cuenta.
|
||||
* @var ItemItemWithIdAndName[] Los usuarios secundarios de la cuenta.
|
||||
*/
|
||||
private array $users = [];
|
||||
/**
|
||||
* @var ItemData[] Los grupos secundarios de la cuenta.
|
||||
* @var ItemItemWithIdAndName[] Los grupos secundarios de la cuenta.
|
||||
*/
|
||||
private array $userGroups = [];
|
||||
/**
|
||||
* @var ItemData[] Las etiquetas de la cuenta.
|
||||
* @var ItemItemWithIdAndName[] Las etiquetas de la cuenta.
|
||||
*/
|
||||
private array $tags = [];
|
||||
|
||||
@@ -68,7 +68,7 @@ class AccountEnrichedDto
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ItemData[] $users
|
||||
* @param ItemItemWithIdAndName[] $users
|
||||
*
|
||||
* @return AccountEnrichedDto
|
||||
*/
|
||||
@@ -81,7 +81,7 @@ class AccountEnrichedDto
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ItemData[] $groups
|
||||
* @param ItemItemWithIdAndName[] $groups
|
||||
*
|
||||
* @return AccountEnrichedDto
|
||||
*/
|
||||
@@ -94,7 +94,7 @@ class AccountEnrichedDto
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ItemData[] $tags
|
||||
* @param ItemItemWithIdAndName[] $tags
|
||||
*
|
||||
* @return AccountEnrichedDto
|
||||
*/
|
||||
@@ -107,7 +107,7 @@ class AccountEnrichedDto
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ItemData[]
|
||||
* @return ItemItemWithIdAndName[]
|
||||
*/
|
||||
public function getUsers(): array
|
||||
{
|
||||
@@ -115,7 +115,7 @@ class AccountEnrichedDto
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ItemData[]
|
||||
* @return ItemItemWithIdAndName[]
|
||||
*/
|
||||
public function getUserGroups(): array
|
||||
{
|
||||
@@ -123,7 +123,7 @@ class AccountEnrichedDto
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ItemData[]
|
||||
* @return ItemItemWithIdAndName[]
|
||||
*/
|
||||
public function getTags(): array
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,13 +24,13 @@
|
||||
|
||||
namespace SP\Domain\Account\Models;
|
||||
|
||||
use SP\Domain\Common\Adapters\DataModelInterface;
|
||||
use SP\Domain\Common\Models\ItemWithIdAndNameModel;
|
||||
use SP\Domain\Common\Models\Model;
|
||||
|
||||
/**
|
||||
* Class PublicLink
|
||||
*/
|
||||
class PublicLink extends Model implements DataModelInterface
|
||||
class PublicLink extends Model implements ItemWithIdAndNameModel
|
||||
{
|
||||
protected ?int $id = null;
|
||||
protected ?int $itemId = null;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\Domain\Account\Ports;
|
||||
|
||||
use SP\DataModel\FileData;
|
||||
use SP\DataModel\FileItemWithIdAndName;
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\Domain\Common\Ports\Repository;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
@@ -41,13 +41,13 @@ interface AccountFileRepository extends Repository
|
||||
/**
|
||||
* Creates an item
|
||||
*
|
||||
* @param FileData $fileData
|
||||
* @param FileItemWithIdAndName $fileData
|
||||
*
|
||||
* @return int
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function create(FileData $fileData): int;
|
||||
public function create(FileItemWithIdAndName $fileData): int;
|
||||
|
||||
/**
|
||||
* Returns the item for given id
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
namespace SP\Domain\Account\Ports;
|
||||
|
||||
use SP\DataModel\FileData;
|
||||
use SP\DataModel\FileExtData;
|
||||
use SP\DataModel\FileItemWithIdAndName;
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\Domain\Common\Services\ServiceException;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
@@ -48,7 +48,7 @@ interface AccountFileService
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function create(FileData $itemData): int;
|
||||
public function create(FileItemWithIdAndName $itemData): int;
|
||||
|
||||
/**
|
||||
* Returns the item for given id
|
||||
@@ -92,7 +92,7 @@ interface AccountFileService
|
||||
/**
|
||||
* Returns the item for given id
|
||||
*
|
||||
* @return FileData[]
|
||||
* @return FileItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\Domain\Account\Ports;
|
||||
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
|
||||
@@ -36,7 +36,7 @@ use SP\Domain\Core\Exceptions\QueryException;
|
||||
interface AccountToTagService
|
||||
{
|
||||
/**
|
||||
* @return ItemData[]
|
||||
* @return ItemItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\Domain\Account\Ports;
|
||||
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\Core\Exceptions\SPException;
|
||||
@@ -37,7 +37,7 @@ interface AccountToUserGroupService
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return ItemData[]
|
||||
* @return ItemItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
* @throws SPException
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\Domain\Account\Ports;
|
||||
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\Core\Exceptions\SPException;
|
||||
@@ -37,7 +37,7 @@ interface AccountToUserService
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return ItemData[]
|
||||
* @return ItemItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
* @throws SPException
|
||||
|
||||
@@ -55,7 +55,7 @@ use SP\Domain\Core\Exceptions\NoSuchPropertyException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\Core\Exceptions\SPException;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetService;
|
||||
use SP\Domain\User\Services\UserLoginResponse;
|
||||
use SP\Infrastructure\Common\Repositories\NoSuchItemException;
|
||||
use SP\Infrastructure\Database\QueryResult;
|
||||
@@ -75,7 +75,7 @@ final class Account extends Service implements AccountService
|
||||
private readonly AccountToUserGroupRepository $accountToUserGroupRepository,
|
||||
private readonly AccountToUserRepository $accountToUserRepository,
|
||||
private readonly AccountToTagRepository $accountToTagRepository,
|
||||
private readonly ItemPresetServiceInterface $itemPresetService,
|
||||
private readonly ItemPresetService $itemPresetService,
|
||||
private readonly AccountHistoryService $accountHistoryService,
|
||||
private readonly AccountItemsService $accountItemsService,
|
||||
private readonly AccountPresetService $accountPresetService,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -25,8 +25,8 @@
|
||||
namespace SP\Domain\Account\Services;
|
||||
|
||||
use SP\Core\Application;
|
||||
use SP\DataModel\FileData;
|
||||
use SP\DataModel\FileExtData;
|
||||
use SP\DataModel\FileItemWithIdAndName;
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\Domain\Account\Ports\AccountFileRepository;
|
||||
use SP\Domain\Account\Ports\AccountFileService;
|
||||
@@ -62,14 +62,14 @@ final class AccountFile extends Service implements AccountFileService
|
||||
/**
|
||||
* Creates an item
|
||||
*
|
||||
* @param FileData $itemData
|
||||
* @param FileItemWithIdAndName $itemData
|
||||
*
|
||||
* @return int
|
||||
* @throws ConstraintException
|
||||
* @throws InvalidImageException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function create(FileData $itemData): int
|
||||
public function create(FileItemWithIdAndName $itemData): int
|
||||
{
|
||||
if (FileUtil::isImage($itemData)) {
|
||||
$itemData->setThumb($this->imageUtil->createThumbnail($itemData->getContent()));
|
||||
@@ -152,7 +152,7 @@ final class AccountFile extends Service implements AccountFileService
|
||||
* Returns the item for given id
|
||||
*
|
||||
* @param int $id
|
||||
* @return FileData[]
|
||||
* @return FileItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
* @throws SPException
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -38,7 +38,7 @@ use SP\Domain\Core\Exceptions\NoSuchPropertyException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\Core\Exceptions\ValidationException;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetService;
|
||||
use SP\Mvc\Controller\Validators\ValidatorInterface;
|
||||
|
||||
/**
|
||||
@@ -50,7 +50,7 @@ final class AccountPreset extends Service implements AccountPresetService
|
||||
{
|
||||
public function __construct(
|
||||
Application $application,
|
||||
private readonly ItemPresetServiceInterface $itemPresetService,
|
||||
private readonly ItemPresetService $itemPresetService,
|
||||
private readonly AccountToUserGroupRepository $accountToUserGroupRepository,
|
||||
private readonly AccountToUserRepository $accountToUserRepository,
|
||||
private readonly ConfigDataInterface $configData,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SP\Domain\Account\Services;
|
||||
|
||||
use SP\Core\Application;
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Account\Ports\AccountToTagRepository;
|
||||
use SP\Domain\Account\Ports\AccountToTagService;
|
||||
use SP\Domain\Common\Models\Simple;
|
||||
@@ -52,7 +52,7 @@ final class AccountToTag extends Service implements AccountToTagService
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return ItemData[]
|
||||
* @return ItemItemWithIdAndName[]
|
||||
*
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
@@ -64,6 +64,6 @@ final class AccountToTag extends Service implements AccountToTagService
|
||||
->getTagsByAccountId($id)
|
||||
->getDataAsArray(Simple::class);
|
||||
|
||||
return array_map(fn($tag) => ItemData::buildFromSimpleModel($tag), $tags);
|
||||
return array_map(fn($tag) => ItemItemWithIdAndName::buildFromSimpleModel($tag), $tags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SP\Domain\Account\Services;
|
||||
|
||||
use SP\Core\Application;
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Account\Ports\AccountToUserRepository;
|
||||
use SP\Domain\Account\Ports\AccountToUserService;
|
||||
use SP\Domain\Common\Services\Service;
|
||||
@@ -48,7 +48,7 @@ final class AccountToUser extends Service implements AccountToUserService
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return ItemData[]
|
||||
* @return ItemItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
* @throws SPException
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SP\Domain\Account\Services;
|
||||
|
||||
use SP\Core\Application;
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Account\Ports\AccountToUserGroupRepository;
|
||||
use SP\Domain\Account\Ports\AccountToUserGroupService;
|
||||
use SP\Domain\Common\Services\Service;
|
||||
@@ -48,13 +48,15 @@ final class AccountToUserGroup extends Service implements AccountToUserGroupServ
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return ItemData[]
|
||||
* @return ItemItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
* @throws SPException
|
||||
*/
|
||||
public function getUserGroupsByAccountId(int $id): array
|
||||
{
|
||||
return $this->accountToUserGroupRepository->getUserGroupsByAccountId($id)->getDataAsArray(ItemData::class);
|
||||
return $this->accountToUserGroupRepository->getUserGroupsByAccountId($id)->getDataAsArray(
|
||||
ItemItemWithIdAndName::class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,13 @@
|
||||
|
||||
namespace SP\Domain\Category\Models;
|
||||
|
||||
use SP\Domain\Common\Adapters\DataModelInterface;
|
||||
use SP\Domain\Common\Models\ItemWithIdAndNameModel;
|
||||
use SP\Domain\Common\Models\Model;
|
||||
|
||||
/**
|
||||
* Class Category
|
||||
*/
|
||||
class Category extends Model implements DataModelInterface
|
||||
class Category extends Model implements ItemWithIdAndNameModel
|
||||
{
|
||||
protected ?int $id = null;
|
||||
protected ?string $name = null;
|
||||
|
||||
@@ -24,13 +24,13 @@
|
||||
|
||||
namespace SP\Domain\Client\Models;
|
||||
|
||||
use SP\Domain\Common\Adapters\DataModelInterface;
|
||||
use SP\Domain\Common\Models\ItemWithIdAndNameModel;
|
||||
use SP\Domain\Common\Models\Model;
|
||||
|
||||
/**
|
||||
* Class Client
|
||||
*/
|
||||
class Client extends Model implements DataModelInterface
|
||||
class Client extends Model implements ItemWithIdAndNameModel
|
||||
{
|
||||
protected ?int $isGlobal = null;
|
||||
protected ?int $id = null;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\Domain\Client\Ports;
|
||||
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\Domain\Client\Models\Client;
|
||||
use SP\Domain\Common\Services\ServiceException;
|
||||
@@ -106,7 +106,7 @@ interface ClientService
|
||||
/**
|
||||
* Returns all clients visible for a given user
|
||||
*
|
||||
* @return ItemData[]
|
||||
* @return ItemItemWithIdAndName[]
|
||||
* @throws QueryException
|
||||
* @throws ConstraintException
|
||||
*/
|
||||
|
||||
@@ -60,7 +60,7 @@ final class Client extends Service implements ClientService
|
||||
/**
|
||||
* @param ItemSearchData $itemSearchData
|
||||
*
|
||||
* @return QueryResult
|
||||
* @return QueryResult<T>
|
||||
*/
|
||||
public function search(ItemSearchData $itemSearchData): QueryResult
|
||||
{
|
||||
@@ -169,7 +169,6 @@ final class Client extends Service implements ClientService
|
||||
* Get all items from the service's repository
|
||||
*
|
||||
* @return array<T>
|
||||
* @throws SPException
|
||||
*/
|
||||
public function getAll(): array
|
||||
{
|
||||
|
||||
51
lib/SP/Domain/Common/Attributes/Hydratable.php
Normal file
51
lib/SP/Domain/Common/Attributes/Hydratable.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/*
|
||||
* sysPass
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
* sysPass is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* sysPass is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Domain\Common\Attributes;
|
||||
|
||||
use Attribute;
|
||||
|
||||
/**
|
||||
* Class Hydratable
|
||||
*/
|
||||
#[Attribute(Attribute::TARGET_CLASS)]
|
||||
final class Hydratable
|
||||
{
|
||||
private readonly array $targetClass;
|
||||
|
||||
public function __construct(private readonly string $sourceProperty, array $targetClass)
|
||||
{
|
||||
$this->targetClass = array_filter($targetClass, static fn(string $class) => class_exists($class));
|
||||
}
|
||||
|
||||
public function getTargetClass(): array
|
||||
{
|
||||
return $this->targetClass;
|
||||
}
|
||||
|
||||
public function getSourceProperty(): string
|
||||
{
|
||||
return $this->sourceProperty;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\Domain\Common\Dtos;
|
||||
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
|
||||
/**
|
||||
* Trait ItemDataTrait
|
||||
@@ -32,12 +32,12 @@ use SP\DataModel\ItemData;
|
||||
trait ItemDataTrait
|
||||
{
|
||||
/**
|
||||
* @param ItemData[] $items
|
||||
* @param ItemItemWithIdAndName[] $items
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function buildFromItemData(array $items): array
|
||||
{
|
||||
return array_filter($items, static fn($value) => $value instanceof ItemData);
|
||||
return array_filter($items, static fn($value) => $value instanceof ItemItemWithIdAndName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -22,19 +22,28 @@
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Domain\Common\Adapters;
|
||||
namespace SP\Domain\Common\Models;
|
||||
|
||||
/**
|
||||
* Interface HydratableInterface
|
||||
* Interface HydratableModel
|
||||
*/
|
||||
interface HydratableInterface
|
||||
interface HydratableModel
|
||||
{
|
||||
/**
|
||||
* Deserialize the hydratable property and returns the object.
|
||||
*
|
||||
* @template T
|
||||
* @param class-string<T>|null $class
|
||||
* @param string $property
|
||||
* @param class-string<T> $class
|
||||
*
|
||||
* @return T|null
|
||||
*/
|
||||
public function hydrate(?string $class = null, string $property = 'data'): mixed;
|
||||
public function hydrate(string $class): ?object;
|
||||
|
||||
/**
|
||||
* Serialize the object in the hydratable property
|
||||
* @param object $object
|
||||
*
|
||||
* @return static A new instance of the model with the serialized property
|
||||
*/
|
||||
public function dehydrate(object $object): static;
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -22,14 +22,12 @@
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Domain\Common\Adapters;
|
||||
namespace SP\Domain\Common\Models;
|
||||
|
||||
/**
|
||||
* Interface DataModelInterface
|
||||
*
|
||||
* @package SP\DataModel
|
||||
* Interface ItemWithIdAndNameModel
|
||||
*/
|
||||
interface DataModelInterface
|
||||
interface ItemWithIdAndNameModel
|
||||
{
|
||||
public function getId(): ?int;
|
||||
|
||||
@@ -61,7 +61,7 @@ abstract class Model implements JsonSerializable, ArrayAccess
|
||||
{
|
||||
return array_filter(
|
||||
get_object_vars($this),
|
||||
fn($key) => $key !== 'properties' && $key !== 'fields',
|
||||
static fn(string $key) => $key !== 'properties' && $key !== 'fields',
|
||||
ARRAY_FILTER_USE_KEY
|
||||
);
|
||||
}
|
||||
@@ -118,9 +118,7 @@ abstract class Model implements JsonSerializable, ArrayAccess
|
||||
*/
|
||||
final public static function getCols(?array $exclude = null): array
|
||||
{
|
||||
$self = new static();
|
||||
|
||||
return array_keys($self->toArray(null, $exclude));
|
||||
return array_keys((new static())->toArray(null, $exclude));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,37 +24,52 @@
|
||||
|
||||
namespace SP\Domain\Common\Models;
|
||||
|
||||
use SP\Domain\Core\Exceptions\NoSuchPropertyException;
|
||||
use SP\Util\Util;
|
||||
use ReflectionClass;
|
||||
use SP\Domain\Common\Attributes\Hydratable;
|
||||
|
||||
/**
|
||||
* Trait Datamodel
|
||||
* Trait SerializedModel
|
||||
*/
|
||||
trait SerializedModel
|
||||
{
|
||||
/**
|
||||
* @template THydrate
|
||||
* @param class-string<THydrate>|null $class
|
||||
* @param string $property
|
||||
* @param class-string<THydrate> $class
|
||||
*
|
||||
* @return THydrate|null
|
||||
* @throws NoSuchPropertyException
|
||||
*/
|
||||
public function hydrate(?string $class = null, string $property = 'data'): mixed
|
||||
public function hydrate(string $class): ?object
|
||||
{
|
||||
if (property_exists($this, $property)) {
|
||||
if ($this->{$property} === null) {
|
||||
return null;
|
||||
}
|
||||
$reflectionClass = new ReflectionClass($this);
|
||||
|
||||
if ($class !== null) {
|
||||
return Util::unserialize($class, $this->{$property});
|
||||
}
|
||||
foreach ($reflectionClass->getAttributes(Hydratable::class) as $attribute) {
|
||||
/** @var Hydratable $instance */
|
||||
$instance = $attribute->newInstance();
|
||||
|
||||
/** @noinspection UnserializeExploitsInspection */
|
||||
return unserialize($this->{$property});
|
||||
if (in_array($class, $instance->getTargetClass()) && $this->{$instance->getSourceProperty()} !== null) {
|
||||
return unserialize($this->{$instance->getSourceProperty()}, ['allowed_classes' => [$class]]) ?: null;
|
||||
}
|
||||
}
|
||||
|
||||
throw new NoSuchPropertyException($property);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function dehydrate(object $object): static
|
||||
{
|
||||
$reflectionClass = new ReflectionClass($this);
|
||||
|
||||
foreach ($reflectionClass->getAttributes(Hydratable::class) as $attribute) {
|
||||
/** @var Hydratable $instance */
|
||||
$instance = $attribute->newInstance();
|
||||
|
||||
if (in_array($object::class, $instance->getTargetClass())) {
|
||||
return $this->mutate([$instance->getSourceProperty() => serialize($object)]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\Domain\Core\Acl;
|
||||
|
||||
use SP\DataModel\ActionData;
|
||||
use SP\DataModel\ActionItemWithIdAndName;
|
||||
use SP\Infrastructure\File\FileException;
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ interface ActionsInterface
|
||||
*
|
||||
* @throws ActionNotFoundException
|
||||
*/
|
||||
public function getActionById(int $id): ActionData;
|
||||
public function getActionById(int $id): ActionItemWithIdAndName;
|
||||
|
||||
/**
|
||||
* @throws FileException
|
||||
|
||||
@@ -24,13 +24,13 @@
|
||||
|
||||
namespace SP\Domain\CustomField\Models;
|
||||
|
||||
use SP\Domain\Common\Adapters\DataModelInterface;
|
||||
use SP\Domain\Common\Models\ItemWithIdAndNameModel;
|
||||
use SP\Domain\Common\Models\Model;
|
||||
|
||||
/**
|
||||
* Class CustomFieldType
|
||||
*/
|
||||
class CustomFieldType extends Model implements DataModelInterface
|
||||
class CustomFieldType extends Model implements ItemWithIdAndNameModel
|
||||
{
|
||||
protected ?int $id = null;
|
||||
protected ?string $name = null;
|
||||
|
||||
@@ -29,7 +29,7 @@ use Exception;
|
||||
use SP\Core\Crypt\Hash;
|
||||
use SP\DataModel\ProfileData;
|
||||
use SP\DataModel\User;
|
||||
use SP\DataModel\UserProfileData;
|
||||
use SP\DataModel\UserProfileItemWithIdAndName;
|
||||
use SP\Domain\Config\Models\Config;
|
||||
use SP\Domain\Config\Ports\ConfigDataInterface;
|
||||
use SP\Domain\Config\Ports\ConfigFileService;
|
||||
@@ -344,7 +344,7 @@ final class InstallerService implements InstallerServiceInterface
|
||||
]
|
||||
);
|
||||
|
||||
$userProfile = new UserProfileData(['name' => 'Admin', 'profile' => new ProfileData()]);
|
||||
$userProfile = new UserProfileItemWithIdAndName(['name' => 'Admin', 'profile' => new ProfileData()]);
|
||||
|
||||
$userData = new User([
|
||||
'userGroupId' => $this->userGroupService->create($userGroup),
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -22,16 +22,27 @@
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Domain\Account\Models;
|
||||
namespace SP\Domain\ItemPreset\Models;
|
||||
|
||||
use SP\Domain\Common\Adapters\HydratableInterface;
|
||||
use SP\DataModel\ItemPreset\AccountPermission;
|
||||
use SP\DataModel\ItemPreset\AccountPrivate;
|
||||
use SP\DataModel\ItemPreset\Password;
|
||||
use SP\DataModel\ItemPreset\SessionTimeout;
|
||||
use SP\Domain\Common\Attributes\Hydratable;
|
||||
use SP\Domain\Common\Models\HydratableModel;
|
||||
use SP\Domain\Common\Models\Model;
|
||||
use SP\Domain\Common\Models\SerializedModel;
|
||||
|
||||
/**
|
||||
* Class ItemPreset
|
||||
*/
|
||||
class ItemPreset extends Model implements HydratableInterface
|
||||
#[Hydratable('data', [
|
||||
Password::class,
|
||||
AccountPrivate::class,
|
||||
AccountPermission::class,
|
||||
SessionTimeout::class
|
||||
])]
|
||||
class ItemPreset extends Model implements HydratableModel
|
||||
{
|
||||
use SerializedModel;
|
||||
|
||||
@@ -69,16 +80,18 @@ class ItemPreset extends Model implements HydratableInterface
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function getHash(): string
|
||||
{
|
||||
return sha1(
|
||||
$this->type . (int)$this->userId . (int)$this->userGroupId . (int)$this->userProfileId .
|
||||
(int)$this->priority
|
||||
);
|
||||
}
|
||||
|
||||
public function getType(): ?string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getUserId(): ?int
|
||||
{
|
||||
return $this->userId;
|
||||
}
|
||||
}
|
||||
@@ -24,27 +24,91 @@
|
||||
|
||||
namespace SP\Domain\ItemPreset\Ports;
|
||||
|
||||
use Exception;
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\Domain\Common\Ports\Repository;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\ItemPreset\Models\ItemPreset as ItemPresetModel;
|
||||
use SP\Infrastructure\Database\QueryResult;
|
||||
|
||||
/**
|
||||
* Class AccountDefaultPermissionRepository
|
||||
* Class ItemPresetRepository
|
||||
*
|
||||
* @package SP\Infrastructure\Account\Repositories
|
||||
* @template T of ItemPresetModel
|
||||
*/
|
||||
interface ItemPresetRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* Creates an item
|
||||
*
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function create(ItemPresetModel $itemPreset): QueryResult;
|
||||
|
||||
/**
|
||||
* Updates an item
|
||||
*
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function update(ItemPresetModel $itemPreset): int;
|
||||
|
||||
/**
|
||||
* Deletes an item
|
||||
*
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function delete(int $id): QueryResult;
|
||||
|
||||
/**
|
||||
* Returns the item for given id
|
||||
*
|
||||
* @param string $type
|
||||
* @param int $userId
|
||||
* @param int $userGroupId
|
||||
* @param int $userProfileId
|
||||
* @param int $itemPresetId
|
||||
*
|
||||
* @return QueryResult
|
||||
*/
|
||||
public function getById(int $itemPresetId): QueryResult;
|
||||
|
||||
/**
|
||||
* Returns all the items
|
||||
*
|
||||
* @return QueryResult<T>
|
||||
*/
|
||||
public function getAll(): QueryResult;
|
||||
|
||||
/**
|
||||
* Deletes all the items for given ids
|
||||
*
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function deleteByIdBatch(array $itemPresetIds): QueryResult;
|
||||
|
||||
/**
|
||||
* Searches for items by a given filter
|
||||
*
|
||||
* @param ItemSearchData $itemSearchData
|
||||
*
|
||||
* @return QueryResult<T>
|
||||
*
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function search(ItemSearchData $itemSearchData): QueryResult;
|
||||
|
||||
/**
|
||||
* Returns the item for given id
|
||||
*
|
||||
* @param string $type
|
||||
* @param int $userId
|
||||
* @param int $userGroupId
|
||||
* @param int $userProfileId
|
||||
*
|
||||
* @return QueryResult<T>
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -25,33 +25,31 @@
|
||||
namespace SP\Domain\ItemPreset\Ports;
|
||||
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\Domain\Account\Models\ItemPreset;
|
||||
use SP\Domain\Common\Services\ServiceException;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\ItemPreset\Services\ItemPresetRequest;
|
||||
use SP\Domain\ItemPreset\Services\ItemPresetService;
|
||||
use SP\Domain\ItemPreset\Models\ItemPreset as ItemPresetModel;
|
||||
use SP\Infrastructure\Common\Repositories\NoSuchItemException;
|
||||
use SP\Infrastructure\Database\QueryResult;
|
||||
|
||||
/**
|
||||
* Class ItemPresetService
|
||||
*
|
||||
* @package SP\Domain\Account\Services
|
||||
* @template T of ItemPresetModel
|
||||
*/
|
||||
interface ItemPresetServiceInterface
|
||||
interface ItemPresetService
|
||||
{
|
||||
/**
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function create(ItemPresetRequest $itemPresetRequest): int;
|
||||
public function create(ItemPresetModel $itemPreset): int;
|
||||
|
||||
/**
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function update(ItemPresetRequest $itemPresetRequest): int;
|
||||
public function update(ItemPresetModel $itemPreset): int;
|
||||
|
||||
/**
|
||||
* Deletes an item
|
||||
@@ -69,12 +67,12 @@ interface ItemPresetServiceInterface
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function getById(int $id): ItemPreset;
|
||||
public function getById(int $id): ItemPresetModel;
|
||||
|
||||
/**
|
||||
* Returns all the items
|
||||
*
|
||||
* @return ItemPreset[]
|
||||
* @return array<T>
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
@@ -83,6 +81,7 @@ interface ItemPresetServiceInterface
|
||||
/**
|
||||
* Searches for items by a given filter
|
||||
*
|
||||
* @return QueryResult<T>
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
@@ -92,16 +91,16 @@ interface ItemPresetServiceInterface
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function getForCurrentUser(string $type): ?ItemPreset;
|
||||
public function getForCurrentUser(string $type): ?ItemPresetModel;
|
||||
|
||||
/**
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function getForUser(string $type, int $userId, int $userGroupId, int $userProfileId): ?ItemPreset;
|
||||
public function getForUser(string $type, int $userId, int $userGroupId, int $userProfileId): ?ItemPresetModel;
|
||||
|
||||
/**
|
||||
* @param int[] $ids
|
||||
* @param int[] $ids
|
||||
*
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
@@ -26,50 +26,47 @@ namespace SP\Domain\ItemPreset\Services;
|
||||
|
||||
use SP\Core\Application;
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\Domain\Account\Models\ItemPreset;
|
||||
use SP\Domain\Common\Services\Service;
|
||||
use SP\Domain\Common\Services\ServiceException;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\Core\Exceptions\SPException;
|
||||
use SP\Domain\ItemPreset\Models\ItemPreset as ItemPresetModel;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetRepository;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetService;
|
||||
use SP\Infrastructure\Common\Repositories\NoSuchItemException;
|
||||
use SP\Infrastructure\Database\QueryResult;
|
||||
use SP\Infrastructure\ItemPreset\Repositories\ItemPresetBaseRepository;
|
||||
|
||||
use function SP\__u;
|
||||
|
||||
/**
|
||||
* Class ItemPresetService
|
||||
* Class ItemPreset
|
||||
*
|
||||
* @package SP\Domain\Account\Services
|
||||
* @template T of ItemPresetModel
|
||||
*/
|
||||
final class ItemPresetService extends Service implements ItemPresetServiceInterface
|
||||
final class ItemPreset extends Service implements ItemPresetService
|
||||
{
|
||||
private ItemPresetBaseRepository $itemPresetRepository;
|
||||
|
||||
public function __construct(Application $application, ItemPresetRepository $itemPresetRepository)
|
||||
public function __construct(Application $application, private readonly ItemPresetRepository $itemPresetRepository)
|
||||
{
|
||||
parent::__construct($application);
|
||||
|
||||
$this->itemPresetRepository = $itemPresetRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function create(ItemPresetRequest $itemPresetRequest): int
|
||||
public function create(ItemPresetModel $itemPreset): int
|
||||
{
|
||||
return $this->itemPresetRepository->create($itemPresetRequest->prepareToPersist());
|
||||
return $this->itemPresetRepository->create($itemPreset)->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function update(ItemPresetRequest $itemPresetRequest): int
|
||||
public function update(ItemPresetModel $itemPreset): int
|
||||
{
|
||||
return $this->itemPresetRepository->update($itemPresetRequest->prepareToPersist());
|
||||
return $this->itemPresetRepository->update($itemPreset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,8 +78,8 @@ final class ItemPresetService extends Service implements ItemPresetServiceInterf
|
||||
*/
|
||||
public function delete(int $id): ItemPresetService
|
||||
{
|
||||
if ($this->itemPresetRepository->delete($id) === 0) {
|
||||
throw new NoSuchItemException(__u('Value not found'));
|
||||
if ($this->itemPresetRepository->delete($id)->getAffectedNumRows() === 0) {
|
||||
throw NoSuchItemException::error(__u('Value not found'));
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -91,36 +88,35 @@ final class ItemPresetService extends Service implements ItemPresetServiceInterf
|
||||
/**
|
||||
* Returns the item for given id
|
||||
*
|
||||
* @param int $id
|
||||
* @return ItemPresetModel
|
||||
* @throws NoSuchItemException
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function getById(int $id): ItemPreset
|
||||
public function getById(int $id): ItemPresetModel
|
||||
{
|
||||
$result = $this->itemPresetRepository->getById($id);
|
||||
|
||||
if ($result->getNumRows() === 0) {
|
||||
throw new NoSuchItemException(__u('Value not found'));
|
||||
throw NoSuchItemException::error(__u('Value not found'));
|
||||
}
|
||||
|
||||
return $result->getData();
|
||||
return $result->getData(ItemPresetModel::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the items
|
||||
*
|
||||
* @return ItemPreset[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
* @return array<T>
|
||||
*/
|
||||
public function getAll(): array
|
||||
{
|
||||
return $this->itemPresetRepository->getAll()->getDataAsArray();
|
||||
return $this->itemPresetRepository->getAll()->getDataAsArray(ItemPresetModel::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for items by a given filter
|
||||
*
|
||||
* @return QueryResult<T>
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
@@ -133,7 +129,7 @@ final class ItemPresetService extends Service implements ItemPresetServiceInterf
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function getForCurrentUser(string $type): ?ItemPreset
|
||||
public function getForCurrentUser(string $type): ?ItemPresetModel
|
||||
{
|
||||
$userData = $this->context->getUserData();
|
||||
|
||||
@@ -149,28 +145,18 @@ final class ItemPresetService extends Service implements ItemPresetServiceInterf
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function getForUser(
|
||||
string $type,
|
||||
int $userId,
|
||||
int $userGroupId,
|
||||
int $userProfileId
|
||||
): ?ItemPreset {
|
||||
$result = $this->itemPresetRepository->getByFilter(
|
||||
public function getForUser(string $type, int $userId, int $userGroupId, int $userProfileId): ?ItemPresetModel
|
||||
{
|
||||
return $this->itemPresetRepository->getByFilter(
|
||||
$type,
|
||||
$userId,
|
||||
$userGroupId,
|
||||
$userProfileId
|
||||
);
|
||||
|
||||
if ($result->getNumRows() === 1) {
|
||||
return $result->getData();
|
||||
}
|
||||
|
||||
return null;
|
||||
)->getData(ItemPresetModel::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[] $ids
|
||||
* @param int[] $ids
|
||||
*
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
@@ -178,13 +164,10 @@ final class ItemPresetService extends Service implements ItemPresetServiceInterf
|
||||
*/
|
||||
public function deleteByIdBatch(array $ids): int
|
||||
{
|
||||
$count = $this->itemPresetRepository->deleteByIdBatch($ids);
|
||||
$count = $this->itemPresetRepository->deleteByIdBatch($ids)->getAffectedNumRows();
|
||||
|
||||
if ($count !== count($ids)) {
|
||||
throw new ServiceException(
|
||||
__u('Error while deleting the values'),
|
||||
SPException::WARNING
|
||||
);
|
||||
throw ServiceException::warning(__u('Error while deleting the values'));
|
||||
}
|
||||
|
||||
return $count;
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* sysPass
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
* sysPass is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* sysPass is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Domain\ItemPreset\Services;
|
||||
|
||||
use SP\Domain\Account\Models\ItemPreset;
|
||||
|
||||
/**
|
||||
* Class ItemPresetRequest
|
||||
*
|
||||
* @package SP\Domain\ItemPreset\Services
|
||||
*/
|
||||
final class ItemPresetRequest
|
||||
{
|
||||
private ItemPreset $itemPresetData;
|
||||
private $data;
|
||||
|
||||
/**
|
||||
* ItemPresetRequest constructor.
|
||||
*/
|
||||
public function __construct(ItemPreset $itemPresetData, $data)
|
||||
{
|
||||
$this->itemPresetData = $itemPresetData;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function getItemPresetData(): ItemPreset
|
||||
{
|
||||
return $this->itemPresetData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function prepareToPersist(): ItemPreset
|
||||
{
|
||||
$this->itemPresetData->setData(serialize($this->data));
|
||||
|
||||
return $this->itemPresetData;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SP\Domain\Notification\Ports;
|
||||
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\DataModel\NotificationData;
|
||||
use SP\DataModel\NotificationItemWithIdAndName;
|
||||
use SP\Domain\Common\Services\ServiceException;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
@@ -45,7 +45,7 @@ interface NotificationServiceInterface
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function create(NotificationData $itemData): int;
|
||||
public function create(NotificationItemWithIdAndName $itemData): int;
|
||||
|
||||
/**
|
||||
* Updates an item
|
||||
@@ -53,14 +53,14 @@ interface NotificationServiceInterface
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function update(NotificationData $itemData): int;
|
||||
public function update(NotificationItemWithIdAndName $itemData): int;
|
||||
|
||||
/**
|
||||
* Devolver los elementos con los ids especificados
|
||||
*
|
||||
* @param int[] $ids
|
||||
*
|
||||
* @return NotificationData[]
|
||||
* @return NotificationItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
@@ -113,12 +113,12 @@ interface NotificationServiceInterface
|
||||
* @throws QueryException
|
||||
* @throws NoSuchItemException
|
||||
*/
|
||||
public function getById(int $id): NotificationData;
|
||||
public function getById(int $id): NotificationItemWithIdAndName;
|
||||
|
||||
/**
|
||||
* Returns all the items
|
||||
*
|
||||
* @return NotificationData[]
|
||||
* @return NotificationItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
@@ -136,21 +136,21 @@ interface NotificationServiceInterface
|
||||
/**
|
||||
* Devolver las notificaciones de un usuario para una fecha y componente determinados
|
||||
*
|
||||
* @return NotificationData[]
|
||||
* @return NotificationItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function getForUserIdByDate(string $component, int $id): array;
|
||||
|
||||
/**
|
||||
* @return NotificationData[]
|
||||
* @return NotificationItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function getAllForUserId(int $id): array;
|
||||
|
||||
/**
|
||||
* @return NotificationData[]
|
||||
* @return NotificationItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace SP\Domain\Notification\Services;
|
||||
|
||||
use SP\Core\Application;
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\DataModel\NotificationData;
|
||||
use SP\DataModel\NotificationItemWithIdAndName;
|
||||
use SP\Domain\Common\Services\Service;
|
||||
use SP\Domain\Common\Services\ServiceException;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
@@ -60,7 +60,7 @@ final class NotificationService extends Service implements NotificationServiceIn
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function create(NotificationData $itemData): int
|
||||
public function create(NotificationItemWithIdAndName $itemData): int
|
||||
{
|
||||
return $this->notificationRepository->create($itemData)->getLastId();
|
||||
}
|
||||
@@ -71,7 +71,7 @@ final class NotificationService extends Service implements NotificationServiceIn
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function update(NotificationData $itemData): int
|
||||
public function update(NotificationItemWithIdAndName $itemData): int
|
||||
{
|
||||
return $this->notificationRepository->update($itemData);
|
||||
}
|
||||
@@ -81,7 +81,7 @@ final class NotificationService extends Service implements NotificationServiceIn
|
||||
*
|
||||
* @param int[] $ids
|
||||
*
|
||||
* @return NotificationData[]
|
||||
* @return NotificationItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
@@ -175,7 +175,7 @@ final class NotificationService extends Service implements NotificationServiceIn
|
||||
* @throws QueryException
|
||||
* @throws NoSuchItemException
|
||||
*/
|
||||
public function getById(int $id): NotificationData
|
||||
public function getById(int $id): NotificationItemWithIdAndName
|
||||
{
|
||||
$result = $this->notificationRepository->getById($id);
|
||||
|
||||
@@ -189,7 +189,7 @@ final class NotificationService extends Service implements NotificationServiceIn
|
||||
/**
|
||||
* Returns all the items
|
||||
*
|
||||
* @return NotificationData[]
|
||||
* @return NotificationItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
@@ -215,7 +215,7 @@ final class NotificationService extends Service implements NotificationServiceIn
|
||||
/**
|
||||
* Devolver las notificaciones de un usuario para una fecha y componente determinados
|
||||
*
|
||||
* @return NotificationData[]
|
||||
* @return NotificationItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
@@ -225,7 +225,7 @@ final class NotificationService extends Service implements NotificationServiceIn
|
||||
}
|
||||
|
||||
/**
|
||||
* @return NotificationData[]
|
||||
* @return NotificationItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
@@ -235,7 +235,7 @@ final class NotificationService extends Service implements NotificationServiceIn
|
||||
}
|
||||
|
||||
/**
|
||||
* @return NotificationData[]
|
||||
* @return NotificationItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\Domain\Plugin\Ports;
|
||||
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
@@ -169,7 +169,7 @@ interface PluginManagerInterface
|
||||
/**
|
||||
* Devolver los plugins activados
|
||||
*
|
||||
* @return ItemData[]
|
||||
* @return ItemItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SP\Domain\Plugin\Services;
|
||||
|
||||
use SP\Core\Application;
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\Domain\Common\Services\Service;
|
||||
use SP\Domain\Common\Services\ServiceException;
|
||||
@@ -264,7 +264,7 @@ final class PluginManager extends Service implements PluginManagerInterface
|
||||
/**
|
||||
* Devolver los plugins activados
|
||||
*
|
||||
* @return ItemData[]
|
||||
* @return ItemItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
* @throws SPException
|
||||
|
||||
@@ -24,13 +24,13 @@
|
||||
|
||||
namespace SP\Domain\Tag\Models;
|
||||
|
||||
use SP\Domain\Common\Adapters\DataModelInterface;
|
||||
use SP\Domain\Common\Models\ItemWithIdAndNameModel;
|
||||
use SP\Domain\Common\Models\Model;
|
||||
|
||||
/**
|
||||
* Class Tag
|
||||
*/
|
||||
class Tag extends Model implements DataModelInterface
|
||||
class Tag extends Model implements ItemWithIdAndNameModel
|
||||
{
|
||||
protected ?int $id = null;
|
||||
protected ?string $name = null;
|
||||
|
||||
@@ -24,13 +24,13 @@
|
||||
|
||||
namespace SP\Domain\User\Models;
|
||||
|
||||
use SP\Domain\Common\Adapters\DataModelInterface;
|
||||
use SP\Domain\Common\Models\ItemWithIdAndNameModel;
|
||||
use SP\Domain\Common\Models\Model;
|
||||
|
||||
/**
|
||||
* Class GroupData
|
||||
*/
|
||||
class UserGroup extends Model implements DataModelInterface
|
||||
class UserGroup extends Model implements ItemWithIdAndNameModel
|
||||
{
|
||||
protected ?int $id = null;
|
||||
protected ?string $name = null;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SP\Domain\User\Ports;
|
||||
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\DataModel\UserProfileData;
|
||||
use SP\DataModel\UserProfileItemWithIdAndName;
|
||||
use SP\Domain\Common\Services\ServiceException;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
@@ -45,7 +45,7 @@ interface UserProfileServiceInterface
|
||||
* @throws QueryException
|
||||
* @throws NoSuchItemException
|
||||
*/
|
||||
public function getById(int $id): UserProfileData;
|
||||
public function getById(int $id): UserProfileItemWithIdAndName;
|
||||
|
||||
/**
|
||||
* @throws ConstraintException
|
||||
@@ -74,7 +74,7 @@ interface UserProfileServiceInterface
|
||||
* @throws QueryException
|
||||
* @throws DuplicatedItemException
|
||||
*/
|
||||
public function create(UserProfileData $itemData): int;
|
||||
public function create(UserProfileItemWithIdAndName $itemData): int;
|
||||
|
||||
/**
|
||||
* @throws ConstraintException
|
||||
@@ -82,7 +82,7 @@ interface UserProfileServiceInterface
|
||||
* @throws DuplicatedItemException
|
||||
* @throws ServiceException
|
||||
*/
|
||||
public function update(UserProfileData $itemData): void;
|
||||
public function update(UserProfileItemWithIdAndName $itemData): void;
|
||||
|
||||
/**
|
||||
* @throws ConstraintException
|
||||
@@ -93,7 +93,7 @@ interface UserProfileServiceInterface
|
||||
/**
|
||||
* Get all items from the service's repository
|
||||
*
|
||||
* @return UserProfileData[]
|
||||
* @return UserProfileItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace SP\Domain\User\Services;
|
||||
use SP\Core\Application;
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\DataModel\ProfileData;
|
||||
use SP\DataModel\UserProfileData;
|
||||
use SP\DataModel\UserProfileItemWithIdAndName;
|
||||
use SP\Domain\Common\Services\Service;
|
||||
use SP\Domain\Common\Services\ServiceException;
|
||||
use SP\Domain\Common\Services\ServiceItemTrait;
|
||||
@@ -67,7 +67,7 @@ final class UserProfileService extends Service implements UserProfileServiceInte
|
||||
* @throws QueryException
|
||||
* @throws NoSuchItemException
|
||||
*/
|
||||
public function getById(int $id): UserProfileData
|
||||
public function getById(int $id): UserProfileItemWithIdAndName
|
||||
{
|
||||
$result = $this->userProfileRepository->getById($id);
|
||||
|
||||
@@ -130,7 +130,7 @@ final class UserProfileService extends Service implements UserProfileServiceInte
|
||||
* @throws QueryException
|
||||
* @throws DuplicatedItemException
|
||||
*/
|
||||
public function create(UserProfileData $itemData): int
|
||||
public function create(UserProfileItemWithIdAndName $itemData): int
|
||||
{
|
||||
return $this->userProfileRepository->create($itemData);
|
||||
}
|
||||
@@ -141,7 +141,7 @@ final class UserProfileService extends Service implements UserProfileServiceInte
|
||||
* @throws DuplicatedItemException
|
||||
* @throws ServiceException
|
||||
*/
|
||||
public function update(UserProfileData $itemData): void
|
||||
public function update(UserProfileItemWithIdAndName $itemData): void
|
||||
{
|
||||
$update = $this->userProfileRepository->update($itemData);
|
||||
|
||||
@@ -163,7 +163,7 @@ final class UserProfileService extends Service implements UserProfileServiceInte
|
||||
/**
|
||||
* Get all items from the service's repository
|
||||
*
|
||||
* @return UserProfileData[]
|
||||
* @return UserProfileItemWithIdAndName[]
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\Infrastructure\Account\Repositories;
|
||||
|
||||
use SP\DataModel\FileData;
|
||||
use SP\DataModel\FileItemWithIdAndName;
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\Domain\Account\Ports\AccountFileRepository;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
@@ -48,13 +48,13 @@ final class AccountFile extends BaseRepository implements AccountFileRepository
|
||||
/**
|
||||
* Creates an item
|
||||
*
|
||||
* @param FileData $fileData
|
||||
* @param FileItemWithIdAndName $fileData
|
||||
*
|
||||
* @return int
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function create(FileData $fileData): int
|
||||
public function create(FileItemWithIdAndName $fileData): int
|
||||
{
|
||||
$query = $this->queryFactory
|
||||
->newInsert()
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\Infrastructure\Account\Repositories;
|
||||
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Account\Ports\AccountToUserRepository;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
@@ -150,6 +150,6 @@ final class AccountToUser extends BaseRepository implements AccountToUserReposit
|
||||
->bindValues(['accountId' => $id])
|
||||
->orderBy(['User.name ASC']);
|
||||
|
||||
return $this->db->doSelect(QueryData::build($query)->setMapClassName(ItemData::class));
|
||||
return $this->db->doSelect(QueryData::build($query)->setMapClassName(ItemItemWithIdAndName::class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SP\Infrastructure\Account\Repositories;
|
||||
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Account\Ports\AccountToUserGroupRepository;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
@@ -67,7 +67,7 @@ final class AccountToUserGroup extends BaseRepository implements AccountToUserGr
|
||||
->bindValues(['accountId' => $id])
|
||||
->orderBy(['UserGroup.name ASC']);
|
||||
|
||||
return $this->db->doSelect(QueryData::build($query)->setMapClassName(ItemData::class));
|
||||
return $this->db->doSelect(QueryData::build($query)->setMapClassName(ItemItemWithIdAndName::class));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,7 +92,7 @@ final class AccountToUserGroup extends BaseRepository implements AccountToUserGr
|
||||
->bindValues(['userGroupId' => $id])
|
||||
->orderBy(['UserGroup.name ASC']);
|
||||
|
||||
return $this->db->doSelect(QueryData::build($query)->setMapClassName(ItemData::class));
|
||||
return $this->db->doSelect(QueryData::build($query)->setMapClassName(ItemItemWithIdAndName::class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
273
lib/SP/Infrastructure/ItemPreset/Repositories/ItemPreset.php
Normal file
273
lib/SP/Infrastructure/ItemPreset/Repositories/ItemPreset.php
Normal file
@@ -0,0 +1,273 @@
|
||||
<?php
|
||||
/*
|
||||
* sysPass
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
* sysPass is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* sysPass is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Infrastructure\ItemPreset\Repositories;
|
||||
|
||||
use Exception;
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\ItemPreset\Models\ItemPreset as ItemPresetModel;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetRepository;
|
||||
use SP\Infrastructure\Common\Repositories\BaseRepository;
|
||||
use SP\Infrastructure\Common\Repositories\RepositoryItemTrait;
|
||||
use SP\Infrastructure\Database\QueryData;
|
||||
use SP\Infrastructure\Database\QueryResult;
|
||||
|
||||
use function SP\__u;
|
||||
|
||||
/**
|
||||
* Class ItemPresetBaseRepository
|
||||
*
|
||||
* @template T of ItemPresetModel
|
||||
*/
|
||||
class ItemPreset extends BaseRepository implements ItemPresetRepository
|
||||
{
|
||||
use RepositoryItemTrait;
|
||||
|
||||
public const TABLE = 'ItemPreset';
|
||||
|
||||
/**
|
||||
* Creates an item
|
||||
*
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function create(ItemPresetModel $itemPreset): QueryResult
|
||||
{
|
||||
$query = $this->queryFactory
|
||||
->newInsert()
|
||||
->into(self::TABLE)
|
||||
->cols($itemPreset->toArray(null, ['id']));
|
||||
|
||||
$queryData = QueryData::build($query)->setOnErrorMessage(__u('Error while creating the permission'));
|
||||
|
||||
return $this->db->doQuery($queryData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an item
|
||||
*
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function update(ItemPresetModel $itemPreset): int
|
||||
{
|
||||
$query = $this->queryFactory
|
||||
->newUpdate()
|
||||
->table(self::TABLE)
|
||||
->cols($itemPreset->toArray(null, ['id']))
|
||||
->where('id = :id')
|
||||
->limit(1)
|
||||
->bindValues(
|
||||
[
|
||||
'id' => $itemPreset->getId()
|
||||
]
|
||||
);
|
||||
|
||||
$queryData = QueryData::build($query)->setOnErrorMessage(__u('Error while updating the permission'));
|
||||
|
||||
return $this->db->doQuery($queryData)->getAffectedNumRows();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an item
|
||||
*
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function delete(int $id): QueryResult
|
||||
{
|
||||
$query = $this->queryFactory
|
||||
->newDelete()
|
||||
->from(self::TABLE)
|
||||
->where('id = :id')
|
||||
->bindValues(['id' => $id]);
|
||||
|
||||
$queryData = QueryData::build($query)->setOnErrorMessage(__u('Error while deleting the permission'));
|
||||
|
||||
return $this->db->doQuery($queryData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the item for given id
|
||||
*
|
||||
* @param int $itemPresetId
|
||||
*
|
||||
* @return QueryResult
|
||||
*/
|
||||
public function getById(int $itemPresetId): QueryResult
|
||||
{
|
||||
$query = $this->queryFactory
|
||||
->newSelect()
|
||||
->from(self::TABLE)
|
||||
->cols(ItemPresetModel::getCols())
|
||||
->where('id = :id')
|
||||
->bindValues(['id' => $itemPresetId])
|
||||
->limit(1);
|
||||
|
||||
$queryData = QueryData::buildWithMapper($query, ItemPresetModel::class);
|
||||
|
||||
return $this->db->doSelect($queryData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the item for given id
|
||||
*
|
||||
* @param string $type
|
||||
* @param int $userId
|
||||
* @param int $userGroupId
|
||||
* @param int $userProfileId
|
||||
*
|
||||
* @return QueryResult<T>
|
||||
*/
|
||||
public function getByFilter(string $type, int $userId, int $userGroupId, int $userProfileId): QueryResult
|
||||
{
|
||||
$query = $this->queryFactory
|
||||
->newSelect()
|
||||
->from(self::TABLE)
|
||||
->cols(ItemPresetModel::getCols())
|
||||
->cols(
|
||||
[
|
||||
'IF(userId IS NOT NULL, priority + 3,
|
||||
IF(userGroupId IS NOT NULL, priority + 2,
|
||||
IF(userProfileId IS NOT NULL, priority + 1, 0)))' => 'score'
|
||||
]
|
||||
)
|
||||
->where('type = :type')
|
||||
->where(
|
||||
'(userId = :userId OR userGroupId = :userGroupId OR userProfileId = :userProfileId
|
||||
OR userGroupId IN (SELECT UserToUserGroup.userGroupId
|
||||
FROM UserToUserGroup
|
||||
WHERE UserToUserGroup.userId = :userId))'
|
||||
)
|
||||
->bindValues([
|
||||
'type' => $type,
|
||||
'userId' => $userId,
|
||||
'userGroupId' => $userGroupId,
|
||||
'userProfileId' => $userProfileId
|
||||
])
|
||||
->orderBy(['score DESC'])
|
||||
->limit(1);
|
||||
|
||||
$queryData = QueryData::buildWithMapper($query, ItemPresetModel::class);
|
||||
|
||||
return $this->db->doSelect($queryData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the items
|
||||
*
|
||||
* @return QueryResult<T>
|
||||
*/
|
||||
public function getAll(): QueryResult
|
||||
{
|
||||
$query = $this->queryFactory
|
||||
->newSelect()
|
||||
->from(self::TABLE)
|
||||
->cols(ItemPresetModel::getCols());
|
||||
|
||||
return $this->db->doSelect(QueryData::buildWithMapper($query, ItemPresetModel::class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all the items for given ids
|
||||
*
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function deleteByIdBatch(array $itemPresetIds): QueryResult
|
||||
{
|
||||
if (count($itemPresetIds) === 0) {
|
||||
return new QueryResult();
|
||||
}
|
||||
|
||||
$query = $this->queryFactory
|
||||
->newDelete()
|
||||
->from(self::TABLE)
|
||||
->where('id IN (:ids)', ['ids' => $itemPresetIds]);
|
||||
|
||||
$queryData = QueryData::build($query)->setOnErrorMessage(__u('Error while removing the permissions'));
|
||||
|
||||
return $this->db->doQuery($queryData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Searches for items by a given filter
|
||||
*
|
||||
* @param ItemSearchData $itemSearchData
|
||||
*
|
||||
* @return QueryResult<T>
|
||||
*
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function search(ItemSearchData $itemSearchData): QueryResult
|
||||
{
|
||||
$query = $this->queryFactory
|
||||
->newSelect()
|
||||
->from(self::TABLE)
|
||||
->cols(ItemPresetModel::getColsWithPreffix('ItemPreset'))
|
||||
->cols([
|
||||
'IF(userId IS NOT NULL, priority + 3,
|
||||
IF(userGroupId IS NOT NULL, priority + 2,
|
||||
IF(userProfileId IS NOT NULL, priority + 1, 0)))' => 'score',
|
||||
'User.name' => 'userName',
|
||||
'UserProfile.name' => 'userProfileName',
|
||||
'UserGroup.name' => 'userGroupName'
|
||||
])
|
||||
->leftJoin('User', 'ItemPreset.userId = User.id ')
|
||||
->leftJoin('UserProfile', 'ItemPreset.userProfileId = UserProfile.id')
|
||||
->leftJoin('UserGroup', 'ItemPreset.userGroupId = UserGroup.id')
|
||||
->orderBy(['ItemPreset.type', 'score DESC'])
|
||||
->limit($itemSearchData->getLimitCount())
|
||||
->offset($itemSearchData->getLimitStart());
|
||||
|
||||
if (!empty($itemSearchData->getSeachString())) {
|
||||
$query->where(
|
||||
'ItemPreset.type LIKE :type
|
||||
OR User.name LIKE :userName
|
||||
OR UserProfile.name LIKE :userProfileName
|
||||
OR UserGroup.name LIKE :userGroupName'
|
||||
);
|
||||
|
||||
$search = '%' . $itemSearchData->getSeachString() . '%';
|
||||
|
||||
$query->bindValues(
|
||||
[
|
||||
'type' => $search,
|
||||
'userName' => $search,
|
||||
'userProfileName' => $search,
|
||||
'userGroupName' => $search
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$queryData = QueryData::build($query)->setMapClassName(ItemPresetModel::class);
|
||||
|
||||
return $this->db->doSelect($queryData, true);
|
||||
}
|
||||
}
|
||||
@@ -1,369 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* sysPass
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
* sysPass is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* sysPass is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Infrastructure\ItemPreset\Repositories;
|
||||
|
||||
use RuntimeException;
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\Domain\Account\Models\ItemPreset;
|
||||
use SP\Domain\Common\Ports\Repository;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetRepository;
|
||||
use SP\Infrastructure\Common\Repositories\BaseRepository;
|
||||
use SP\Infrastructure\Common\Repositories\RepositoryItemTrait;
|
||||
use SP\Infrastructure\Database\QueryData;
|
||||
use SP\Infrastructure\Database\QueryResult;
|
||||
|
||||
/**
|
||||
* Class AccountDefaultPermissionRepository
|
||||
*
|
||||
* @package SP\Infrastructure\Account\Repositories
|
||||
*/
|
||||
class ItemPresetBaseRepository extends BaseRepository implements Repository, ItemPresetRepository
|
||||
{
|
||||
use RepositoryItemTrait;
|
||||
|
||||
/**
|
||||
* Creates an item
|
||||
*
|
||||
* @param ItemPreset $itemData
|
||||
*
|
||||
* @return int
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function create($itemData): int
|
||||
{
|
||||
$queryData = new QueryData();
|
||||
$queryData->setQuery(
|
||||
'INSERT INTO ItemPreset
|
||||
SET type = ?,
|
||||
userId = ?,
|
||||
userGroupId = ?,
|
||||
userProfileId = ?,
|
||||
`fixed` = ?,
|
||||
priority = ?,
|
||||
`data` = ?,
|
||||
`hash` = ?'
|
||||
);
|
||||
$queryData->setParams([
|
||||
$itemData->getType(),
|
||||
$itemData->getUserId(),
|
||||
$itemData->getUserGroupId(),
|
||||
$itemData->getUserProfileId(),
|
||||
$itemData->getFixed(),
|
||||
$itemData->getPriority(),
|
||||
$itemData->getData(),
|
||||
$itemData->getHash(),
|
||||
]);
|
||||
$queryData->setOnErrorMessage(__u('Error while creating the permission'));
|
||||
|
||||
return $this->db->doQuery($queryData)->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an item
|
||||
*
|
||||
* @param ItemPreset $itemData
|
||||
*
|
||||
* @return int
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function update($itemData): int
|
||||
{
|
||||
$queryData = new QueryData();
|
||||
$queryData->setQuery(
|
||||
'UPDATE ItemPreset
|
||||
SET type = ?,
|
||||
userId = ?,
|
||||
userGroupId = ?,
|
||||
userProfileId = ?,
|
||||
`fixed` = ?,
|
||||
priority = ?,
|
||||
`data` = ?,
|
||||
`hash` = ?
|
||||
WHERE id = ? LIMIT 1'
|
||||
);
|
||||
$queryData->setParams([
|
||||
$itemData->getType(),
|
||||
$itemData->getUserId(),
|
||||
$itemData->getUserGroupId(),
|
||||
$itemData->getUserProfileId(),
|
||||
$itemData->getFixed(),
|
||||
$itemData->getPriority(),
|
||||
$itemData->getData(),
|
||||
$itemData->getHash(),
|
||||
$itemData->getId(),
|
||||
]);
|
||||
$queryData->setOnErrorMessage(__u('Error while updating the permission'));
|
||||
|
||||
return $this->db->doQuery($queryData)->getAffectedNumRows();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an item
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return int
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function delete(int $id): int
|
||||
{
|
||||
$queryData = new QueryData();
|
||||
$queryData->setQuery('DELETE FROM ItemPreset WHERE id = ? LIMIT 1');
|
||||
$queryData->setParams([$id]);
|
||||
$queryData->setOnErrorMessage(__u('Error while removing the permission'));
|
||||
|
||||
return $this->db->doQuery($queryData)->getAffectedNumRows();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the item for given id
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return QueryResult
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function getById(int $id): QueryResult
|
||||
{
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(ItemPreset::class);
|
||||
$queryData->setQuery(
|
||||
'SELECT id, type, userId, userGroupId, userProfileId, `fixed`, priority, `data`
|
||||
FROM ItemPreset WHERE id = ? LIMIT 1'
|
||||
);
|
||||
$queryData->setParams([$id]);
|
||||
|
||||
return $this->db->doSelect($queryData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the item for given id
|
||||
*
|
||||
* @param string $type
|
||||
* @param int $userId
|
||||
* @param int $userGroupId
|
||||
* @param int $userProfileId
|
||||
*
|
||||
* @return QueryResult
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function getByFilter(
|
||||
string $type,
|
||||
int $userId,
|
||||
int $userGroupId,
|
||||
int $userProfileId
|
||||
): QueryResult {
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(ItemPreset::class);
|
||||
$queryData->setQuery(
|
||||
'SELECT id, type, userId, userGroupId, userProfileId, `fixed`, priority, `data`,
|
||||
IF(userId IS NOT NULL, priority + 3,
|
||||
IF(userGroupId IS NOT NULL, priority + 2,
|
||||
IF(userProfileId IS NOT NULL, priority + 1, 0))) AS score
|
||||
FROM ItemPreset
|
||||
WHERE type = ?
|
||||
AND (userId = ?
|
||||
OR userGroupId = ?
|
||||
OR userProfileId = ?
|
||||
OR userGroupId IN (SELECT UserToUserGroup.userGroupId
|
||||
FROM UserToUserGroup
|
||||
WHERE UserToUserGroup.userId = ?)
|
||||
)
|
||||
ORDER BY score DESC
|
||||
LIMIT 1'
|
||||
);
|
||||
|
||||
$queryData->setParams([$type, $userId, $userGroupId, $userProfileId, $userId]);
|
||||
|
||||
return $this->db->doSelect($queryData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the items
|
||||
*
|
||||
* @return QueryResult
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function getAll(): QueryResult
|
||||
{
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(ItemPreset::class);
|
||||
$queryData->setQuery(
|
||||
'SELECT id, type, userId, userGroupId, userProfileId, `fixed`, priority, `data`
|
||||
FROM ItemPreset'
|
||||
);
|
||||
|
||||
return $this->db->doSelect($queryData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the items for given ids
|
||||
*
|
||||
* @param array $ids
|
||||
*
|
||||
* @return QueryResult
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function getByIdBatch(array $ids): QueryResult
|
||||
{
|
||||
if (count($ids) === 0) {
|
||||
return new QueryResult();
|
||||
}
|
||||
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(ItemPreset::class);
|
||||
$queryData->setQuery(
|
||||
'SELECT type, userId, userGroupId, userProfileId, `fixed`, priority, `data`
|
||||
FROM ItemPreset WHERE id IN ('.$this->buildParamsFromArray($ids).')'
|
||||
);
|
||||
$queryData->setParams($ids);
|
||||
|
||||
return $this->db->doSelect($queryData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all the items for given ids
|
||||
*
|
||||
* @param int[] $ids
|
||||
*
|
||||
* @return int
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function deleteByIdBatch(array $ids): int
|
||||
{
|
||||
if (count($ids) === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$queryData = new QueryData();
|
||||
$queryData->setQuery('DELETE FROM ItemPreset WHERE id IN ('.$this->buildParamsFromArray($ids).')');
|
||||
$queryData->setParams($ids);
|
||||
$queryData->setOnErrorMessage(__u('Error while removing the permissions'));
|
||||
|
||||
return $this->db->doQuery($queryData)->getAffectedNumRows();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the item is in use or not
|
||||
*
|
||||
* @param $id int
|
||||
*/
|
||||
public function checkInUse(int $id): bool
|
||||
{
|
||||
throw new RuntimeException('Not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the item is duplicated on updating
|
||||
*
|
||||
* @param mixed $itemData
|
||||
*/
|
||||
public function checkDuplicatedOnUpdate($itemData): bool
|
||||
{
|
||||
throw new RuntimeException('Not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the item is duplicated on adding
|
||||
*
|
||||
* @param mixed $itemData
|
||||
*/
|
||||
public function checkDuplicatedOnAdd($itemData): bool
|
||||
{
|
||||
throw new RuntimeException('Not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for items by a given filter
|
||||
*
|
||||
* @param ItemSearchData $itemSearchData
|
||||
*
|
||||
* @return QueryResult
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function search(ItemSearchData $itemSearchData): QueryResult
|
||||
{
|
||||
$queryData = new QueryData();
|
||||
$queryData->setSelect(
|
||||
'ItemPreset.id,
|
||||
ItemPreset.type,
|
||||
ItemPreset.userId,
|
||||
ItemPreset.userGroupId,
|
||||
ItemPreset.userProfileId,
|
||||
ItemPreset.`fixed`,
|
||||
ItemPreset.priority,
|
||||
ItemPreset.data,
|
||||
User.name AS userName,
|
||||
UserProfile.name AS userProfileName,
|
||||
UserGroup.name AS userGroupName,
|
||||
IF(ItemPreset.userId IS NOT NULL, ItemPreset.priority + 3,
|
||||
IF(ItemPreset.userGroupId IS NOT NULL, ItemPreset.priority + 2,
|
||||
IF(ItemPreset.userProfileId IS NOT NULL, ItemPreset.priority + 1, 0))) AS score'
|
||||
);
|
||||
$queryData->setFrom(
|
||||
'
|
||||
ItemPreset
|
||||
LEFT JOIN User ON ItemPreset.userId = User.id
|
||||
LEFT JOIN UserProfile ON ItemPreset.userProfileId = UserProfile.id
|
||||
LEFT JOIN UserGroup ON ItemPreset.userGroupId = UserGroup.id'
|
||||
);
|
||||
$queryData->setOrder(
|
||||
'ItemPreset.type, score DESC'
|
||||
);
|
||||
|
||||
if (!empty($itemSearchData->getSeachString())) {
|
||||
$queryData->setWhere(
|
||||
'ItemPreset.type LIKE ?
|
||||
OR User.name LIKE ?
|
||||
OR UserProfile.name LIKE ?
|
||||
OR UserGroup.name LIKE ?'
|
||||
);
|
||||
|
||||
$search = '%'.$itemSearchData->getSeachString().'%';
|
||||
$queryData->addParam($search);
|
||||
$queryData->addParam($search);
|
||||
$queryData->addParam($search);
|
||||
$queryData->addParam($search);
|
||||
}
|
||||
|
||||
$queryData->setLimit(
|
||||
'?,?',
|
||||
[$itemSearchData->getLimitStart(), $itemSearchData->getLimitCount()]
|
||||
);
|
||||
|
||||
return $this->db->doSelect($queryData, true);
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ namespace SP\Infrastructure\Notification\Repositories;
|
||||
|
||||
use RuntimeException;
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\DataModel\NotificationData;
|
||||
use SP\DataModel\NotificationItemWithIdAndName;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\Notification\Ports\NotificationRepository;
|
||||
@@ -48,7 +48,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific
|
||||
/**
|
||||
* Creates an item
|
||||
*
|
||||
* @param NotificationData $itemData
|
||||
* @param NotificationItemWithIdAndName $itemData
|
||||
*
|
||||
* @return QueryResult
|
||||
* @throws ConstraintException
|
||||
@@ -85,7 +85,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific
|
||||
/**
|
||||
* Updates an item
|
||||
*
|
||||
* @param NotificationData $itemData
|
||||
* @param NotificationItemWithIdAndName $itemData
|
||||
*
|
||||
* @return int
|
||||
* @throws ConstraintException
|
||||
@@ -208,7 +208,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific
|
||||
WHERE id = ? LIMIT 1';
|
||||
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(NotificationData::class);
|
||||
$queryData->setMapClassName(NotificationItemWithIdAndName::class);
|
||||
$queryData->setQuery($query);
|
||||
$queryData->addParam($id);
|
||||
$queryData->setOnErrorMessage(__u('Error while retrieving notification'));
|
||||
@@ -239,7 +239,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific
|
||||
ORDER BY id';
|
||||
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(NotificationData::class);
|
||||
$queryData->setMapClassName(NotificationItemWithIdAndName::class);
|
||||
$queryData->setQuery($query);
|
||||
$queryData->setOnErrorMessage(__u('Error while retrieving the notifications'));
|
||||
|
||||
@@ -276,7 +276,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific
|
||||
ORDER BY id';
|
||||
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(NotificationData::class);
|
||||
$queryData->setMapClassName(NotificationItemWithIdAndName::class);
|
||||
$queryData->setQuery($query);
|
||||
$queryData->setParams($ids);
|
||||
|
||||
@@ -350,7 +350,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific
|
||||
public function search(ItemSearchData $itemSearchData): QueryResult
|
||||
{
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(NotificationData::class);
|
||||
$queryData->setMapClassName(NotificationItemWithIdAndName::class);
|
||||
$queryData->setSelect('id, type, component, description, `date`, checked, userId, sticky, onlyAdmin');
|
||||
$queryData->setFrom('Notification');
|
||||
$queryData->setOrder('`date` DESC');
|
||||
@@ -387,7 +387,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific
|
||||
int $userId
|
||||
): QueryResult {
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(NotificationData::class);
|
||||
$queryData->setMapClassName(NotificationItemWithIdAndName::class);
|
||||
$queryData->setSelect('id, type, component, description, `date`, checked, userId, sticky, onlyAdmin');
|
||||
$queryData->setFrom('Notification');
|
||||
$queryData->setOrder('`date` DESC');
|
||||
@@ -434,7 +434,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific
|
||||
int $userId
|
||||
): QueryResult {
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(NotificationData::class);
|
||||
$queryData->setMapClassName(NotificationItemWithIdAndName::class);
|
||||
$queryData->setSelect('id, type, component, description, `date`, checked, userId, sticky, onlyAdmin');
|
||||
$queryData->setFrom('Notification');
|
||||
$queryData->setOrder('`date` DESC');
|
||||
@@ -518,7 +518,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific
|
||||
ORDER BY id';
|
||||
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(NotificationData::class);
|
||||
$queryData->setMapClassName(NotificationItemWithIdAndName::class);
|
||||
$queryData->setQuery($query);
|
||||
$queryData->setParams([$component, $userId]);
|
||||
$queryData->setOnErrorMessage(__u('Error while retrieving the notifications'));
|
||||
@@ -551,7 +551,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific
|
||||
ORDER BY `date` DESC ';
|
||||
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(NotificationData::class);
|
||||
$queryData->setMapClassName(NotificationItemWithIdAndName::class);
|
||||
$queryData->setQuery($query);
|
||||
$queryData->addParam($id);
|
||||
$queryData->setOnErrorMessage(__u('Error while retrieving the notifications'));
|
||||
@@ -585,7 +585,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific
|
||||
ORDER BY `date` DESC ';
|
||||
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(NotificationData::class);
|
||||
$queryData->setMapClassName(NotificationItemWithIdAndName::class);
|
||||
$queryData->setQuery($query);
|
||||
$queryData->addParam($id);
|
||||
$queryData->setOnErrorMessage(__u('Error while retrieving the notifications'));
|
||||
@@ -618,7 +618,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific
|
||||
ORDER BY `date` DESC ';
|
||||
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(NotificationData::class);
|
||||
$queryData->setMapClassName(NotificationItemWithIdAndName::class);
|
||||
$queryData->setQuery($query);
|
||||
$queryData->addParam($id);
|
||||
$queryData->setOnErrorMessage(__u('Error while retrieving the notifications'));
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SP\Infrastructure\Plugin\Repositories;
|
||||
|
||||
use RuntimeException;
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
@@ -82,7 +82,7 @@ final class PluginBaseRepository extends BaseRepository implements PluginReposit
|
||||
public function getEnabled(): QueryResult
|
||||
{
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(ItemData::class);
|
||||
$queryData->setMapClassName(ItemItemWithIdAndName::class);
|
||||
$queryData->setQuery('SELECT id, `name` FROM Plugin WHERE enabled = 1 ORDER BY id');
|
||||
|
||||
return $this->db->doSelect($queryData);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -25,14 +25,14 @@
|
||||
namespace SP\Infrastructure\Plugin\Repositories;
|
||||
|
||||
use SP\DataModel\EncryptedModel;
|
||||
use SP\Domain\Common\Adapters\HydratableInterface;
|
||||
use SP\Domain\Common\Models\HydratableModel;
|
||||
use SP\Domain\Common\Models\Model;
|
||||
use SP\Domain\Common\Models\SerializedModel;
|
||||
|
||||
/**
|
||||
* Class PluginDataModel
|
||||
*/
|
||||
final class PluginDataModel extends Model implements HydratableInterface
|
||||
final class PluginDataModel extends Model implements HydratableModel
|
||||
{
|
||||
use SerializedModel;
|
||||
use EncryptedModel;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -24,13 +24,13 @@
|
||||
|
||||
namespace SP\Infrastructure\Plugin\Repositories;
|
||||
|
||||
use SP\Domain\Common\Adapters\DataModelInterface;
|
||||
use SP\Domain\Common\Models\ItemWithIdAndNameModel;
|
||||
use SP\Domain\Common\Models\Model;
|
||||
|
||||
/**
|
||||
* Class PluginModel
|
||||
*/
|
||||
class PluginModel extends Model implements DataModelInterface
|
||||
class PluginModel extends Model implements ItemWithIdAndNameModel
|
||||
{
|
||||
protected ?int $id = null;
|
||||
protected ?string $name = null;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SP\Infrastructure\User\Repositories;
|
||||
|
||||
use SP\DataModel\ItemSearchData;
|
||||
use SP\DataModel\UserProfileData;
|
||||
use SP\DataModel\UserProfileItemWithIdAndName;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\User\Ports\UserProfileRepository;
|
||||
@@ -111,7 +111,7 @@ final class UserProfileBaseRepository extends BaseRepository implements UserProf
|
||||
public function getById(int $id): QueryResult
|
||||
{
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(UserProfileData::class);
|
||||
$queryData->setMapClassName(UserProfileItemWithIdAndName::class);
|
||||
$queryData->setQuery('SELECT id, `name`, `profile` FROM UserProfile WHERE id = ? LIMIT 1');
|
||||
$queryData->addParam($id);
|
||||
|
||||
@@ -128,7 +128,7 @@ final class UserProfileBaseRepository extends BaseRepository implements UserProf
|
||||
public function getAll(): QueryResult
|
||||
{
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(UserProfileData::class);
|
||||
$queryData->setMapClassName(UserProfileItemWithIdAndName::class);
|
||||
$queryData->setQuery('SELECT id, `name` FROM UserProfile ORDER BY `name`');
|
||||
|
||||
return $this->db->doSelect($queryData);
|
||||
@@ -153,7 +153,7 @@ final class UserProfileBaseRepository extends BaseRepository implements UserProf
|
||||
'SELECT id, `name` FROM UserProfile WHERE id IN ('.$this->buildParamsFromArray($ids).')';
|
||||
|
||||
$queryData = new QueryData();
|
||||
$queryData->setMapClassName(UserProfileData::class);
|
||||
$queryData->setMapClassName(UserProfileItemWithIdAndName::class);
|
||||
$queryData->setQuery($query);
|
||||
$queryData->setParams($ids);
|
||||
|
||||
@@ -217,7 +217,7 @@ final class UserProfileBaseRepository extends BaseRepository implements UserProf
|
||||
/**
|
||||
* Creates an item
|
||||
*
|
||||
* @param UserProfileData $itemData
|
||||
* @param UserProfileItemWithIdAndName $itemData
|
||||
*
|
||||
* @return int
|
||||
* @throws ConstraintException
|
||||
@@ -244,7 +244,7 @@ final class UserProfileBaseRepository extends BaseRepository implements UserProf
|
||||
/**
|
||||
* Checks whether the item is duplicated on adding
|
||||
*
|
||||
* @param UserProfileData $itemData
|
||||
* @param UserProfileItemWithIdAndName $itemData
|
||||
*
|
||||
* @return bool
|
||||
* @throws ConstraintException
|
||||
@@ -262,7 +262,7 @@ final class UserProfileBaseRepository extends BaseRepository implements UserProf
|
||||
/**
|
||||
* Updates an item
|
||||
*
|
||||
* @param UserProfileData $itemData
|
||||
* @param UserProfileItemWithIdAndName $itemData
|
||||
*
|
||||
* @return int
|
||||
* @throws ConstraintException
|
||||
@@ -293,7 +293,7 @@ final class UserProfileBaseRepository extends BaseRepository implements UserProf
|
||||
/**
|
||||
* Checks whether the item is duplicated on updating
|
||||
*
|
||||
* @param UserProfileData $itemData
|
||||
* @param UserProfileItemWithIdAndName $itemData
|
||||
*
|
||||
* @return bool
|
||||
* @throws ConstraintException
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SP\Mvc\View\Components;
|
||||
|
||||
use RuntimeException;
|
||||
use SP\Domain\Common\Adapters\DataModelInterface;
|
||||
use SP\Domain\Common\Models\ItemWithIdAndNameModel;
|
||||
use SP\Domain\Core\Exceptions\SPException;
|
||||
use SP\Http\JsonResponse;
|
||||
|
||||
@@ -76,7 +76,7 @@ final class SelectItemAdapter implements ItemAdapterInterface
|
||||
$out = [];
|
||||
|
||||
foreach ($this->items as $item) {
|
||||
if (!$item instanceof DataModelInterface) {
|
||||
if (!$item instanceof ItemWithIdAndNameModel) {
|
||||
throw new RuntimeException(__u('Wrong object type'));
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ final class SelectItemAdapter implements ItemAdapterInterface
|
||||
{
|
||||
return array_map(
|
||||
static function ($item) {
|
||||
if (!$item instanceof DataModelInterface) {
|
||||
if (!$item instanceof ItemWithIdAndNameModel) {
|
||||
throw new RuntimeException(__u('Wrong object type'));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -27,7 +27,7 @@ namespace SP\Providers\Notification;
|
||||
use Exception;
|
||||
use SP\Core\Application;
|
||||
use SP\Core\Events\Event;
|
||||
use SP\DataModel\NotificationData;
|
||||
use SP\DataModel\NotificationItemWithIdAndName;
|
||||
use SP\Domain\Core\Events\EventReceiver;
|
||||
use SP\Domain\Notification\Ports\NotificationServiceInterface;
|
||||
use SP\Providers\EventsTrait;
|
||||
@@ -96,7 +96,7 @@ final class NotificationHandler extends Provider implements EventReceiver
|
||||
$userIds = $eventMessage !== null ? $eventMessage->getExtra('userId') : [];
|
||||
|
||||
foreach ($userIds as $userId) {
|
||||
$notificationData = new NotificationData();
|
||||
$notificationData = new NotificationItemWithIdAndName();
|
||||
$notificationData->setType(__('Request'));
|
||||
$notificationData->setComponent(__('Accounts'));
|
||||
$notificationData->setUserId($userId);
|
||||
@@ -107,9 +107,9 @@ final class NotificationHandler extends Provider implements EventReceiver
|
||||
}
|
||||
|
||||
/**
|
||||
* @param NotificationData $notificationData
|
||||
* @param NotificationItemWithIdAndName $notificationData
|
||||
*/
|
||||
private function notify(NotificationData $notificationData): void
|
||||
private function notify(NotificationItemWithIdAndName $notificationData): void
|
||||
{
|
||||
try {
|
||||
$this->notificationService->create($notificationData);
|
||||
@@ -129,7 +129,7 @@ final class NotificationHandler extends Provider implements EventReceiver
|
||||
if ($notify[0] === true) {
|
||||
$userId = $eventMessage->getExtra('userId')[0];
|
||||
|
||||
$notificationData = new NotificationData();
|
||||
$notificationData = new NotificationItemWithIdAndName();
|
||||
$notificationData->setType(__('Notification'));
|
||||
$notificationData->setComponent(__('Accounts'));
|
||||
$notificationData->setUserId($userId);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
@@ -27,7 +27,7 @@ namespace SP\Util;
|
||||
use FilesystemIterator;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use SP\DataModel\FileData;
|
||||
use SP\DataModel\FileItemWithIdAndName;
|
||||
use SP\Domain\Core\Exceptions\FileNotFoundException;
|
||||
use SP\Domain\Core\Exceptions\InvalidClassException;
|
||||
use SP\Infrastructure\File\FileException;
|
||||
@@ -80,7 +80,7 @@ class FileUtil
|
||||
return rmdir($dir);
|
||||
}
|
||||
|
||||
public static function isImage(FileData $fileData): bool
|
||||
public static function isImage(FileItemWithIdAndName $fileData): bool
|
||||
{
|
||||
return in_array(strtolower($fileData->getType()), self::IMAGE_MIME, true);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ use PHPUnit\Framework\MockObject\Exception;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use SP\Core\Acl\Actions;
|
||||
use SP\Core\Context\ContextException;
|
||||
use SP\DataModel\ActionData;
|
||||
use SP\DataModel\ActionItemWithIdAndName;
|
||||
use SP\Domain\Core\Acl\ActionNotFoundException;
|
||||
use SP\Domain\Storage\Ports\FileCacheService;
|
||||
use SP\Domain\Storage\Ports\XmlFileStorageService;
|
||||
@@ -106,7 +106,7 @@ class ActionsTest extends UnitaryTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ActionData[]
|
||||
* @return ActionItemWithIdAndName[]
|
||||
*/
|
||||
private function checkLoadAndSave(): array
|
||||
{
|
||||
@@ -124,7 +124,7 @@ class ActionsTest extends UnitaryTestCase
|
||||
->willReturn($actions);
|
||||
|
||||
$actionsMapped = array_map(
|
||||
static fn(array $a) => new ActionData($a['id'], $a['name'], $a['text'], $a['route']),
|
||||
static fn(array $a) => new ActionItemWithIdAndName($a['id'], $a['name'], $a['text'], $a['route']),
|
||||
$actions
|
||||
);
|
||||
|
||||
@@ -172,7 +172,7 @@ class ActionsTest extends UnitaryTestCase
|
||||
$actions = $this->getActions();
|
||||
|
||||
$actionsMapped = array_map(
|
||||
static fn(array $a) => new ActionData($a['id'], $a['name'], $a['text'], $a['route']),
|
||||
static fn(array $a) => new ActionItemWithIdAndName($a['id'], $a['name'], $a['text'], $a['route']),
|
||||
$actions
|
||||
);
|
||||
|
||||
@@ -272,7 +272,7 @@ class ActionsTest extends UnitaryTestCase
|
||||
->willReturn($actions);
|
||||
|
||||
$actionsMapped = array_map(
|
||||
static fn(array $a) => new ActionData($a['id'], $a['name'], $a['text'], $a['route']),
|
||||
static fn(array $a) => new ActionItemWithIdAndName($a['id'], $a['name'], $a['text'], $a['route']),
|
||||
$actions
|
||||
);
|
||||
|
||||
@@ -292,7 +292,7 @@ class ActionsTest extends UnitaryTestCase
|
||||
public function testGetActionById()
|
||||
{
|
||||
$actionsMapped = array_map(
|
||||
static fn(array $a) => new ActionData($a['id'], $a['name'], $a['text'], $a['route']),
|
||||
static fn(array $a) => new ActionItemWithIdAndName($a['id'], $a['name'], $a['text'], $a['route']),
|
||||
$this->getActions()
|
||||
);
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace SPT\Domain\Account\Adapters;
|
||||
use League\Fractal\Manager;
|
||||
use League\Fractal\Resource\Item;
|
||||
use PHPUnit\Framework\MockObject\Exception;
|
||||
use SP\DataModel\ActionData;
|
||||
use SP\DataModel\ActionItemWithIdAndName;
|
||||
use SP\Domain\Account\Adapters\AccountAdapter;
|
||||
use SP\Domain\Core\Acl\AclActionsInterface;
|
||||
use SP\Domain\Core\Acl\ActionNotFoundException;
|
||||
@@ -57,7 +57,7 @@ class AccountAdapterTest extends UnitaryTestCase
|
||||
->method('getActionById')
|
||||
->with(AclActionsInterface::ACCOUNT_VIEW)
|
||||
->willReturn(
|
||||
new ActionData(
|
||||
new ActionItemWithIdAndName(
|
||||
self::$faker->randomNumber(),
|
||||
self::$faker->colorName,
|
||||
self::$faker->sentence,
|
||||
@@ -140,7 +140,7 @@ class AccountAdapterTest extends UnitaryTestCase
|
||||
->method('getActionById')
|
||||
->with(AclActionsInterface::ACCOUNT_VIEW)
|
||||
->willReturn(
|
||||
new ActionData(
|
||||
new ActionItemWithIdAndName(
|
||||
self::$faker->randomNumber(),
|
||||
self::$faker->colorName,
|
||||
self::$faker->sentence,
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace SPT\Domain\Account\Services;
|
||||
|
||||
use PHPUnit\Framework\MockObject\Exception;
|
||||
use SP\Core\Acl\Acl;
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Account\Adapters\AccountPermission;
|
||||
use SP\Domain\Account\Dtos\AccountAclDto;
|
||||
use SP\Domain\Account\Services\AccountAcl;
|
||||
@@ -75,8 +75,8 @@ class AccountAclTest extends UnitaryTestCase
|
||||
'isPrivateGroup' => 0,
|
||||
'otherUserGroupEdit' => 0,
|
||||
'otherUserEdit' => 0,
|
||||
'users' => [new ItemData(['id' => 3, 'isEdit' => 1])],
|
||||
'groups' => [new ItemData(['id' => 2, 'isEdit' => 1])],
|
||||
'users' => [new ItemItemWithIdAndName(['id' => 3, 'isEdit' => 1])],
|
||||
'groups' => [new ItemItemWithIdAndName(['id' => 2, 'isEdit' => 1])],
|
||||
|
||||
],
|
||||
2 => [
|
||||
@@ -88,8 +88,8 @@ class AccountAclTest extends UnitaryTestCase
|
||||
'otherUserEdit' => 0,
|
||||
'users' => [],
|
||||
'groups' => [
|
||||
new ItemData(['id' => 2, 'isEdit' => 1]),
|
||||
new ItemData(['id' => 3, 'isEdit' => 1]),
|
||||
new ItemItemWithIdAndName(['id' => 2, 'isEdit' => 1]),
|
||||
new ItemItemWithIdAndName(['id' => 3, 'isEdit' => 1]),
|
||||
],
|
||||
],
|
||||
3 => [
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
namespace SPT\Domain\Account\Services;
|
||||
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use SP\DataModel\FileData;
|
||||
use SP\DataModel\FileExtData;
|
||||
use SP\DataModel\FileItemWithIdAndName;
|
||||
use SP\Domain\Account\Ports\AccountFileRepository;
|
||||
use SP\Domain\Account\Services\AccountFile;
|
||||
use SP\Domain\Common\Services\ServiceException;
|
||||
@@ -59,8 +59,8 @@ class AccountFileTest extends UnitaryTestCase
|
||||
*/
|
||||
public function testCreate(): void
|
||||
{
|
||||
$fileData = FileData::buildFromSimpleModel(FileDataGenerator::factory()->buildFileData())
|
||||
->mutate(
|
||||
$fileData = FileItemWithIdAndName::buildFromSimpleModel(FileDataGenerator::factory()->buildFileData())
|
||||
->mutate(
|
||||
['type' => self::$faker->mimeType()]
|
||||
);
|
||||
|
||||
@@ -83,7 +83,7 @@ class AccountFileTest extends UnitaryTestCase
|
||||
*/
|
||||
public function testCreateWithThumbnail(): void
|
||||
{
|
||||
$fileData = FileData::buildFromSimpleModel(FileDataGenerator::factory()->buildFileData());
|
||||
$fileData = FileItemWithIdAndName::buildFromSimpleModel(FileDataGenerator::factory()->buildFileData());
|
||||
|
||||
$this->accountFileRepository
|
||||
->expects(self::once())
|
||||
@@ -221,7 +221,7 @@ class AccountFileTest extends UnitaryTestCase
|
||||
*/
|
||||
public function testGetByAccountId(): void
|
||||
{
|
||||
$fileData = FileData::buildFromSimpleModel(FileDataGenerator::factory()->buildFileData());
|
||||
$fileData = FileItemWithIdAndName::buildFromSimpleModel(FileDataGenerator::factory()->buildFileData());
|
||||
|
||||
$queryResult = new QueryResult([$fileData]);
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ use SP\Domain\Core\Exceptions\NoSuchPropertyException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\Core\Exceptions\ValidationException;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetService;
|
||||
use SP\Mvc\Controller\Validators\ValidatorInterface;
|
||||
use SPT\Generators\AccountDataGenerator;
|
||||
use SPT\Generators\ItemPresetDataGenerator;
|
||||
@@ -48,8 +48,8 @@ use SPT\UnitaryTestCase;
|
||||
class AccountPresetTest extends UnitaryTestCase
|
||||
{
|
||||
|
||||
private ItemPresetServiceInterface|MockObject $itemPresetService;
|
||||
private AccountPreset $accountPreset;
|
||||
private ItemPresetService|MockObject $itemPresetService;
|
||||
private AccountPreset $accountPreset;
|
||||
private ValidatorInterface|MockObject $passwordValidator;
|
||||
|
||||
/**
|
||||
@@ -170,7 +170,7 @@ class AccountPresetTest extends UnitaryTestCase
|
||||
$configData = $this->config->getConfigData();
|
||||
$configData->setAccountExpireEnabled(true);
|
||||
|
||||
$this->itemPresetService = $this->createMock(ItemPresetServiceInterface::class);
|
||||
$this->itemPresetService = $this->createMock(ItemPresetService::class);
|
||||
$this->passwordValidator = $this->createMock(ValidatorInterface::class);
|
||||
$this->accountToUserGroupRepository = $this->createMock(AccountToUserGroupRepository::class);
|
||||
$this->accountToUserRepository = $this->createMock(AccountToUserRepository::class);
|
||||
|
||||
@@ -32,7 +32,6 @@ use SP\Domain\Account\Dtos\AccountUpdateBulkDto;
|
||||
use SP\Domain\Account\Dtos\AccountUpdateDto;
|
||||
use SP\Domain\Account\Dtos\EncryptedPassword;
|
||||
use SP\Domain\Account\Models\Account as AccountModel;
|
||||
use SP\Domain\Account\Models\ItemPreset;
|
||||
use SP\Domain\Account\Ports\AccountCryptService;
|
||||
use SP\Domain\Account\Ports\AccountHistoryService;
|
||||
use SP\Domain\Account\Ports\AccountItemsService;
|
||||
@@ -48,8 +47,9 @@ use SP\Domain\Config\Ports\ConfigService;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\Core\Exceptions\SPException;
|
||||
use SP\Domain\ItemPreset\Models\ItemPreset;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetService;
|
||||
use SP\Infrastructure\Common\Repositories\NoSuchItemException;
|
||||
use SP\Infrastructure\Database\QueryResult;
|
||||
use SPT\Generators\AccountDataGenerator;
|
||||
@@ -67,9 +67,9 @@ class AccountTest extends UnitaryTestCase
|
||||
private AccountRepository|MockObject $accountRepository;
|
||||
private AccountToUserGroupRepository|MockObject $accountToUserGroupRepository;
|
||||
private AccountToUserRepository|MockObject $accountToUserRepository;
|
||||
private AccountToTagRepository|MockObject $accountToTagRepository;
|
||||
private ItemPresetServiceInterface|MockObject $itemPresetService;
|
||||
private AccountHistoryService|MockObject $accountHistoryService;
|
||||
private AccountToTagRepository|MockObject $accountToTagRepository;
|
||||
private ItemPresetService|MockObject $itemPresetService;
|
||||
private AccountHistoryService|MockObject $accountHistoryService;
|
||||
private ConfigService|MockObject $configService;
|
||||
private AccountCryptService|MockObject $accountCryptService;
|
||||
private AccountPresetService|MockObject $accountPresetService;
|
||||
@@ -1329,7 +1329,7 @@ class AccountTest extends UnitaryTestCase
|
||||
$this->accountToUserGroupRepository = $this->createMock(AccountToUserGroupRepository::class);
|
||||
$this->accountToUserRepository = $this->createMock(AccountToUserRepository::class);
|
||||
$this->accountToTagRepository = $this->createMock(AccountToTagRepository::class);
|
||||
$this->itemPresetService = $this->createMock(ItemPresetServiceInterface::class);
|
||||
$this->itemPresetService = $this->createMock(ItemPresetService::class);
|
||||
$this->accountHistoryService = $this->createMock(AccountHistoryService::class);
|
||||
$this->configService = $this->createMock(ConfigService::class);
|
||||
$this->accountCryptService = $this->createMock(AccountCryptService::class);
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SPT\Domain\Account\Services;
|
||||
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Account\Ports\AccountToTagRepository;
|
||||
use SP\Domain\Account\Services\AccountToTag;
|
||||
use SP\Domain\Common\Models\Simple;
|
||||
@@ -67,7 +67,7 @@ class AccountToTagTest extends UnitaryTestCase
|
||||
$actual = $this->accountToTag->getTagsByAccountId($accountId);
|
||||
$expected = $result->getData(Simple::class)->toArray(null, null, true);
|
||||
|
||||
$this->assertTrue($actual[0] instanceof ItemData);
|
||||
$this->assertTrue($actual[0] instanceof ItemItemWithIdAndName);
|
||||
$this->assertEquals($expected, $actual[0]->toArray());
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SPT\Domain\Account\Services;
|
||||
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Account\Ports\AccountToUserGroupRepository;
|
||||
use SP\Domain\Account\Services\AccountToUserGroup;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
@@ -57,7 +57,7 @@ class AccountToUserGroupTest extends UnitaryTestCase
|
||||
$result =
|
||||
new QueryResult(
|
||||
[
|
||||
new ItemData(
|
||||
new ItemItemWithIdAndName(
|
||||
[
|
||||
'id' => self::$faker->randomNumber(),
|
||||
'name' => self::$faker->colorName,
|
||||
@@ -74,9 +74,9 @@ class AccountToUserGroupTest extends UnitaryTestCase
|
||||
->willReturn($result);
|
||||
|
||||
$actual = $this->accountToUserGroup->getUserGroupsByAccountId($accountId);
|
||||
$expected = $result->getData(ItemData::class)->toArray(null, null, true);
|
||||
$expected = $result->getData(ItemItemWithIdAndName::class)->toArray(null, null, true);
|
||||
|
||||
$this->assertTrue($actual[0] instanceof ItemData);
|
||||
$this->assertTrue($actual[0] instanceof ItemItemWithIdAndName);
|
||||
$this->assertEquals($expected, $actual[0]->toArray(null, null, true));
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace SPT\Domain\Account\Services;
|
||||
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Account\Ports\AccountToUserRepository;
|
||||
use SP\Domain\Account\Services\AccountToUser;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
@@ -57,7 +57,7 @@ class AccountToUserTest extends UnitaryTestCase
|
||||
$result =
|
||||
new QueryResult(
|
||||
[
|
||||
new ItemData(
|
||||
new ItemItemWithIdAndName(
|
||||
[
|
||||
'id' => self::$faker->randomNumber(),
|
||||
'name' => self::$faker->colorName,
|
||||
@@ -75,9 +75,9 @@ class AccountToUserTest extends UnitaryTestCase
|
||||
->willReturn($result);
|
||||
|
||||
$actual = $this->accountToUser->getUsersByAccountId($accountId);
|
||||
$expected = $result->getData(ItemData::class)->toArray(null, null, true);
|
||||
$expected = $result->getData(ItemItemWithIdAndName::class)->toArray(null, null, true);
|
||||
|
||||
$this->assertTrue($actual[0] instanceof ItemData);
|
||||
$this->assertTrue($actual[0] instanceof ItemItemWithIdAndName);
|
||||
$this->assertEquals($expected, $actual[0]->toArray(null, null, true));
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ use DOMDocument;
|
||||
use PHPUnit\Framework\MockObject\Exception;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use RuntimeException;
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Account\Ports\AccountService;
|
||||
use SP\Domain\Account\Ports\AccountToTagService;
|
||||
use SP\Domain\Common\Services\ServiceException;
|
||||
@@ -56,7 +56,7 @@ class XmlAccountExportTest extends UnitaryTestCase
|
||||
public function testExport()
|
||||
{
|
||||
$account = AccountDataGenerator::factory()->buildAccount();
|
||||
$tag = new ItemData(['id' => self::$faker->randomNumber(3)]);
|
||||
$tag = new ItemItemWithIdAndName(['id' => self::$faker->randomNumber(3)]);
|
||||
|
||||
$document = new DOMDocument();
|
||||
|
||||
|
||||
322
tests/SPT/Domain/ItemPreset/Services/ItemPresetTest.php
Normal file
322
tests/SPT/Domain/ItemPreset/Services/ItemPresetTest.php
Normal file
@@ -0,0 +1,322 @@
|
||||
<?php
|
||||
/*
|
||||
* sysPass
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
* sysPass is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* sysPass is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SPT\Domain\ItemPreset\Services;
|
||||
|
||||
use PHPUnit\Framework\MockObject\Exception;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use SP\Domain\Common\Services\ServiceException;
|
||||
use SP\Domain\Core\Exceptions\ConstraintException;
|
||||
use SP\Domain\Core\Exceptions\QueryException;
|
||||
use SP\Domain\ItemPreset\Models\ItemPreset as ItemPresetModel;
|
||||
use SP\Domain\ItemPreset\Ports\ItemPresetRepository;
|
||||
use SP\Domain\ItemPreset\Services\ItemPreset;
|
||||
use SP\Infrastructure\Common\Repositories\NoSuchItemException;
|
||||
use SP\Infrastructure\Database\QueryResult;
|
||||
use SPT\Generators\ItemPresetDataGenerator;
|
||||
use SPT\Generators\ItemSearchDataGenerator;
|
||||
use SPT\UnitaryTestCase;
|
||||
|
||||
/**
|
||||
* Class ItemPresetTest
|
||||
*
|
||||
* @group unitary
|
||||
*/
|
||||
class ItemPresetTest extends UnitaryTestCase
|
||||
{
|
||||
|
||||
private ItemPresetRepository|MockObject $itemPresetRepository;
|
||||
private ItemPreset $itemPreset;
|
||||
|
||||
/**
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
$itemPreset = ItemPresetDataGenerator::factory()->buildItemPresetData((object)['foo' => 'bar']);
|
||||
|
||||
$this->itemPresetRepository
|
||||
->expects(self::once())
|
||||
->method('update')
|
||||
->with($itemPreset)
|
||||
->willReturn(1);
|
||||
|
||||
$this->itemPreset->update($itemPreset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function testGetForUser()
|
||||
{
|
||||
$itemPreset = ItemPresetDataGenerator::factory()->buildItemPresetData((object)['foo' => 'bar']);
|
||||
|
||||
$this->itemPresetRepository
|
||||
->expects(self::once())
|
||||
->method('getByFilter')
|
||||
->with('test', 100, 200, 300)
|
||||
->willReturn(new QueryResult([$itemPreset]));
|
||||
|
||||
$out = $this->itemPreset->getForUser('test', 100, 200, 300);
|
||||
|
||||
$this->assertEquals($itemPreset, $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function testCreate()
|
||||
{
|
||||
$itemPreset = ItemPresetDataGenerator::factory()->buildItemPresetData((object)['foo' => 'bar']);
|
||||
|
||||
$queryResult = new QueryResult([]);
|
||||
|
||||
$this->itemPresetRepository
|
||||
->expects(self::once())
|
||||
->method('create')
|
||||
->with($itemPreset)
|
||||
->willReturn($queryResult->setLastId(100));
|
||||
|
||||
$this->assertEquals(100, $this->itemPreset->create($itemPreset));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function testGetForCurrentUser()
|
||||
{
|
||||
$itemPreset = ItemPresetDataGenerator::factory()->buildItemPresetData((object)['foo' => 'bar']);
|
||||
|
||||
$userData = $this->context->getUserData();
|
||||
|
||||
$this->itemPresetRepository
|
||||
->expects(self::once())
|
||||
->method('getByFilter')
|
||||
->with('test', $userData->getId(), $userData->getUserGroupId(), $userData->getUserProfileId())
|
||||
->willReturn(new QueryResult([$itemPreset]));
|
||||
|
||||
$out = $this->itemPreset->getForCurrentUser('test');
|
||||
|
||||
$this->assertEquals($itemPreset, $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ConstraintException
|
||||
* @throws ServiceException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function testDeleteByIdBatch()
|
||||
{
|
||||
$ids = array_map(static fn() => self::$faker->randomNumber(3), range(0, 4));
|
||||
|
||||
$queryResult = new QueryResult([]);
|
||||
|
||||
$this->itemPresetRepository
|
||||
->expects(self::once())
|
||||
->method('deleteByIdBatch')
|
||||
->with($ids)
|
||||
->willReturn($queryResult->setAffectedNumRows(5));
|
||||
|
||||
$this->assertEquals(5, $this->itemPreset->deleteByIdBatch($ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ConstraintException
|
||||
* @throws ServiceException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function testDeleteByIdBatchWithException()
|
||||
{
|
||||
$ids = array_map(static fn() => self::$faker->randomNumber(3), range(0, 4));
|
||||
|
||||
$queryResult = new QueryResult([]);
|
||||
|
||||
$this->itemPresetRepository
|
||||
->expects(self::once())
|
||||
->method('deleteByIdBatch')
|
||||
->with($ids)
|
||||
->willReturn($queryResult->setAffectedNumRows(4));
|
||||
|
||||
$this->expectException(ServiceException::class);
|
||||
$this->expectExceptionMessage('Error while deleting the values');
|
||||
|
||||
$this->itemPreset->deleteByIdBatch($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testGetAll()
|
||||
{
|
||||
$queryResult = $this->createMock(QueryResult::class);
|
||||
$queryResult->expects($this->once())
|
||||
->method('getDataAsArray')
|
||||
->with(ItemPresetModel::class)
|
||||
->willReturn([1]);
|
||||
|
||||
$this->itemPresetRepository
|
||||
->expects($this->once())
|
||||
->method('getAll')
|
||||
->willReturn($queryResult);
|
||||
|
||||
$out = $this->itemPreset->getAll();
|
||||
|
||||
$this->assertEquals([1], $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NoSuchItemException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testGetById()
|
||||
{
|
||||
$itemPreset = ItemPresetDataGenerator::factory()->buildItemPresetData((object)['foo' => 'bar']);
|
||||
|
||||
$queryResult = $this->createMock(QueryResult::class);
|
||||
$queryResult->expects($this->once())
|
||||
->method('getNumRows')
|
||||
->willReturn(1);
|
||||
|
||||
$queryResult->expects($this->once())
|
||||
->method('getData')
|
||||
->with(ItemPresetModel::class)
|
||||
->willReturn($itemPreset);
|
||||
|
||||
$this->itemPresetRepository
|
||||
->expects($this->once())
|
||||
->method('getById')
|
||||
->with(100)
|
||||
->willReturn($queryResult);
|
||||
|
||||
$out = $this->itemPreset->getById(100);
|
||||
|
||||
$this->assertEquals($itemPreset, $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NoSuchItemException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testGetByIdWithNoRows()
|
||||
{
|
||||
$queryResult = $this->createMock(QueryResult::class);
|
||||
$queryResult->expects($this->once())
|
||||
->method('getNumRows')
|
||||
->willReturn(0);
|
||||
|
||||
$this->itemPresetRepository
|
||||
->expects($this->once())
|
||||
->method('getById')
|
||||
->with(100)
|
||||
->willReturn($queryResult);
|
||||
|
||||
$this->expectException(NoSuchItemException::class);
|
||||
$this->expectExceptionMessage('Value not found');
|
||||
|
||||
$this->itemPreset->getById(100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function testSearch()
|
||||
{
|
||||
$itemPreset = ItemPresetDataGenerator::factory()->buildItemPresetData((object)['foo' => 'bar']);
|
||||
$itemSearchData = ItemSearchDataGenerator::factory()->buildItemSearchData();
|
||||
|
||||
$queryResult = new QueryResult([$itemPreset]);
|
||||
|
||||
$this->itemPresetRepository
|
||||
->expects($this->once())
|
||||
->method('search')
|
||||
->with($itemSearchData)
|
||||
->willReturn($queryResult);
|
||||
|
||||
$out = $this->itemPreset->search($itemSearchData);
|
||||
|
||||
$this->assertEquals($queryResult, $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NoSuchItemException
|
||||
* @throws Exception
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
$queryResult = $this->createMock(QueryResult::class);
|
||||
$queryResult->expects($this->once())
|
||||
->method('getAffectedNumRows')
|
||||
->willReturn(1);
|
||||
|
||||
$this->itemPresetRepository
|
||||
->expects($this->once())
|
||||
->method('delete')
|
||||
->with(100)
|
||||
->willReturn($queryResult);
|
||||
|
||||
$this->itemPreset->delete(100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NoSuchItemException
|
||||
* @throws Exception
|
||||
* @throws ConstraintException
|
||||
* @throws QueryException
|
||||
*/
|
||||
public function testDeleteWithNoRows()
|
||||
{
|
||||
$queryResult = $this->createMock(QueryResult::class);
|
||||
$queryResult->expects($this->once())
|
||||
->method('getAffectedNumRows')
|
||||
->willReturn(0);
|
||||
|
||||
$this->itemPresetRepository
|
||||
->expects($this->once())
|
||||
->method('delete')
|
||||
->with(100)
|
||||
->willReturn($queryResult);
|
||||
|
||||
$this->expectException(NoSuchItemException::class);
|
||||
$this->expectExceptionMessage('Value not found');
|
||||
|
||||
$this->itemPreset->delete(100);
|
||||
}
|
||||
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->itemPresetRepository = $this->createMock(ItemPresetRepository::class);
|
||||
|
||||
$this->itemPreset = new ItemPreset($this->application, $this->itemPresetRepository);
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace SPT\Generators;
|
||||
|
||||
use SP\DataModel\ItemData;
|
||||
use SP\DataModel\ItemItemWithIdAndName;
|
||||
use SP\Domain\Account\Dtos\AccountCreateDto;
|
||||
use SP\Domain\Account\Dtos\AccountEnrichedDto;
|
||||
use SP\Domain\Account\Dtos\AccountHistoryDto;
|
||||
@@ -94,12 +94,12 @@ final class AccountDataGenerator extends DataGenerator
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ItemData[]
|
||||
* @return ItemItemWithIdAndName[]
|
||||
*/
|
||||
public function buildItemData(): array
|
||||
{
|
||||
return array_map(
|
||||
fn() => new ItemData(['id' => $this->faker->randomNumber(3), 'name' => $this->faker->name]),
|
||||
fn() => new ItemItemWithIdAndName(['id' => $this->faker->randomNumber(3), 'name' => $this->faker->name]),
|
||||
range(0, 9)
|
||||
);
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user