feat: Show delete button based on workflow permissions (#4686)

This commit is contained in:
Alex Grozav
2022-11-22 13:40:20 +02:00
committed by GitHub
parent 6f8d0de55d
commit 4f64e26a83
2 changed files with 25 additions and 11 deletions

View File

@@ -113,7 +113,7 @@ import SaveButton from "@/components/SaveButton.vue";
import TagsDropdown from "@/components/TagsDropdown.vue";
import InlineTextEdit from "@/components/InlineTextEdit.vue";
import BreakpointsObserver from "@/components/BreakpointsObserver.vue";
import { IWorkflowDataUpdate, IWorkflowToShare } from "@/Interface";
import {IWorkflowDataUpdate, IWorkflowDb, IWorkflowToShare} from "@/Interface";
import { saveAs } from 'file-saver';
import { titleChange } from "../mixins/titleChange";
@@ -124,6 +124,8 @@ import { useSettingsStore } from "@/stores/settings";
import { useWorkflowsStore } from "@/stores/workflows";
import { useRootStore } from "@/stores/n8nRootStore";
import { useTagsStore } from "@/stores/tags";
import {getWorkflowPermissions, IPermissions} from "@/permissions";
import {useUsersStore} from "@/stores/users";
const hasChanged = (prev: string[], curr: string[]) => {
if (prev.length !== curr.length) {
@@ -164,6 +166,7 @@ export default mixins(workflowHelpers, titleChange).extend({
useSettingsStore,
useUIStore,
useWorkflowsStore,
useUsersStore,
),
isWorkflowActive(): boolean {
return this.workflowsStore.isWorkflowActive;
@@ -183,6 +186,9 @@ export default mixins(workflowHelpers, titleChange).extend({
isWorkflowSaving(): boolean {
return this.uiStore.isActionActive('workflowSaving');
},
workflow(): IWorkflowDb {
return this.workflowsStore.workflow;
},
currentWorkflowId(): string {
return this.workflowsStore.workflowId;
},
@@ -192,6 +198,9 @@ export default mixins(workflowHelpers, titleChange).extend({
onExecutionsTab(): boolean {
return [ VIEWS.EXECUTION_HOME.toString(), VIEWS.EXECUTIONS.toString(), VIEWS.EXECUTION_PREVIEW ].includes(this.$route.name || '');
},
workflowPermissions(): IPermissions {
return getWorkflowPermissions(this.usersStore.currentUser, this.workflow);
},
workflowMenuItems(): Array<{}> {
return [
{
@@ -219,13 +228,15 @@ export default mixins(workflowHelpers, titleChange).extend({
label: this.$locale.baseText('generic.settings'),
disabled: !this.onWorkflowPage || this.isNewWorkflow,
},
{
id: WORKFLOW_MENU_ACTIONS.DELETE,
label: this.$locale.baseText('menuActions.delete'),
disabled: !this.onWorkflowPage || this.isNewWorkflow,
customClass: this.$style.deleteItem,
divided: true,
},
...(this.workflowPermissions.delete ? [
{
id: WORKFLOW_MENU_ACTIONS.DELETE,
label: this.$locale.baseText('menuActions.delete'),
disabled: !this.onWorkflowPage || this.isNewWorkflow,
customClass: this.$style.deleteItem,
divided: true,
},
] : []),
];
},
},