Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide publish button for user without tagmanager_use_custom_templates capability #785

Merged
merged 10 commits into from
May 8, 2024
2 changes: 2 additions & 0 deletions API.php
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ public function createContainerVersion($idSite, $idContainer, $name, $descriptio
{
$name = $this->decodeQuotes($name);
$this->accessValidator->checkWriteCapability($idSite);
$this->accessValidator->checkUseCustomTemplatesCapability($idSite);
$this->containers->checkContainerExists($idSite, $idContainer);

if (empty($idContainerVersion)) {
Expand Down Expand Up @@ -1058,6 +1059,7 @@ public function updateContainerVersion($idSite, $idContainer, $idContainerVersio
{
$name = $this->decodeQuotes($name);
$this->accessValidator->checkWriteCapability($idSite);
$this->accessValidator->checkUseCustomTemplatesCapability($idSite);
araichyk marked this conversation as resolved.
Show resolved Hide resolved
$this->containers->checkContainerVersionExists($idSite, $idContainer, $idContainerVersion);

return $this->containers->updateContainerVersion($idSite, $idContainer, $idContainerVersion, $name, $description);
Expand Down
3 changes: 3 additions & 0 deletions Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ public function manageVariables()

public function manageVersions()
{
$idSite = Common::getRequestVar('idSite', null, 'int');
$this->accessValidator->checkWriteCapability($idSite);
$this->accessValidator->checkUseCustomTemplatesCapability($idSite);
$path = TagManager::getAbsolutePathToContainerDirectory();
Filechecks::dieIfDirectoriesNotWritable(array($path));
$versionsHelpText = $this->renderTemplate('helpContent', [
Expand Down
6 changes: 4 additions & 2 deletions Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public function configureTagManagerMenu(MenuTagManager $menu)
$menu->addItem($menuCategory, 'TagManager_Tags', $this->urlForAction('manageTags', $params), $orderId = 105);
$menu->addItem($menuCategory, 'TagManager_Triggers', $this->urlForAction('manageTriggers', $params), $orderId = 110);
$menu->addItem($menuCategory, 'TagManager_Variables', $this->urlForAction('manageVariables', $params), $orderId = 115);
$menu->addItem($menuCategory, 'TagManager_Versions', $this->urlForAction('manageVersions', $params), $orderId = 115);

$previewEnabled = false;
foreach ($container['releases'] as $release) {
Expand All @@ -119,7 +118,10 @@ public function configureTagManagerMenu(MenuTagManager $menu)
$menu->addItem($menuCategory, 'TagManager_EnablePreviewDebug', array(), $orderId = 130, false,'icon-bug', "tagManagerHelper.enablePreviewMode(" . json_encode($container['idcontainer']) . ")");
}

$menu->addItem($menuCategory, 'TagManager_Publish', array(), $orderId = 135, false, 'icon-rocket', "tagManagerHelper.editVersion(" . json_encode($container['idcontainer']) . ", 0, function () { window.location.reload(); })");
if ($this->accessValidator->hasUseCustomTemplatesCapability($idSite)) {
$menu->addItem($menuCategory, 'TagManager_Versions', $this->urlForAction('manageVersions', $params), $orderId = 115);
$menu->addItem($menuCategory, 'TagManager_Publish', array(), $orderId = 135, false, 'icon-rocket', "tagManagerHelper.editVersion(" . json_encode($container['idcontainer']) . ", 0, function () { window.location.reload(); })");
}
}
$menu->addItem($menuCategory, 'TagManager_InstallCode', $this->urlForAction('releases', $params), $orderId = 140, false,'icon-embed', "tagManagerHelper.showInstallCode(" . json_encode($container['idcontainer']) . ")");

Expand Down
28 changes: 0 additions & 28 deletions tests/UI/ContainerVersion_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,6 @@ describe("ContainerVersion", function () {
await capture.page(page, 'debug_version_enable');
});

it('should load versions page with some versions as view user', async function () {
permissions.setViewUser();
await page.goto(container1Base);
await capture.page(page, 'version_some_exist_view_user');
});

it('should load versions page with no versions as view user', async function () {
permissions.setViewUser();
await page.goto(container3Base);
await page.waitForSelector('.manageVersion', { visible: true });
await capture.selector(page, 'version_none_exist_view_user', '.manageVersion');
});

it('should be able to show import version screen', async function () {
await page.goto(container1Base);
await page.click('.importVersion');
Expand Down Expand Up @@ -273,19 +260,4 @@ describe("ContainerVersion", function () {
await page.waitForTimeout(200);
await capture.page(page, 'import_version_confirmed');
});

it('should show notice not possible to publish to live container and preselect alternative environment', async function () {
permissions.setWriteUser();
await page.goto(container1Base);
await page.click('.createNewVersion');
await page.waitForNetworkIdle();
await capture.page(page, 'no_publish_live_container_capability');
});

it('should show notice not possible to publish to live container and preselect alternative environment in selector', async function () {
permissions.setWriteUser();
await page.goto(container1Base);
await clickFirstRowTableAction('icon-rocket');
await capture.modal(page, 'no_publish_live_container_capability_selector');
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading