test(IT): Test account edit pass

Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
Rubén D
2024-08-04 12:05:52 +02:00
parent ad5135add2
commit e7782c50e1
25 changed files with 345 additions and 295 deletions

View File

@@ -46,12 +46,14 @@ final class CopyController extends AccountViewBase
public function copyAction(int $id): void
{
try {
$this->accountHelper->initializeFor(AclActionsInterface::ACCOUNT_COPY);
$accountEnrichedDto = new AccountEnrichedDto($this->accountService->getByIdEnriched($id));
$accountEnrichedDto = $this->accountService->withUsers($accountEnrichedDto);
$accountEnrichedDto = $this->accountService->withUserGroups($accountEnrichedDto);
$accountEnrichedDto = $this->accountService->withTags($accountEnrichedDto);
$this->accountHelper->setViewForAccount($accountEnrichedDto, AclActionsInterface::ACCOUNT_COPY);
$this->accountHelper->setViewForAccount($accountEnrichedDto);
$this->view->addTemplate('account');
$this->view->assign(

View File

@@ -47,22 +47,16 @@ final class CopyPassHistoryController extends AccountControllerBase
{
use JsonTrait;
private AccountService $accountService;
private AccountPasswordHelper $accountPasswordHelper;
public function __construct(
Application $application,
WebControllerHelper $webControllerHelper,
AccountService $accountService,
AccountPasswordHelper $accountPasswordHelper
Application $application,
WebControllerHelper $webControllerHelper,
private readonly AccountService $accountService,
private readonly AccountPasswordHelper $accountPasswordHelper
) {
parent::__construct(
$application,
$webControllerHelper
);
$this->accountService = $accountService;
$this->accountPasswordHelper = $accountPasswordHelper;
}
/**

View File

@@ -43,7 +43,8 @@ final class CreateController extends AccountViewBase
public function createAction(): void
{
try {
$this->accountHelper->setViewForBlank(AclActionsInterface::ACCOUNT_CREATE);
$this->accountHelper->initializeFor(AclActionsInterface::ACCOUNT_CREATE);
$this->accountHelper->setViewForBlank();
$this->view->addTemplate('account');
$this->view->assign(

View File

@@ -67,12 +67,14 @@ final class DeleteController extends AccountControllerBase
public function deleteAction(?int $id = null): void
{
try {
$this->accountHelper->initializeFor(AclActionsInterface::ACCOUNT_DELETE);
$accountEnrichedDto = new AccountEnrichedDto($this->accountService->getByIdEnriched($id));
$accountEnrichedDto = $this->accountService->withUsers($accountEnrichedDto);
$accountEnrichedDto = $this->accountService->withUserGroups($accountEnrichedDto);
$accountEnrichedDto = $this->accountService->withTags($accountEnrichedDto);
$this->accountHelper->setViewForAccount($accountEnrichedDto, AclActionsInterface::ACCOUNT_DELETE);
$this->accountHelper->setViewForAccount($accountEnrichedDto);
$this->view->addTemplate('account');
$this->view->assign(

View File

@@ -26,9 +26,13 @@ namespace SP\Modules\Web\Controllers\Account;
use Exception;
use SP\Core\Events\Event;
use SP\Domain\Account\Dtos\AccountEnrichedDto;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Modules\Web\Util\ErrorUtil;
use function SP\__;
use function SP\processException;
/**
* Class EditController
*/
@@ -43,12 +47,14 @@ final class EditController extends AccountViewBase
public function editAction(int $id): void
{
try {
$accountEnrichedDto = $this->accountService->getByIdEnriched($id);
$this->accountHelper->initializeFor(AclActionsInterface::ACCOUNT_EDIT);
$accountEnrichedDto = new AccountEnrichedDto($this->accountService->getByIdEnriched($id));
$accountEnrichedDto = $this->accountService->withUsers($accountEnrichedDto);
$accountEnrichedDto = $this->accountService->withUserGroups($accountEnrichedDto);
$accountEnrichedDto = $this->accountService->withTags($accountEnrichedDto);
$this->accountHelper->setViewForAccount($accountEnrichedDto, AclActionsInterface::ACCOUNT_EDIT);
$this->accountHelper->setViewForAccount($accountEnrichedDto);
$this->view->addTemplate('account');
$this->view->assign(

View File

@@ -28,9 +28,13 @@ use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use SP\Core\Events\Event;
use SP\Domain\Account\Dtos\AccountEnrichedDto;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Modules\Web\Util\ErrorUtil;
use function SP\__;
use function SP\processException;
/**
* Class EditPassController
*/
@@ -47,11 +51,13 @@ final class EditPassController extends AccountViewBase
public function editPassAction(int $id): void
{
try {
$accountEnrichedDto = $this->accountService->getByIdEnriched($id);
$this->accountHelper->initializeFor(AclActionsInterface::ACCOUNT_EDIT_PASS);
$accountEnrichedDto = new AccountEnrichedDto($this->accountService->getByIdEnriched($id));
$accountEnrichedDto = $this->accountService->withUsers($accountEnrichedDto);
$accountEnrichedDto = $this->accountService->withUserGroups($accountEnrichedDto);
$this->accountHelper->setViewForAccount($accountEnrichedDto, AclActionsInterface::ACCOUNT_EDIT_PASS);
$this->accountHelper->setViewForAccount($accountEnrichedDto);
$this->view->addTemplate('account-editpass');
$this->view->assign(

View File

@@ -29,6 +29,7 @@ use SP\Core\Application;
use SP\Domain\Account\Adapters\AccountPermission;
use SP\Domain\Account\Adapters\AccountSearchItem;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Acl\AclInterface;
use SP\Domain\Core\UI\ThemeIconsInterface;
use SP\Domain\Http\Ports\RequestService;
use SP\Html\DataGrid\Action\DataGridAction;
@@ -47,7 +48,8 @@ final class AccountActionsHelper extends HelperBase
Application $application,
TemplateInterface $template,
RequestService $request,
private readonly ThemeIconsInterface $icons
private readonly ThemeIconsInterface $icons,
private readonly AclInterface $acl
) {
parent::__construct($application, $template, $request);
}
@@ -140,8 +142,8 @@ final class AccountActionsHelper extends HelperBase
$action->setTitle(__('Back'));
$action->addClass('btn-action');
$action->setIcon($this->icons->back());
$action->addData('action-route', Acl::getActionRoute(AclActionsInterface::ACCOUNT_VIEW));
$action->addData('onclick', Acl::getActionRoute(AclActionsInterface::ACCOUNT_VIEW));
$action->addData('action-route', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_VIEW));
$action->addData('onclick', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_VIEW));
$action->addAttribute('type', 'button');
return $action;
@@ -160,8 +162,8 @@ final class AccountActionsHelper extends HelperBase
$action->addClass('btn-action');
$action->setIcon($this->icons->editPass());
$action->setRuntimeFilter(AccountSearchItem::class, 'isShowViewPass');
$action->addData('action-route', Acl::getActionRoute(AclActionsInterface::ACCOUNT_EDIT_PASS));
$action->addData('onclick', Acl::getActionRoute(AclActionsInterface::ACCOUNT_EDIT_PASS));
$action->addData('action-route', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_EDIT_PASS));
$action->addData('onclick', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_EDIT_PASS));
$action->addAttribute('type', 'button');
return $action;
@@ -180,8 +182,8 @@ final class AccountActionsHelper extends HelperBase
$action->addClass('btn-action');
$action->setIcon($this->icons->edit());
$action->setRuntimeFilter(AccountSearchItem::class, 'isShowEdit');
$action->addData('action-route', Acl::getActionRoute(AclActionsInterface::ACCOUNT_EDIT));
$action->addData('onclick', Acl::getActionRoute(AclActionsInterface::ACCOUNT_EDIT));
$action->addData('action-route', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_EDIT));
$action->addData('onclick', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_EDIT));
$action->addAttribute('type', 'button');
return $action;
@@ -199,8 +201,8 @@ final class AccountActionsHelper extends HelperBase
$action->addClass('btn-action');
$action->setIcon($this->icons->email());
$action->setRuntimeFilter(AccountSearchItem::class, 'isShowRequest');
$action->addData('action-route', Acl::getActionRoute(AclActionsInterface::ACCOUNT_REQUEST));
$action->addData('onclick', Acl::getActionRoute(AclActionsInterface::ACCOUNT_VIEW));
$action->addData('action-route', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_REQUEST));
$action->addData('onclick', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_VIEW));
$action->addAttribute('type', 'submit');
return $action;
@@ -338,8 +340,8 @@ final class AccountActionsHelper extends HelperBase
$action->addClass('btn-action');
$action->setIcon($this->icons->delete());
$action->setRuntimeFilter(AccountSearchItem::class, 'isShowDelete');
$action->addData('action-route', Acl::getActionRoute(AclActionsInterface::ACCOUNT_DELETE));
$action->addData('onclick', Acl::getActionRoute(AclActionsInterface::ACCOUNT_DELETE));
$action->addData('action-route', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_DELETE));
$action->addData('onclick', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_DELETE));
$action->addAttribute('type', 'button');
return $action;
@@ -356,9 +358,9 @@ final class AccountActionsHelper extends HelperBase
$action->setTitle(__('Update Public Link'));
$action->addClass('btn-action');
$action->setIcon($this->icons->publicLink());
$action->addData('action-route', Acl::getActionRoute(AclActionsInterface::PUBLICLINK_REFRESH));
$action->addData('action-route', $this->acl->getRouteFor(AclActionsInterface::PUBLICLINK_REFRESH));
$action->addData('onclick', 'link/refresh');
$action->addData('action-next', Acl::getActionRoute(AclActionsInterface::ACCOUNT_VIEW));
$action->addData('action-next', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_VIEW));
$action->addAttribute('type', 'button');
return $action;
@@ -377,9 +379,9 @@ final class AccountActionsHelper extends HelperBase
$action->setTitle(__('Delete Public Link'));
$action->addClass('btn-action');
$action->setIcon($icon);
$action->addData('action-route', Acl::getActionRoute(AclActionsInterface::PUBLICLINK_DELETE));
$action->addData('action-route', $this->acl->getRouteFor(AclActionsInterface::PUBLICLINK_DELETE));
$action->addData('onclick', 'link/delete');
$action->addData('action-next', Acl::getActionRoute(AclActionsInterface::ACCOUNT_VIEW));
$action->addData('action-next', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_VIEW));
$action->addAttribute('type', 'button');
return $action;
@@ -398,7 +400,7 @@ final class AccountActionsHelper extends HelperBase
$action->setIcon($this->icons->publicLink());
$action->addData('action-route', 'publicLink/saveCreateFromAccount');
$action->addData('onclick', 'link/save');
$action->addData('action-next', Acl::getActionRoute(AclActionsInterface::ACCOUNT_VIEW));
$action->addData('action-next', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_VIEW));
$action->addAttribute('type', 'button');
return $action;
@@ -417,9 +419,9 @@ final class AccountActionsHelper extends HelperBase
$action->addClass('btn-action');
$action->setIcon($this->icons->viewPass());
$action->setRuntimeFilter(AccountSearchItem::class, 'isShowViewPass');
$action->addData('action-route', Acl::getActionRoute(AclActionsInterface::ACCOUNT_HISTORY_VIEW_PASS));
$action->addData('action-route', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_HISTORY_VIEW_PASS));
$action->addData('action-full', 1);
$action->addData('onclick', Acl::getActionRoute(AclActionsInterface::ACCOUNT_HISTORY_VIEW_PASS));
$action->addData('onclick', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_HISTORY_VIEW_PASS));
$action->addAttribute('type', 'button');
return $action;
@@ -439,7 +441,7 @@ final class AccountActionsHelper extends HelperBase
$action->addClass('clip-pass-button');
$action->setIcon($this->icons->clipboard());
$action->setRuntimeFilter(AccountSearchItem::class, 'isShowCopyPass');
$action->addData('action-route', Acl::getActionRoute(AclActionsInterface::ACCOUNT_HISTORY_COPY_PASS));
$action->addData('action-route', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_HISTORY_COPY_PASS));
$action->addData('action-full', 0);
$action->addData('useclipboard', '1');
$action->addAttribute('type', 'button');
@@ -460,9 +462,9 @@ final class AccountActionsHelper extends HelperBase
$action->addClass('btn-action');
$action->setIcon($this->icons->viewPass());
$action->setRuntimeFilter(AccountSearchItem::class, 'isShowViewPass');
$action->addData('action-route', Acl::getActionRoute(AclActionsInterface::ACCOUNT_VIEW_PASS));
$action->addData('action-route', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_VIEW_PASS));
$action->addData('action-full', 1);
$action->addData('onclick', Acl::getActionRoute(AclActionsInterface::ACCOUNT_VIEW_PASS));
$action->addData('onclick', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_VIEW_PASS));
$action->addAttribute('type', 'button');
return $action;
@@ -474,7 +476,7 @@ final class AccountActionsHelper extends HelperBase
public function getCopyPassAction(): DataGridAction
{
$action = new DataGridAction();
$action->setId(AclActionsInterface::ACCOUNT_VIEW_PASS);
$action->setId(AclActionsInterface::ACCOUNT_COPY_PASS);
$action->setType(DataGridActionType::VIEW_ITEM);
$action->setName(__('Copy Password to Clipboard'));
$action->setTitle(__('Copy Password to Clipboard'));
@@ -482,7 +484,7 @@ final class AccountActionsHelper extends HelperBase
$action->addClass('clip-pass-button');
$action->setIcon($this->icons->clipboard());
$action->setRuntimeFilter(AccountSearchItem::class, 'isShowCopyPass');
$action->addData('action-route', Acl::getActionRoute(AclActionsInterface::ACCOUNT_COPY_PASS));
$action->addData('action-route', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_COPY_PASS));
$action->addData('action-full', 0);
$action->addData('useclipboard', '1');
$action->addAttribute('type', 'button');
@@ -503,8 +505,8 @@ final class AccountActionsHelper extends HelperBase
$action->addClass('btn-action');
$action->setIcon($this->icons->copy());
$action->setRuntimeFilter(AccountSearchItem::class, 'isShowCopy');
$action->addData('action-route', Acl::getActionRoute(AclActionsInterface::ACCOUNT_COPY));
$action->addData('onclick', Acl::getActionRoute(AclActionsInterface::ACCOUNT_COPY));
$action->addData('action-route', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_COPY));
$action->addData('onclick', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_COPY));
$action->addAttribute('type', 'button');
return $action;

View File

@@ -24,7 +24,6 @@
namespace SP\Modules\Web\Controllers\Helpers\Account;
use SP\Core\Acl\Acl;
use SP\Core\Application;
use SP\Domain\Account\Adapters\AccountPermission;
use SP\Domain\Account\Dtos\AccountAclDto;
@@ -41,6 +40,7 @@ use SP\Domain\Common\Services\ServiceException;
use SP\Domain\Core\Acl\AccountPermissionException;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Acl\AclInterface;
use SP\Domain\Core\Acl\UnauthorizedActionException;
use SP\Domain\Core\Acl\UnauthorizedPageException;
use SP\Domain\Core\Bootstrap\UriContextInterface;
use SP\Domain\Core\Exceptions\ConstraintException;
@@ -73,55 +73,32 @@ final class AccountHelper extends AccountHelperBase
{
use ItemTrait;
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 UserService $userService;
private UserGroupService $userGroupService;
private TagService $tagService;
private MasterPassService $masterPassService;
private ?AccountPermission $accountPermission = null;
private ?int $accountId = null;
public function __construct(
Application $application,
TemplateInterface $template,
RequestService $request,
AclInterface $acl,
AccountService $accountService,
AccountHistoryService $accountHistoryService,
PublicLinkService $publicLinkService,
ItemPresetService $itemPresetService,
MasterPassService $masterPassService,
AccountActionsHelper $accountActionsHelper,
AccountAclService $accountAclService,
CategoryService $categoryService,
ClientService $clientService,
CustomFieldDataService $customFieldService,
UserService $userService,
UserGroupService $userGroupService,
TagService $tagService,
private readonly UriContextInterface $uriContext
Application $application,
TemplateInterface $template,
RequestService $request,
AclInterface $acl,
private readonly AccountService $accountService,
private readonly AccountHistoryService $accountHistoryService,
private readonly PublicLinkService $publicLinkService,
private readonly ItemPresetService $itemPresetService,
MasterPassService $masterPassService,
AccountActionsHelper $accountActionsHelper,
private readonly AccountAclService $accountAclService,
private readonly CategoryService $categoryService,
private readonly ClientService $clientService,
private readonly CustomFieldDataService $customFieldService,
private readonly UserService $userService,
private readonly UserGroupService $userGroupService,
private readonly TagService $tagService,
private readonly UriContextInterface $uriContext
) {
parent::__construct($application, $template, $request, $acl, $accountActionsHelper, $masterPassService);
$this->accountService = $accountService;
$this->accountHistoryService = $accountHistoryService;
$this->publicLinkService = $publicLinkService;
$this->itemPresetService = $itemPresetService;
$this->accountAclService = $accountAclService;
$this->categoryService = $categoryService;
$this->clientService = $clientService;
$this->customFieldService = $customFieldService;
$this->userService = $userService;
$this->userGroupService = $userGroupService;
$this->tagService = $tagService;
$this->view->assign('changesHash', '');
$this->view->assign('chkUserEdit', false);
$this->view->assign('chkGroupEdit', false);
@@ -131,25 +108,21 @@ final class AccountHelper extends AccountHelperBase
* Sets account's view variables
*
* @param AccountEnrichedDto $accountDetailsResponse
* @param int $actionId
*
* @throws AccountPermissionException
* @throws UnauthorizedPageException
* @throws ConstraintException
* @throws QueryException
* @throws SPException
* @throws ServiceException
* @throws UpdatedMasterPassException
* @throws NoSuchItemException
* @throws UnauthorizedActionException
*/
public function setViewForAccount(AccountEnrichedDto $accountDetailsResponse, int $actionId): void
public function setViewForAccount(AccountEnrichedDto $accountDetailsResponse): void
{
if (!$this->actionGranted) {
throw UnauthorizedActionException::error('This view requires initialization');
}
$this->accountId = $accountDetailsResponse->getAccountView()->getId();
$this->actionId = $actionId;
$this->checkActionAccess();
$this->accountAcl = $this->checkAccess($accountDetailsResponse);
$this->accountPermission = $this->checkAccess($accountDetailsResponse);
$accountData = $accountDetailsResponse->getAccountView();
@@ -215,7 +188,7 @@ final class AccountHelper extends AccountHelperBase
$this->view->assign('maxFileSize', round($this->configData->getFilesAllowedSize() / 1024, 1));
$this->view->assign('filesAllowedExts', implode(',', $this->configData->getFilesAllowedExts()));
if ($this->configData->isPublinksEnabled() && $this->accountAcl->isShowLink()) {
if ($this->configData->isPublinksEnabled() && $this->accountPermission->isShowLink()) {
try {
$publicLinkData = $this->publicLinkService->getHashForItem($this->accountId);
$accountActionsDto->setPublicLinkId($publicLinkData->getId());
@@ -278,14 +251,14 @@ final class AccountHelper extends AccountHelperBase
$this->view->assign(
'accountActions',
$this->accountActionsHelper->getActionsForAccount(
$this->accountAcl,
$this->accountPermission,
$accountActionsDto
)
);
$this->view->assign(
'accountActionsMenu',
$this->accountActionsHelper->getActionsGrouppedForAccount(
$this->accountAcl,
$this->accountPermission,
$accountActionsDto
)
);
@@ -296,25 +269,25 @@ final class AccountHelper extends AccountHelperBase
/**
* Comprobar si el usuario dispone de acceso al módulo
*
* @param AccountEnrichedDto $accountDetailsResponse
* @param AccountEnrichedDto $accountEnrichedDto
*
* @return AccountPermission
* @throws AccountPermissionException
* @throws ConstraintException
* @throws QueryException
*/
protected function checkAccess(AccountEnrichedDto $accountDetailsResponse): AccountPermission
protected function checkAccess(AccountEnrichedDto $accountEnrichedDto): AccountPermission
{
$accountAcl = $this->accountAclService->getAcl(
$accountPermission = $this->accountAclService->getAcl(
$this->actionId,
AccountAclDto::makeFromAccount($accountDetailsResponse)
AccountAclDto::makeFromAccount($accountEnrichedDto)
);
if ($accountAcl->checkAccountAccess($this->actionId) === false) {
throw new AccountPermissionException(SPException::INFO);
if ($accountPermission->checkAccountAccess($this->actionId) === false) {
throw new AccountPermissionException();
}
return $accountAcl;
return $accountPermission;
}
/**
@@ -355,24 +328,24 @@ final class AccountHelper extends AccountHelperBase
'addClientEnabled',
!$this->isView && $this->acl->checkUserAccess(AclActionsInterface::CLIENT)
);
$this->view->assign('addClientRoute', Acl::getActionRoute(AclActionsInterface::CLIENT_CREATE));
$this->view->assign('addClientRoute', $this->acl->getRouteFor(AclActionsInterface::CLIENT_CREATE));
$this->view->assign(
'addCategoryEnabled',
!$this->isView && $this->acl->checkUserAccess(AclActionsInterface::CATEGORY)
);
$this->view->assign('addCategoryRoute', Acl::getActionRoute(AclActionsInterface::CATEGORY_CREATE));
$this->view->assign('addCategoryRoute', $this->acl->getRouteFor(AclActionsInterface::CATEGORY_CREATE));
$this->view->assign(
'addTagEnabled',
!$this->isView
&& $this->acl->checkUserAccess(AclActionsInterface::TAG)
);
$this->view->assign('addTagRoute', Acl::getActionRoute(AclActionsInterface::TAG_CREATE));
$this->view->assign('fileListRoute', Acl::getActionRoute(AclActionsInterface::ACCOUNT_FILE_LIST));
$this->view->assign('fileUploadRoute', Acl::getActionRoute(AclActionsInterface::ACCOUNT_FILE_UPLOAD));
$this->view->assign('addTagRoute', $this->acl->getRouteFor(AclActionsInterface::TAG_CREATE));
$this->view->assign('fileListRoute', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_FILE_LIST));
$this->view->assign('fileUploadRoute', $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_FILE_UPLOAD));
$this->view->assign('disabled', $this->isView ? 'disabled' : '');
$this->view->assign('readonly', $this->isView ? 'readonly' : '');
$this->view->assign('showViewCustomPass', $this->accountAcl->isShowViewPass());
$this->view->assign('accountAcl', $this->accountAcl);
$this->view->assign('showViewCustomPass', $this->accountPermission->isShowViewPass());
$this->view->assign('accountAcl', $this->accountPermission);
if ($this->accountId) {
$baseUrl = ($this->configData->getApplicationUrl() ?? $this->uriContext->getWebUri()) .
@@ -388,9 +361,6 @@ final class AccountHelper extends AccountHelperBase
/**
* Sets account's view for a blank form
*
* @param int $actionId
*
* @return void
* @throws UnauthorizedPageException
* @throws ConstraintException
* @throws NoSuchPropertyException
@@ -400,17 +370,18 @@ final class AccountHelper extends AccountHelperBase
* @throws ServiceException
* @throws UpdatedMasterPassException
*/
public function setViewForBlank(int $actionId): void
public function setViewForBlank(): void
{
$this->actionId = $actionId;
$this->accountAcl = new AccountPermission($actionId);
if (!$this->actionGranted) {
throw new UnauthorizedActionException();
}
$this->checkActionAccess();
$this->accountPermission = new AccountPermission($this->actionId);
$userProfileData = $this->context->getUserProfile() ?? new ProfileData();
$userData = $this->context->getUserData();
$this->accountAcl->setShowPermission(
$this->accountPermission->setShowPermission(
$userData->getIsAdminApp()
|| $userData->getIsAdminAcc()
|| $userProfileData->isAccPermission()
@@ -465,7 +436,7 @@ final class AccountHelper extends AccountHelperBase
$this->view->assign(
'accountActions',
$this->accountActionsHelper->getActionsForAccount(
$this->accountAcl,
$this->accountPermission,
new AccountActionsDto($this->accountId)
)
);

View File

@@ -24,42 +24,35 @@
namespace SP\Modules\Web\Controllers\Helpers\Account;
use SP\Core\Acl\Acl;
use SP\Core\Application;
use SP\Domain\Core\Acl\AclInterface;
use SP\Domain\Core\Acl\UnauthorizedPageException;
use SP\Domain\Core\Exceptions\SPException;
use SP\Domain\Crypt\Ports\MasterPassService;
use SP\Domain\Http\Ports\RequestService;
use SP\Domain\User\Services\UpdatedMasterPassException;
use SP\Modules\Web\Controllers\Helpers\HelperBase;
use SP\Mvc\View\TemplateInterface;
use function SP\__u;
/**
* Class AccountHelperBase
*/
abstract class AccountHelperBase extends HelperBase
{
protected ?int $actionId = null;
protected AccountActionsHelper $accountActionsHelper;
protected bool $isView = false;
protected Acl $acl;
private MasterPassService $masterPassService;
protected ?int $actionId = null;
protected bool $isView = false;
protected bool $actionGranted = false;
public function __construct(
Application $application,
TemplateInterface $template,
RequestService $request,
AclInterface $acl,
AccountActionsHelper $accountActionsHelper,
MasterPassService $masterPassService
Application $application,
TemplateInterface $template,
RequestService $request,
protected readonly AclInterface $acl,
protected readonly AccountActionsHelper $accountActionsHelper,
private readonly MasterPassService $masterPassService
) {
parent::__construct($application, $template, $request);
$this->acl = $acl;
$this->accountActionsHelper = $accountActionsHelper;
$this->masterPassService = $masterPassService;
}
/**
@@ -74,15 +67,18 @@ abstract class AccountHelperBase extends HelperBase
* @throws UnauthorizedPageException
* @throws UpdatedMasterPassException
*/
final protected function checkActionAccess(): void
final public function initializeFor(int $actionId): void
{
if (!$this->acl->checkUserAccess($this->actionId)) {
throw new UnauthorizedPageException(SPException::INFO);
if (!$this->acl->checkUserAccess($actionId)) {
throw UnauthorizedPageException::info($actionId);
}
if (!$this->masterPassService->checkUserUpdateMPass($this->context->getUserData()->getLastUpdateMPass())
) {
throw new UpdatedMasterPassException(SPException::INFO);
throw UpdatedMasterPassException::info(__u('The master password needs to be updated'));
}
$this->actionId = $actionId;
$this->actionGranted = true;
}
}

View File

@@ -77,7 +77,7 @@ final class AccountHistoryHelper extends AccountHelperBase
/**
* @param AccountHistory $accountHistoryData
* @param int $actionId
* @param int $actionId
*
* @throws AccountPermissionException
* @throws UnauthorizedPageException
@@ -93,7 +93,7 @@ final class AccountHistoryHelper extends AccountHelperBase
$this->actionId = $actionId;
$this->accountId = $accountHistoryData->getAccountId();
$this->checkActionAccess();
$this->initializeFor($actionId);
$this->checkAccess($accountHistoryData);
$this->view->assign('isView', true);
@@ -105,8 +105,10 @@ final class AccountHistoryHelper extends AccountHelperBase
$this->view->assign(
'historyData',
SelectItemAdapter::factory(self::mapHistoryForDateSelect($this->accountHistoryService->getHistoryForAccount($this->accountId)))
->getItemsFromArraySelected([$accountHistoryData->getId()])
SelectItemAdapter::factory(
self::mapHistoryForDateSelect($this->accountHistoryService->getHistoryForAccount($this->accountId))
)
->getItemsFromArraySelected([$accountHistoryData->getId()])
);
$this->view->assign('accountPassDate', date('Y-m-d H:i:s', $accountHistoryData->getPassDate()));
@@ -148,7 +150,7 @@ final class AccountHistoryHelper extends AccountHelperBase
/**
* Comprobar si el usuario dispone de acceso al módulo
*
* @param AccountHistory $accountHistoryData
* @param AccountHistory $accountHistoryData
*
* @throws AccountPermissionException
* @throws ConstraintException

View File

@@ -57,7 +57,7 @@ final class AccountRequestHelper extends AccountHelperBase
$this->actionId = $actionId;
$this->accountAcl = new AccountPermission($actionId);
$this->checkActionAccess();
$this->initializeFor();
$accountData = $accountDetailsResponse->getAccountView();

View File

@@ -137,7 +137,7 @@ final class AuthTokenGrid extends GridBase
$gridActionSearch->setOnSubmitFunction('appMgmt/search');
$gridActionSearch->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::AUTHTOKEN_SEARCH)
$this->acl->getRouteFor(AclActionsInterface::AUTHTOKEN_SEARCH)
);
return $gridActionSearch;
@@ -158,7 +158,7 @@ final class AuthTokenGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/show');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::AUTHTOKEN_CREATE)
$this->acl->getRouteFor(AclActionsInterface::AUTHTOKEN_CREATE)
);
return $gridAction;
@@ -178,7 +178,7 @@ final class AuthTokenGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/show');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::AUTHTOKEN_VIEW)
$this->acl->getRouteFor(AclActionsInterface::AUTHTOKEN_VIEW)
);
return $gridAction;
@@ -198,7 +198,7 @@ final class AuthTokenGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/show');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::AUTHTOKEN_EDIT)
$this->acl->getRouteFor(AclActionsInterface::AUTHTOKEN_EDIT)
);
return $gridAction;
@@ -218,7 +218,7 @@ final class AuthTokenGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/delete');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::AUTHTOKEN_DELETE)
$this->acl->getRouteFor(AclActionsInterface::AUTHTOKEN_DELETE)
);
return $gridAction;

View File

@@ -24,7 +24,6 @@
namespace SP\Modules\Web\Controllers\Helpers\Grid;
use SP\Core\Acl\Acl;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Exceptions\SPException;
use SP\Html\DataGrid\Action\DataGridAction;
@@ -157,7 +156,7 @@ final class PublicLinkGrid extends GridBase
$gridActionSearch->setOnSubmitFunction('appMgmt/search');
$gridActionSearch->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::PUBLICLINK_SEARCH)
$this->acl->getRouteFor(AclActionsInterface::PUBLICLINK_SEARCH)
);
return $gridActionSearch;
@@ -178,7 +177,7 @@ final class PublicLinkGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/show');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::PUBLICLINK_CREATE)
$this->acl->getRouteFor(AclActionsInterface::PUBLICLINK_CREATE)
);
return $gridAction;
@@ -198,7 +197,7 @@ final class PublicLinkGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/show');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::PUBLICLINK_VIEW)
$this->acl->getRouteFor(AclActionsInterface::PUBLICLINK_VIEW)
);
return $gridAction;
@@ -217,7 +216,7 @@ final class PublicLinkGrid extends GridBase
$gridAction->setOnClickFunction('link/refresh');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::PUBLICLINK_REFRESH)
$this->acl->getRouteFor(AclActionsInterface::PUBLICLINK_REFRESH)
);
return $gridAction;
@@ -237,7 +236,7 @@ final class PublicLinkGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/delete');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::PUBLICLINK_DELETE)
$this->acl->getRouteFor(AclActionsInterface::PUBLICLINK_DELETE)
);
return $gridAction;

View File

@@ -24,8 +24,6 @@
namespace SP\Modules\Web\Controllers\Helpers\Grid;
use SP\Core\Acl\Acl;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Exceptions\SPException;
use SP\Html\DataGrid\Action\DataGridAction;
@@ -53,6 +51,7 @@ final class UserGrid extends GridBase
* @param QueryResult $queryResult
*
* @return DataGridInterface
* @throws SPException
*/
public function getGrid(QueryResult $queryResult): DataGridInterface
{
@@ -85,6 +84,7 @@ final class UserGrid extends GridBase
/**
* @return DataGridInterface
* @throws SPException
*/
protected function getGridLayout(): DataGridInterface
{
@@ -163,7 +163,7 @@ final class UserGrid extends GridBase
$gridActionSearch->setOnSubmitFunction('appMgmt/search');
$gridActionSearch->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::USER_SEARCH)
$this->acl->getRouteFor(AclActionsInterface::USER_SEARCH)
);
return $gridActionSearch;
@@ -184,7 +184,7 @@ final class UserGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/show');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::USER_CREATE)
$this->acl->getRouteFor(AclActionsInterface::USER_CREATE)
);
return $gridAction;
@@ -204,7 +204,7 @@ final class UserGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/show');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::USER_VIEW)
$this->acl->getRouteFor(AclActionsInterface::USER_VIEW)
);
return $gridAction;
@@ -224,7 +224,7 @@ final class UserGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/show');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::USER_EDIT)
$this->acl->getRouteFor(AclActionsInterface::USER_EDIT)
);
return $gridAction;
@@ -245,7 +245,7 @@ final class UserGrid extends GridBase
$gridAction->setFilterRowSource('isLdap');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::USER_EDIT_PASS)
$this->acl->getRouteFor(AclActionsInterface::USER_EDIT_PASS)
);
return $gridAction;
@@ -265,7 +265,7 @@ final class UserGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/delete');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::USER_DELETE)
$this->acl->getRouteFor(AclActionsInterface::USER_DELETE)
);
return $gridAction;

View File

@@ -25,7 +25,6 @@
namespace SP\Modules\Web\Controllers\Helpers\Grid;
use SP\Core\Acl\Acl;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Exceptions\SPException;
use SP\Html\DataGrid\Action\DataGridAction;
@@ -53,6 +52,7 @@ final class UserGroupGrid extends GridBase
* @param QueryResult $queryResult
*
* @return DataGridInterface
* @throws SPException
*/
public function getGrid(QueryResult $queryResult): DataGridInterface
{
@@ -84,6 +84,7 @@ final class UserGroupGrid extends GridBase
/**
* @return DataGridInterface
* @throws SPException
*/
protected function getGridLayout(): DataGridInterface
{
@@ -142,7 +143,7 @@ final class UserGroupGrid extends GridBase
$gridActionSearch->setOnSubmitFunction('appMgmt/search');
$gridActionSearch->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::GROUP_SEARCH)
$this->acl->getRouteFor(AclActionsInterface::GROUP_SEARCH)
);
return $gridActionSearch;
@@ -163,7 +164,7 @@ final class UserGroupGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/show');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::GROUP_CREATE)
$this->acl->getRouteFor(AclActionsInterface::GROUP_CREATE)
);
return $gridAction;
@@ -183,7 +184,7 @@ final class UserGroupGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/show');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::GROUP_VIEW)
$this->acl->getRouteFor(AclActionsInterface::GROUP_VIEW)
);
return $gridAction;
@@ -203,7 +204,7 @@ final class UserGroupGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/show');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::GROUP_EDIT)
$this->acl->getRouteFor(AclActionsInterface::GROUP_EDIT)
);
return $gridAction;
@@ -223,7 +224,7 @@ final class UserGroupGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/delete');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::GROUP_DELETE)
$this->acl->getRouteFor(AclActionsInterface::GROUP_DELETE)
);
return $gridAction;

View File

@@ -25,7 +25,6 @@
namespace SP\Modules\Web\Controllers\Helpers\Grid;
use SP\Core\Acl\Acl;
use SP\Domain\Core\Acl\AclActionsInterface;
use SP\Domain\Core\Exceptions\SPException;
use SP\Html\DataGrid\Action\DataGridAction;
@@ -139,7 +138,7 @@ final class UserProfileGrid extends GridBase
$gridActionSearch->setOnSubmitFunction('appMgmt/search');
$gridActionSearch->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::PROFILE_SEARCH)
$this->acl->getRouteFor(AclActionsInterface::PROFILE_SEARCH)
);
return $gridActionSearch;
@@ -160,7 +159,7 @@ final class UserProfileGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/show');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::PROFILE_CREATE)
$this->acl->getRouteFor(AclActionsInterface::PROFILE_CREATE)
);
return $gridAction;
@@ -180,7 +179,7 @@ final class UserProfileGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/show');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::PROFILE_VIEW)
$this->acl->getRouteFor(AclActionsInterface::PROFILE_VIEW)
);
return $gridAction;
@@ -200,7 +199,7 @@ final class UserProfileGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/show');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::PROFILE_EDIT)
$this->acl->getRouteFor(AclActionsInterface::PROFILE_EDIT)
);
return $gridAction;
@@ -220,7 +219,7 @@ final class UserProfileGrid extends GridBase
$gridAction->setOnClickFunction('appMgmt/delete');
$gridAction->addData(
'action-route',
Acl::getActionRoute(AclActionsInterface::PROFILE_DELETE)
$this->acl->getRouteFor(AclActionsInterface::PROFILE_DELETE)
);
return $gridAction;

View File

@@ -39,16 +39,16 @@ use SP\Mvc\View\TemplateInterface;
*/
abstract class HelperBase
{
protected TemplateInterface $view;
protected ConfigDataInterface $configData;
protected Context $context;
protected EventDispatcherInterface $eventDispatcher;
protected ConfigFileService $config;
protected readonly TemplateInterface $view;
protected readonly ConfigDataInterface $configData;
protected readonly Context $context;
protected readonly EventDispatcherInterface $eventDispatcher;
protected readonly ConfigFileService $config;
public function __construct(
Application $application,
TemplateInterface $template,
protected RequestService $request
Application $application,
TemplateInterface $template,
protected readonly RequestService $request
) {
$this->config = $application->getConfig();
$this->context = $application->getContext();

View File

@@ -24,7 +24,6 @@
namespace SP\Modules\Web\Controllers\Helpers;
use SP\Core\Acl\Acl;
use SP\Core\Application;
use SP\Core\Events\Event;
use SP\Core\Language;
@@ -271,7 +270,7 @@ final class LayoutHelper extends HelperBase
$actionSearch->setData([
'historyReset' => 1,
'view' => 'search',
'route' => Acl::getActionRoute(AclActionsInterface::ACCOUNT),
'route' => $this->acl->getRouteFor(AclActionsInterface::ACCOUNT),
]);
$actions[] = $actionSearch;
@@ -284,7 +283,7 @@ final class LayoutHelper extends HelperBase
$actionNewAccount->setData([
'historyReset' => 0,
'view' => 'account',
'route' => Acl::getActionRoute(AclActionsInterface::ACCOUNT_CREATE),
'route' => $this->acl->getRouteFor(AclActionsInterface::ACCOUNT_CREATE),
]);
$actions[] = $actionNewAccount;
@@ -293,12 +292,12 @@ final class LayoutHelper extends HelperBase
if ($acl->checkUserAccess(AclActionsInterface::ACCESS_MANAGE)) {
$actionAccessManager = new DataGridAction();
$actionAccessManager->setId(AclActionsInterface::ACCESS_MANAGE);
$actionAccessManager->setTitle(Acl::getActionInfo(AclActionsInterface::ACCESS_MANAGE));
$actionAccessManager->setTitle($this->acl->getInfoFor(AclActionsInterface::ACCESS_MANAGE));
$actionAccessManager->setIcon($icons->account());
$actionAccessManager->setData([
'historyReset' => 0,
'view' => 'datatabs',
'route' => Acl::getActionRoute(AclActionsInterface::ACCESS_MANAGE),
'route' => $this->acl->getRouteFor(AclActionsInterface::ACCESS_MANAGE),
]);
$actions[] = $actionAccessManager;
@@ -307,12 +306,12 @@ final class LayoutHelper extends HelperBase
if ($acl->checkUserAccess(AclActionsInterface::ITEMS_MANAGE)) {
$actionItemManager = new DataGridAction();
$actionItemManager->setId(AclActionsInterface::ITEMS_MANAGE);
$actionItemManager->setTitle(Acl::getActionInfo(AclActionsInterface::ITEMS_MANAGE));
$actionItemManager->setTitle($this->acl->getInfoFor(AclActionsInterface::ITEMS_MANAGE));
$actionItemManager->setIcon($icons->group());
$actionItemManager->setData([
'historyReset' => 0,
'view' => 'datatabs',
'route' => Acl::getActionRoute(AclActionsInterface::ITEMS_MANAGE),
'route' => $this->acl->getRouteFor(AclActionsInterface::ITEMS_MANAGE),
]);
$actions[] = $actionItemManager;
@@ -321,12 +320,14 @@ final class LayoutHelper extends HelperBase
if ($acl->checkUserAccess(AclActionsInterface::SECURITY_MANAGE)) {
$actionSecurityManager = new DataGridAction();
$actionSecurityManager->setId(AclActionsInterface::SECURITY_MANAGE);
$actionSecurityManager->setTitle(Acl::getActionInfo(AclActionsInterface::SECURITY_MANAGE));
$actionSecurityManager->setTitle($this->acl->getInfoFor(AclActionsInterface::SECURITY_MANAGE));
$actionSecurityManager->setIcon($icons->getIconByName('security'));
$actionSecurityManager->setData([
'historyReset' => 0,
'view' => 'datatabs',
'route' => Acl::getActionRoute(AclActionsInterface::SECURITY_MANAGE),
'route' => $this->acl->getRouteFor(
AclActionsInterface::SECURITY_MANAGE
),
]);
$actions[] = $actionSecurityManager;
@@ -340,7 +341,7 @@ final class LayoutHelper extends HelperBase
$actionPlugins->setData([
'historyReset' => 1,
'view' => 'plugin',
'route' => Acl::getActionRoute(AclActionsInterface::PLUGIN),
'route' => $this->acl->getRouteFor(AclActionsInterface::PLUGIN),
]);
$actions[] = $actionPlugins;
@@ -354,7 +355,7 @@ final class LayoutHelper extends HelperBase
$actionConfigManager->setData([
'historyReset' => 1,
'view' => 'config',
'route' => Acl::getActionRoute(AclActionsInterface::CONFIG),
'route' => $this->acl->getRouteFor(AclActionsInterface::CONFIG),
]);
$actions[] = $actionConfigManager;

View File

@@ -43,60 +43,13 @@ use function SP\processException;
/**
* Esta clase es la encargada de calcular las access lists de acceso a usuarios.
*/
final class Acl implements AclActionsInterface, AclInterface
final readonly class Acl implements AclActionsInterface, AclInterface
{
/**
* @deprecated
*/
private static ActionsInterface $actionsStatic;
private ActionsInterface $actions;
public function __construct(
private readonly Context $context,
private readonly EventDispatcherInterface $eventDispatcher,
ActionsInterface $actions
private Context $context,
private EventDispatcherInterface $eventDispatcher,
private ActionsInterface $actions
) {
self::$actionsStatic = $actions;
$this->actions = $actions;
}
/**
* Returns action route
*
* @deprecated Use {@link Acl::getRouteFor()} instead
*/
public static function getActionRoute(int $actionId): string
{
try {
return self::$actionsStatic?->getActionById($actionId)->getRoute();
} catch (ActionNotFoundException $e) {
processException($e);
}
return '';
}
/**
* Obtener el nombre de la acción indicada
*
* @param int $actionId El id de la acción
* @param bool $translate
*
* @return string
* @internal param bool $translate Si se devuelve el nombre corto de la acción
* @deprecated Use {@link Acl::getInfoFor()} instead
*/
public static function getActionInfo(int $actionId, bool $translate = true): string
{
try {
$text = self::$actionsStatic?->getActionById($actionId)->getText();
return $translate ? __($text) : $text;
} catch (ActionNotFoundException $e) {
processException($e);
}
return '';
}
/**

View File

@@ -53,8 +53,8 @@ use function SP\processException;
*/
final class AccountAcl extends Service implements AccountAclService
{
private ?AccountAclDto $accountAclDto = null;
private ?AccountPermission $accountAcl = null;
private ?AccountAclDto $accountAclDto = null;
private ?AccountPermission $accountPermission = null;
private UserDataDto $userData;
public function __construct(
@@ -82,8 +82,8 @@ final class AccountAcl extends Service implements AccountAclService
*/
public function getAcl(int $actionId, AccountAclDto $accountAclDto, bool $isHistory = false): AccountPermission
{
$this->accountAcl = new AccountPermission($actionId, $isHistory);
$this->accountAcl->setShowPermission(
$this->accountPermission = new AccountPermission($actionId, $isHistory);
$this->accountPermission->setShowPermission(
self::getShowPermission($this->context->getUserData(), $this->context->getUserProfile())
);
@@ -105,7 +105,7 @@ final class AccountAcl extends Service implements AccountAclService
return $accountAcl;
}
$this->accountAcl->setModified(true);
$this->accountPermission->setModified(true);
}
}
@@ -114,7 +114,7 @@ final class AccountAcl extends Service implements AccountAclService
new Event($this, EventMessage::factory()->addDescription('Account ACL MISS'))
);
$this->accountAcl->setAccountId($accountAclDto->getAccountId());
$this->accountPermission->setAccountId($accountAclDto->getAccountId());
return $this->buildAcl();
}
@@ -186,16 +186,16 @@ final class AccountAcl extends Service implements AccountAclService
private function buildAcl(): AccountPermission
{
$this->compileAccountAccess();
$this->accountAcl->setCompiledAccountAccess(true);
$this->accountPermission->setCompiledAccountAccess(true);
$this->compileShowAccess();
$this->accountAcl->setCompiledShowAccess(true);
$this->accountPermission->setCompiledShowAccess(true);
$this->accountAcl->setTime(time());
$this->accountPermission->setTime(time());
$this->saveAclInCache($this->accountAcl);
$this->saveAclInCache($this->accountPermission);
return $this->accountAcl;
return $this->accountPermission;
}
/**
@@ -204,8 +204,8 @@ final class AccountAcl extends Service implements AccountAclService
*/
private function compileAccountAccess(): void
{
$this->accountAcl->setResultView(false);
$this->accountAcl->setResultEdit(false);
$this->accountPermission->setResultView(false);
$this->accountPermission->setResultEdit(false);
// Check out if user is admin or owner/maingroup
if ($this->userData->getIsAdminApp()
@@ -213,19 +213,19 @@ final class AccountAcl extends Service implements AccountAclService
|| $this->userData->getId() === $this->accountAclDto->getUserId()
|| $this->userData->getUserGroupId() === $this->accountAclDto->getUserGroupId()
) {
$this->accountAcl->setResultView(true);
$this->accountAcl->setResultEdit(true);
$this->accountPermission->setResultView(true);
$this->accountPermission->setResultEdit(true);
return;
}
// Check out if user is listed in secondary users of the account
$userInUsers = $this->getUserInSecondaryUsers($this->userData->getId());
$this->accountAcl->setUserInUsers(count($userInUsers) > 0);
$this->accountPermission->setUserInUsers(count($userInUsers) > 0);
if ($this->accountAcl->isUserInUsers()) {
$this->accountAcl->setResultView(true);
$this->accountAcl->setResultEdit((int)$userInUsers[0]['isEdit'] === 1);
if ($this->accountPermission->isUserInUsers()) {
$this->accountPermission->setResultView(true);
$this->accountPermission->setResultEdit((int)$userInUsers[0]['isEdit'] === 1);
return;
}
@@ -239,9 +239,9 @@ final class AccountAcl extends Service implements AccountAclService
// Check out if user groups match with account's main group
if ($this->getUserGroupsInMainGroup($userGroups)) {
$this->accountAcl->setUserInGroups(true);
$this->accountAcl->setResultView(true);
$this->accountAcl->setResultEdit(true);
$this->accountPermission->setUserInGroups(true);
$this->accountPermission->setResultView(true);
$this->accountPermission->setResultEdit(true);
return;
}
@@ -253,11 +253,11 @@ final class AccountAcl extends Service implements AccountAclService
$this->userData->getUserGroupId()
);
$this->accountAcl->setUserInGroups(count($userGroupsInSecondaryUserGroups) > 0);
$this->accountPermission->setUserInGroups(count($userGroupsInSecondaryUserGroups) > 0);
if ($this->accountAcl->isUserInGroups()) {
$this->accountAcl->setResultView(true);
$this->accountAcl->setResultEdit((int)$userGroupsInSecondaryUserGroups[0]['isEdit'] === 1);
if ($this->accountPermission->isUserInGroups()) {
$this->accountPermission->setResultView(true);
$this->accountPermission->setResultEdit((int)$userGroupsInSecondaryUserGroups[0]['isEdit'] === 1);
}
}
@@ -327,34 +327,36 @@ final class AccountAcl extends Service implements AccountAclService
private function compileShowAccess(): void
{
// Mostrar historial
$this->accountAcl->setShowHistory($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_HISTORY_VIEW));
$this->accountPermission->setShowHistory(
$this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_HISTORY_VIEW)
);
// Mostrar lista archivos
$this->accountAcl->setShowFiles($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_FILE));
$this->accountPermission->setShowFiles($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_FILE));
// Mostrar acción de ver clave
$this->accountAcl->setShowViewPass($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_VIEW_PASS));
$this->accountPermission->setShowViewPass($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_VIEW_PASS));
// Mostrar acción de editar
$this->accountAcl->setShowEdit($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_EDIT));
$this->accountPermission->setShowEdit($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_EDIT));
// Mostrar acción de editar clave
$this->accountAcl->setShowEditPass($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_EDIT_PASS));
$this->accountPermission->setShowEditPass($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_EDIT_PASS));
// Mostrar acción de eliminar
$this->accountAcl->setShowDelete($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_DELETE));
$this->accountPermission->setShowDelete($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_DELETE));
// Mostrar acción de restaurar
$this->accountAcl->setShowRestore($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_EDIT));
$this->accountPermission->setShowRestore($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_EDIT));
// Mostrar acción de enlace público
$this->accountAcl->setShowLink($this->acl->checkUserAccess(AclActionsInterface::PUBLICLINK_CREATE));
$this->accountPermission->setShowLink($this->acl->checkUserAccess(AclActionsInterface::PUBLICLINK_CREATE));
// Mostrar acción de ver cuenta
$this->accountAcl->setShowView($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_VIEW));
$this->accountPermission->setShowView($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_VIEW));
// Mostrar acción de copiar cuenta
$this->accountAcl->setShowCopy($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_COPY));
$this->accountPermission->setShowCopy($this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_COPY));
}
/**

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* sysPass
@@ -38,7 +39,7 @@ final class AccountPermissionException extends SPException
/**
* SPException constructor.
*/
public function __construct(int $type, $code = 0, Exception $previous = null)
public function __construct(int $type = SPException::ERROR, $code = 0, Exception $previous = null)
{
parent::__construct(
__u('You don\'t have permission to access this account'),

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* sysPass
@@ -38,11 +39,11 @@ final class UnauthorizedActionException extends SPException
/**
* SPException constructor.
*
* @param string $type
* @param int $type
* @param int $code
* @param Exception|null $previous
*/
public function __construct(string $type, int $code = 0, Exception $previous = null)
public function __construct(int $type = SPException::ERROR, int $code = 0, Exception $previous = null)
{
parent::__construct(
__u('You don\'t have permission to do this operation'),

View File

@@ -42,9 +42,12 @@ use SP\Core\Bootstrap\PathsContext;
use SP\Core\Definitions\CoreDefinitions;
use SP\Core\Definitions\DomainDefinitions;
use SP\Core\UI\ThemeContext;
use SP\Domain\Account\Adapters\AccountPermission;
use SP\Domain\Account\Ports\AccountAclService;
use SP\Domain\Auth\Ports\LdapConnectionInterface;
use SP\Domain\Config\Ports\ConfigDataInterface;
use SP\Domain\Config\Ports\ConfigFileService;
use SP\Domain\Core\Acl\AclInterface;
use SP\Domain\Core\Bootstrap\BootstrapInterface;
use SP\Domain\Core\Bootstrap\ModuleInterface;
use SP\Domain\Core\Bootstrap\UriContextInterface;
@@ -102,6 +105,21 @@ abstract class IntegrationTestCase extends TestCase
$database = self::createStub(DatabaseInterface::class);
$database->method('runQuery')->willReturnCallback($this->getDatabaseReturn());
$acl = self::createMock(AclInterface::class);
$acl->method('checkUserAccess')->willReturn(true);
$accountAcl = self::createStub(AccountAclService::class);
$accountAcl->method('getAcl')
->willReturnCallback(static function (int $actionId) {
$accountPermission = new AccountPermission($actionId);
$accountPermission->setCompiledAccountAccess(true);
$accountPermission->setCompiledShowAccess(true);
$accountPermission->setResultView(true);
$accountPermission->setResultEdit(true);
return $accountPermission;
});
$mockedDefinitions = [
ConfigFileService::class => $configFileService,
LdapConnectionInterface::class => self::createStub(LdapConnectionInterface::class),
@@ -119,7 +137,9 @@ abstract class IntegrationTestCase extends TestCase
)
->constructorParameter('baseUri', factory([UriContextInterface::class, 'getWebRoot']))
->constructorParameter('module', 'web')
->constructorParameter('name', 'material-blue')
->constructorParameter('name', 'material-blue'),
AclInterface::class => $acl,
AccountAclService::class => $accountAcl
];
@@ -178,7 +198,9 @@ abstract class IntegrationTestCase extends TestCase
*/
protected function getUserDataDto(): UserDataDto
{
return new UserDataDto(UserDataGenerator::factory()->buildUserData());
return new UserDataDto(
UserDataGenerator::factory()->buildUserData()->mutate(['isAdminApp' => false, 'isAdminAcc' => false])
);
}
/**

View File

@@ -65,7 +65,7 @@ class DeleteControllerTest extends IntegrationTestCase
'//div[@class="data-container"]//form[@name="frmaccount" and @data-action-route="account/saveDelete"]|//div[@class="item-actions"]//button'
)->extract(['id']);
return !empty($output) && count($filter) === 3;
return !empty($output) && count($filter) === 2;
}
);

View File

@@ -0,0 +1,89 @@
<?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/>.
*/
declare(strict_types=1);
namespace SP\Tests\Modules\Web\Controllers\Account;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use SP\Domain\Account\Models\AccountView;
use SP\Domain\Core\Exceptions\InvalidClassException;
use SP\Infrastructure\Database\QueryData;
use SP\Infrastructure\Database\QueryResult;
use SP\Infrastructure\File\FileException;
use SP\Mvc\View\OutputHandlerInterface;
use SP\Tests\Generators\AccountDataGenerator;
use SP\Tests\IntegrationTestCase;
use Symfony\Component\DomCrawler\Crawler;
/**
* Class EditControllerTest
*/
#[Group('integration')]
class EditControllerTest extends IntegrationTestCase
{
/**
* @throws NotFoundExceptionInterface
* @throws Exception
* @throws FileException
* @throws InvalidClassException
* @throws ContainerExceptionInterface
*/
public function testEditAction()
{
$definitions = $this->getModuleDefinitions();
$definitions[OutputHandlerInterface::class] = $this->setupOutputHandler(
static function (string $output) {
$crawler = new Crawler($output);
$filter = $crawler->filterXPath(
'//div[@class="data-container"]//form[@name="frmaccount" and @data-action-route="account/saveEdit"]|//div[@class="item-actions"]//button'
)->extract(['id']);
return !empty($output) && count($filter) === 3;
}
);
$container = $this->buildContainer(
$definitions,
$this->buildRequest('get', 'index.php', ['r' => 'account/edit/' . self::$faker->randomNumber(3)])
);
$this->runApp($container);
}
protected function getDatabaseReturn(): callable
{
return function (QueryData $queryData): QueryResult {
if ($queryData->getMapClassName() === AccountView::class) {
return new QueryResult([AccountDataGenerator::factory()->buildAccountDataView()]);
}
return new QueryResult();
};
}
}