diff --git a/packages/editor-ui/src/Interface.ts b/packages/editor-ui/src/Interface.ts index e13b0e8f14..fc02855fc1 100644 --- a/packages/editor-ui/src/Interface.ts +++ b/packages/editor-ui/src/Interface.ts @@ -37,7 +37,6 @@ import { NodeParameterValueType, } from 'n8n-workflow'; import { FAKE_DOOR_FEATURES } from './constants'; -import {ICredentialsDb} from "n8n"; export * from 'n8n-design-system/src/types'; @@ -314,7 +313,7 @@ export interface IWorkflowDb { sharedWith?: Array>; ownedBy?: Partial; versionId: string; - usedCredentials?: Array>; + usedCredentials?: Array>; } // Identical to cli.Interfaces.ts diff --git a/packages/editor-ui/src/components/WorkflowShareModal.ee.vue b/packages/editor-ui/src/components/WorkflowShareModal.ee.vue index 51eb6a4a5c..ec5d983349 100644 --- a/packages/editor-ui/src/components/WorkflowShareModal.ee.vue +++ b/packages/editor-ui/src/components/WorkflowShareModal.ee.vue @@ -232,10 +232,45 @@ export default mixins( const user = this.usersStore.getUserById(userId)!; const isNewSharee = !(this.workflow.sharedWith || []).find((sharee) => sharee.id === userId); + const isLastUserWithAccessToCredentialsById = (this.workflow.usedCredentials || []) + .reduce>((acc, credential) => { + if (!credential.id || !credential.ownedBy || !credential.sharedWith || !this.workflow.sharedWith) { + return acc; + } + + // if is credential owner, and no credential sharees have access to workflow => NOT OK + // if is credential owner, and credential sharees have access to workflow => OK + + // if is credential sharee, and no credential sharees have access to workflow or owner does not have access to workflow => NOT OK + // if is credential sharee, and credential owner has access to workflow => OK + // if is credential sharee, and other credential sharees have access to workflow => OK + + let isLastUserWithAccess = false; + + const isCredentialOwner = credential.ownedBy.id === user.id; + const isCredentialSharee = !!credential.sharedWith.find((sharee) => sharee.id === user.id); + + if (isCredentialOwner) { + isLastUserWithAccess = !credential.sharedWith.some((sharee) => { + return this.workflow.sharedWith!.find((workflowSharee) => workflowSharee.id === sharee.id); + }); + } else if (isCredentialSharee) { + isLastUserWithAccess = !credential.sharedWith.some((sharee) => { + return this.workflow.sharedWith!.find((workflowSharee) => workflowSharee.id === sharee.id); + }) && !this.workflow.sharedWith!.find((workflowSharee) => workflowSharee.id === credential.ownedBy!.id); + } + + acc[credential.id] = isLastUserWithAccess; + + return acc; + }, {}); + + const isLastUserWithAccessToCredentials = Object.values(isLastUserWithAccessToCredentialsById).some((value) => value); + let confirm = true; if (!isNewSharee) { confirm = await this.confirmMessage( - this.$locale.baseText('workflows.shareModal.list.delete.confirm.message', { + this.$locale.baseText(`workflows.shareModal.list.delete.confirm.${isLastUserWithAccessToCredentials ? 'lastUserWithAccessToCredentials.' : ''}message`, { interpolate: { name: user.fullName as string, workflow: this.workflow.name }, }), this.$locale.baseText('workflows.shareModal.list.delete.confirm.title', { interpolate: { name: user.fullName } }), diff --git a/packages/editor-ui/src/plugins/i18n/locales/en.json b/packages/editor-ui/src/plugins/i18n/locales/en.json index 2113662426..d0ed0acbf9 100644 --- a/packages/editor-ui/src/plugins/i18n/locales/en.json +++ b/packages/editor-ui/src/plugins/i18n/locales/en.json @@ -1388,7 +1388,8 @@ "workflows.shareModal.select.placeholder": "Add people", "workflows.shareModal.list.delete": "Remove access", "workflows.shareModal.list.delete.confirm.title": "Remove {name}'s access?", - "workflows.shareModal.list.delete.confirm.message": "This might cause the workflow to stop working: if {name} is the only user with access to credentials used in this workflow, those credentials will also be removed from {workflow}.", + "workflows.shareModal.list.delete.confirm.message": "{name} will no longer have access to the workflow.", + "workflows.shareModal.list.delete.confirm.lastUserWithAccessToCredentials.message": "This might cause the workflow to stop working: {name} is the only user with access to credentials used in this workflow, those credentials will also be removed from {workflow}.", "workflows.shareModal.list.delete.confirm.confirmButtonText": "Remove access", "workflows.shareModal.list.delete.confirm.cancelButtonText": "Cancel", "workflows.shareModal.onSave.success.title": "Workflow sharing settings have been saved",