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
4 changes: 3 additions & 1 deletion Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ 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_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
3 changes: 1 addition & 2 deletions tests/UI/ContainerVersion_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,9 @@ describe("ContainerVersion", function () {
await capture.page(page, 'import_version_confirmed');
});

it('should show notice not possible to publish to live container and preselect alternative environment', async function () {
it('should show notice not possible to create new version with no tagmanager_use_custom_templates', async function () {
permissions.setWriteUser();
await page.goto(container1Base);
await page.click('.createNewVersion');
await page.waitForNetworkIdle();
await capture.page(page, 'no_publish_live_container_capability');
});
Expand Down
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.
507 changes: 275 additions & 232 deletions vue/dist/TagManager.umd.js

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions vue/dist/TagManager.umd.min.js

Large diffs are not rendered by default.

29 changes: 19 additions & 10 deletions vue/src/Tag/TagEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,14 @@ export default defineComponent({

setTimeout(() => {
const createdX = translate('TagManager_CreatedX', translate('TagManager_Tag'));
const wantToRedeploy = translate(
'TagManager_WantToDeployThisChangeCreateVersion',
'<a class="createNewVersionLink">',
'</a>',
);
let wantToRedeploy = '';
if (this.hasPublishCapability()) {
wantToRedeploy = translate(
'TagManager_WantToDeployThisChangeCreateVersion',
'<a class="createNewVersionLink">',
'</a>',
);
}

this.showNotification(`${createdX} ${wantToRedeploy}`, 'success');
}, 200);
Expand Down Expand Up @@ -750,11 +753,14 @@ export default defineComponent({
});

const updatedAt = translate('TagManager_UpdatedX', translate('TagManager_Tag'));
const wantToDeploy = translate(
'TagManager_WantToDeployThisChangeCreateVersion',
'<a class="createNewVersionLink">',
'</a>',
);
let wantToDeploy = '';
if (this.hasPublishCapability()) {
wantToDeploy = translate(
'TagManager_WantToDeployThisChangeCreateVersion',
'<a class="createNewVersionLink">',
'</a>',
);
}

this.showNotification(`${updatedAt} ${wantToDeploy}`, 'success');
}).finally(() => {
Expand All @@ -775,6 +781,9 @@ export default defineComponent({

return true;
},
hasPublishCapability() {
return Matomo.hasUserCapability('tagmanager_write') && Matomo.hasUserCapability('tagmanager_use_custom_templates');
},
},
computed: {
availableFireLimits() {
Expand Down
29 changes: 19 additions & 10 deletions vue/src/Trigger/TriggerEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,14 @@ export default defineComponent({

setTimeout(() => {
const createdX = translate('TagManager_CreatedX', translate('TagManager_Trigger'));
const wantToRedeploy = translate(
'TagManager_WantToDeployThisChangeCreateVersion',
'<a href="" class="createNewVersionLink">',
'</a>',
);
let wantToRedeploy = '';
if (this.hasPublishCapability()) {
wantToRedeploy = translate(
'TagManager_WantToDeployThisChangeCreateVersion',
'<a class="createNewVersionLink">',
'</a>',
);
}

this.showNotification(`${createdX} ${wantToRedeploy}`, 'success');
}, 200);
Expand Down Expand Up @@ -611,11 +614,14 @@ export default defineComponent({
});

const updatedAt = translate('TagManager_UpdatedX', translate('TagManager_Trigger'));
const wantToDeploy = translate(
'TagManager_WantToDeployThisChangeCreateVersion',
'<a href="" class="createNewVersionLink">',
'</a>',
);
let wantToDeploy = '';
if (this.hasPublishCapability()) {
wantToDeploy = translate(
'TagManager_WantToDeployThisChangeCreateVersion',
'<a class="createNewVersionLink">',
'</a>',
);
}

this.showNotification(`${updatedAt} ${wantToDeploy}`, 'success');
}).finally(() => {
Expand All @@ -632,6 +638,9 @@ export default defineComponent({
}
return { comparison: 'equals', actual, expected: '' };
},
hasPublishCapability() {
return Matomo.hasUserCapability('tagmanager_write') && Matomo.hasUserCapability('tagmanager_use_custom_templates');
},
},
computed: {
isLoading() {
Expand Down
29 changes: 19 additions & 10 deletions vue/src/Variable/VariableEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,14 @@ export default defineComponent({

setTimeout(() => {
const createdX = translate('TagManager_CreatedX', translate('TagManager_Variable'));
const wantToRedeploy = translate(
'TagManager_WantToDeployThisChangeCreateVersion',
'<a class="createNewVersionLink">',
'</a>',
);
let wantToRedeploy = '';
if (this.hasPublishCapability()) {
wantToRedeploy = translate(
'TagManager_WantToDeployThisChangeCreateVersion',
'<a class="createNewVersionLink">',
'</a>',
);
}

this.showNotification(`${createdX} ${wantToRedeploy}`, 'success');
}, 200);
Expand Down Expand Up @@ -614,11 +617,14 @@ export default defineComponent({
});

const updatedAt = translate('TagManager_UpdatedX', translate('TagManager_Variable'));
const wantToDeploy = translate(
'TagManager_WantToDeployThisChangeCreateVersion',
'<a class="createNewVersionLink">',
'</a>',
);
let wantToDeploy = '';
if (this.hasPublishCapability()) {
wantToDeploy = translate(
'TagManager_WantToDeployThisChangeCreateVersion',
'<a class="createNewVersionLink">',
'</a>',
);
}

this.showNotification(`${updatedAt} ${wantToDeploy}`, 'success');
}).finally(() => {
Expand All @@ -632,6 +638,9 @@ export default defineComponent({
}
return true;
},
hasPublishCapability() {
return Matomo.hasUserCapability('tagmanager_write') && Matomo.hasUserCapability('tagmanager_use_custom_templates');
},
},
computed: {
typeInlineHelp() {
Expand Down
16 changes: 11 additions & 5 deletions vue/src/Version/VersionEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,14 @@ export default defineComponent({

setTimeout(() => {
const createdX = translate('TagManager_CreatedX', translate('TagManager_Version'));
const wantToRedeploy = translate(
'TagManager_WantToDeployThisChangeCreateVersion',
'<a class="createNewVersionLink">',
'</a>',
);
let wantToRedeploy = '';
if (this.hasPublishCapability()) {
wantToRedeploy = translate(
'TagManager_WantToDeployThisChangeCreateVersion',
'<a class="createNewVersionLink">',
'</a>',
);
}

this.showNotification(`${createdX} ${wantToRedeploy}`, 'success');
}, 200);
Expand Down Expand Up @@ -471,6 +474,9 @@ export default defineComponent({

return true;
},
hasPublishCapability() {
return Matomo.hasUserCapability('tagmanager_write') && Matomo.hasUserCapability('tagmanager_use_custom_templates');
},
},
computed: {
create() {
Expand Down
7 changes: 5 additions & 2 deletions vue/src/Version/VersionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
{{ translate('TagManager_NoVersionsFound') }}
<a
class="createContainerVersionNow"
v-show="hasWriteAccess"
v-show="hasWriteAccess && hasCustomTemplatesCapability"
@click="createVersion()"
>
{{ translate('TagManager_CreateNewVersionNow') }}
Expand Down Expand Up @@ -120,7 +120,7 @@
<div class="tableActionBar">
<a
class="createNewVersion"
v-show="hasWriteAccess"
v-show="hasWriteAccess && hasCustomTemplatesCapability"
@click="createVersion()"
>
<span class="icon-add">&nbsp;</span>{{ translate('TagManager_CreateNewVersion') }}
Expand Down Expand Up @@ -382,6 +382,9 @@ export default defineComponent({
hasWriteAccess() {
return Matomo.hasUserCapability('tagmanager_write');
},
hasCustomTemplatesCapability() {
return Matomo.hasUserCapability('tagmanager_use_custom_templates');
},
canPublishToLive() {
return Matomo.hasUserCapability('tagmanager_publish_live_container');
},
Expand Down
Loading