mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
feat: Show delete button based on workflow permissions (#4686)
This commit is contained in:
parent
6f8d0de55d
commit
4f64e26a83
|
@ -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,
|
||||
},
|
||||
] : []),
|
||||
];
|
||||
},
|
||||
},
|
||||
|
|
|
@ -55,8 +55,10 @@ export const parsePermissionsTable = (user: IUser | null, table: IPermissionsTab
|
|||
|
||||
export const getCredentialPermissions = (user: IUser | null, credential: ICredentialsResponse) => {
|
||||
const settingsStore = useSettingsStore();
|
||||
const isSharingEnabled = settingsStore.isEnterpriseFeatureEnabled(EnterpriseEditionFeature.Sharing);
|
||||
|
||||
const table: IPermissionsTable = [
|
||||
{ name: UserRole.ResourceOwner, test: () => !!(credential && credential.ownedBy && credential.ownedBy.id === user?.id) || !settingsStore.isEnterpriseFeatureEnabled(EnterpriseEditionFeature.Sharing) },
|
||||
{ name: UserRole.ResourceOwner, test: () => !!(credential && credential.ownedBy && credential.ownedBy.id === user?.id) || !isSharingEnabled },
|
||||
{ name: UserRole.ResourceReader, test: () => !!(credential && credential.sharedWith && credential.sharedWith.find((sharee) => sharee.id === user?.id)) },
|
||||
{ name: 'read', test: [UserRole.ResourceOwner, UserRole.InstanceOwner, UserRole.ResourceReader] },
|
||||
{ name: 'save', test: [UserRole.ResourceOwner, UserRole.InstanceOwner] },
|
||||
|
@ -73,10 +75,11 @@ export const getCredentialPermissions = (user: IUser | null, credential: ICreden
|
|||
|
||||
export const getWorkflowPermissions = (user: IUser | null, workflow: IWorkflowDb) => {
|
||||
const settingsStore = useSettingsStore();
|
||||
const isSharingEnabled = settingsStore.isEnterpriseFeatureEnabled(EnterpriseEditionFeature.WorkflowSharing);
|
||||
const isNewWorkflow = workflow.id === PLACEHOLDER_EMPTY_WORKFLOW_ID;
|
||||
|
||||
const table: IPermissionsTable = [
|
||||
{ name: UserRole.ResourceOwner, test: () => !!(isNewWorkflow || workflow && workflow.ownedBy && workflow.ownedBy.id === user?.id) || !settingsStore.isEnterpriseFeatureEnabled(EnterpriseEditionFeature.WorkflowSharing) },
|
||||
{ name: UserRole.ResourceOwner, test: () => !!(isNewWorkflow || workflow && workflow.ownedBy && workflow.ownedBy.id === user?.id) || !isSharingEnabled },
|
||||
{ name: UserRole.ResourceReader, test: () => !!(workflow && workflow.sharedWith && workflow.sharedWith.find((sharee) => sharee.id === user?.id)) },
|
||||
{ name: 'read', test: [UserRole.ResourceOwner, UserRole.InstanceOwner, UserRole.ResourceReader] },
|
||||
{ name: 'save', test: [UserRole.ResourceOwner, UserRole.InstanceOwner] },
|
||||
|
@ -85,7 +88,7 @@ export const getWorkflowPermissions = (user: IUser | null, workflow: IWorkflowDb
|
|||
{ name: 'updateSharing', test: [UserRole.ResourceOwner] },
|
||||
{ name: 'updateNodeAccess', test: [UserRole.ResourceOwner] },
|
||||
{ name: 'delete', test: [UserRole.ResourceOwner, UserRole.InstanceOwner] },
|
||||
{ name: 'use', test: [UserRole.ResourceOwner, UserRole.ResourceReader] },
|
||||
{ name: 'use', test: [UserRole.ResourceOwner, UserRole.InstanceOwner, UserRole.ResourceReader] },
|
||||
];
|
||||
|
||||
return parsePermissionsTable(user, table);
|
||||
|
|
Loading…
Reference in a new issue