diff --git a/app/modules/web/Controllers/Helpers/Account/AccountActionsDto.php b/app/modules/web/Controllers/Helpers/Account/AccountActionsDto.php index cdb84952..b2bbb663 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountActionsDto.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountActionsDto.php @@ -44,9 +44,13 @@ final class AccountActionsDto */ private $accountParentId; /** - * @var bool + * @var int */ private $publicLinkId; + /** + * @var int + */ + private $publicLinkCreatorId; /** * AccountActionsDto constructor. @@ -103,7 +107,7 @@ final class AccountActionsDto } /** - * @return bool + * @return int */ public function getPublicLinkId() { @@ -111,10 +115,26 @@ final class AccountActionsDto } /** - * @param bool $publicLinkId + * @param int $publicLinkId */ - public function setPublicLinkId($publicLinkId) + public function setPublicLinkId(int $publicLinkId) { - $this->publicLinkId = (int)$publicLinkId; + $this->publicLinkId = $publicLinkId; + } + + /** + * @return int + */ + public function getPublicLinkCreatorId() + { + return $this->publicLinkCreatorId; + } + + /** + * @param int $publicLinkCreatorId + */ + public function setPublicLinkCreatorId(int $publicLinkCreatorId) + { + $this->publicLinkCreatorId = $publicLinkCreatorId; } } \ No newline at end of file diff --git a/app/modules/web/Controllers/Helpers/Account/AccountActionsHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountActionsHelper.php index 1429deda..82452612 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountActionsHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountActionsHelper.php @@ -73,12 +73,12 @@ final class AccountActionsHelper extends HelperBase /** * Set icons for view * - * @param \SP\Services\Account\AccountAcl $accountAcl - * @param AccountActionsDto $accountActionsDto + * @param AccountAcl $accountAcl + * @param AccountActionsDto $accountActionsDto * * @return DataGridAction[] */ - public function getActionsForAccount(\SP\Services\Account\AccountAcl $accountAcl, AccountActionsDto $accountActionsDto) + public function getActionsForAccount(AccountAcl $accountAcl, AccountActionsDto $accountActionsDto) { $actions = []; @@ -249,13 +249,15 @@ final class AccountActionsHelper extends HelperBase /** * Set icons for view * - * @param \SP\Services\Account\AccountAcl $accountAcl - * @param AccountActionsDto $accountActionsDto + * @param AccountAcl $accountAcl + * @param AccountActionsDto $accountActionsDto * * @return DataGridAction[] */ public function getActionsGrouppedForAccount(AccountAcl $accountAcl, AccountActionsDto $accountActionsDto) { + $userData = $this->context->getUserData(); + $actions = []; if ($accountAcl->isShowDelete()) { @@ -268,10 +270,30 @@ final class AccountActionsHelper extends HelperBase && $accountAcl->isShowLink() && $accountAcl->isShowViewPass() ) { - $action = $accountActionsDto->getPublicLinkId() ? $this->getPublicLinkRefreshAction() : $this->getPublicLinkAction(); - $itemId = $accountActionsDto->getPublicLinkId() ?: $accountActionsDto->getAccountId(); + $itemId = $accountActionsDto->getPublicLinkId(); - $actions[] = $action->addData('item-id', $itemId); + if ($itemId) { + $actionRefresh = $this->getPublicLinkRefreshAction(); + $actionRefresh->addData('item-id', $itemId); + $actionRefresh->addData('account-id', $accountActionsDto->getAccountId()); + + $actions[] = $actionRefresh; + + if ($userData->getIsAdminApp() + || $userData->getId() === $accountActionsDto->getPublicLinkCreatorId() + ) { + $actionDelete = $this->getPublicLinkDeleteAction(); + $actionDelete->addData('item-id', $itemId); + $actionDelete->addData('account-id', $accountActionsDto->getAccountId()); + + $actions[] = $actionDelete; + } + } else { + $action = $this->getPublicLinkAction(); + $action->addData('account-id', $accountActionsDto->getAccountId()); + + $actions[] = $action; + } } if ($accountAcl->isShowViewPass()) { @@ -342,6 +364,29 @@ final class AccountActionsHelper extends HelperBase return $action; } + /** + * @return DataGridAction + */ + public function getPublicLinkDeleteAction() + { + $icon = clone $this->icons->getIconPublicLink(); + $icon->setIcon('link_off'); + + $action = new DataGridAction(); + $action->setId(ActionsInterface::PUBLICLINK_DELETE); + $action->setName(__('Eliminar Enlace Público')); + $action->setTitle(__('Eliminar Enlace Público')); + $action->addClass('btn-action'); + $action->setIcon($icon); + $action->addData('action-route', Acl::getActionRoute(ActionsInterface::PUBLICLINK_DELETE)); + $action->addData('action-sk', $this->sk); + $action->addData('onclick', 'link/delete'); + $action->addData('action-next', Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW)); + $action->addAttribute('type', 'button'); + + return $action; + } + /** * @return DataGridAction */ diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php index 1b90b601..a6a6c0d8 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php @@ -168,6 +168,7 @@ final class AccountHelper extends HelperBase try { $publicLinkData = $this->publicLinkService->getHashForItem($this->accountId); $accountActionsDto->setPublicLinkId($publicLinkData->getId()); + $accountActionsDto->setPublicLinkCreatorId($publicLinkData->getUserId()); $this->view->assign('publicLinkUrl', PublicLinkService::getLinkForHash($publicLinkData->getHash())); $this->view->assign('publicLinkId', $publicLinkData->getId()); diff --git a/app/modules/web/Controllers/PublicLinkController.php b/app/modules/web/Controllers/PublicLinkController.php index 68ef748d..6cbbb51a 100644 --- a/app/modules/web/Controllers/PublicLinkController.php +++ b/app/modules/web/Controllers/PublicLinkController.php @@ -59,6 +59,9 @@ final class PublicLinkController extends ControllerBase implements CrudControlle /** * Search action * + * @return bool + * @throws \DI\DependencyException + * @throws \DI\NotFoundException * @throws \SP\Core\Exceptions\ConstraintException * @throws \SP\Core\Exceptions\QueryException */ @@ -79,6 +82,8 @@ final class PublicLinkController extends ControllerBase implements CrudControlle * getSearchGrid * * @return $this + * @throws \DI\DependencyException + * @throws \DI\NotFoundException * @throws \SP\Core\Exceptions\ConstraintException * @throws \SP\Core\Exceptions\QueryException */ diff --git a/lib/SP/Services/Install/Installer.php b/lib/SP/Services/Install/Installer.php index 8e301321..504ddbb0 100644 --- a/lib/SP/Services/Install/Installer.php +++ b/lib/SP/Services/Install/Installer.php @@ -57,7 +57,7 @@ final class Installer extends Service */ const VERSION = [3, 0, 0]; const VERSION_TEXT = '3.0-beta'; - const BUILD = 18100701; + const BUILD = 18100801; /** * @var DatabaseSetupInterface diff --git a/public/js/app-actions.js b/public/js/app-actions.js index 25027f93..f1d6c02f 100644 --- a/public/js/app-actions.js +++ b/public/js/app-actions.js @@ -1003,12 +1003,12 @@ sysPass.Actions = function (log) { log.info("link:save"); const request = function (notify) { - const itemId = $obj.data("item-id"); + const accountId = $obj.data("account-id"); const opts = sysPassApp.requests.getRequestOpts(); - if (itemId) { - opts.url = ajaxUrl.entrypoint + "?r=" + $obj.data("action-route") + "/" + itemId + "/" + notify; + if (accountId) { + opts.url = ajaxUrl.entrypoint + "?r=" + $obj.data("action-route") + "/" + accountId + "/" + notify; } else { opts.url = ajaxUrl.entrypoint + "?r=" + $obj.data("action-route"); opts.data = $obj.serialize(); @@ -1018,7 +1018,7 @@ sysPass.Actions = function (log) { sysPassApp.msg.out(json); if (json.status === 0) { - getContent({r: $obj.data("action-next") + "/" + itemId}); + getContent({r: $obj.data("action-next") + "/" + accountId}); } }); }; @@ -1045,6 +1045,42 @@ sysPass.Actions = function (log) { } }); }, + delete: function ($obj) { + log.info("link:delete"); + + const atext = "
" + sysPassApp.config.LANG[12] + "
'+sysPassApp.config.LANG[3]+"
'+sysPassApp.config.LANG[3]+"
'+sysPassApp.config.LANG[59]+"
'+sysPassApp.config.LANG[48]+ -"
'+sysPassApp.config.LANG[20]+"
'+sysPassApp.config.LANG[58]+"
'+sysPassApp.config.LANG[57]+"
'+sysPassApp.config.LANG[71]+"
'+sysPassApp.config.LANG[59]+"
'+sysPassApp.config.LANG[48]+ +"
'+sysPassApp.config.LANG[12]+"
'+sysPassApp.config.LANG[20]+"
'+sysPassApp.config.LANG[58]+"
'+sysPassApp.config.LANG[57]+"
'+sysPassApp.config.LANG[71]+"