feat: Show warning message when removing last sharee that has access to credentials (no-changelog) (#4811)

* feat: add custom message when removing last credential accessor

* chore: remove unused imports

* chore: undo config schema changes

* fix: remove hash from interface
This commit is contained in:
Alex Grozav 2022-12-07 14:49:55 +02:00 committed by GitHub
parent c60e883640
commit 1fc17b5d81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 4 deletions

View file

@ -37,7 +37,6 @@ import {
NodeParameterValueType, NodeParameterValueType,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { FAKE_DOOR_FEATURES } from './constants'; import { FAKE_DOOR_FEATURES } from './constants';
import {ICredentialsDb} from "n8n";
export * from 'n8n-design-system/src/types'; export * from 'n8n-design-system/src/types';
@ -314,7 +313,7 @@ export interface IWorkflowDb {
sharedWith?: Array<Partial<IUser>>; sharedWith?: Array<Partial<IUser>>;
ownedBy?: Partial<IUser>; ownedBy?: Partial<IUser>;
versionId: string; versionId: string;
usedCredentials?: Array<Partial<ICredentialsDb>>; usedCredentials?: Array<Partial<ICredentialsResponse>>;
} }
// Identical to cli.Interfaces.ts // Identical to cli.Interfaces.ts

View file

@ -232,10 +232,45 @@ export default mixins(
const user = this.usersStore.getUserById(userId)!; const user = this.usersStore.getUserById(userId)!;
const isNewSharee = !(this.workflow.sharedWith || []).find((sharee) => sharee.id === userId); const isNewSharee = !(this.workflow.sharedWith || []).find((sharee) => sharee.id === userId);
const isLastUserWithAccessToCredentialsById = (this.workflow.usedCredentials || [])
.reduce<Record<string, boolean>>((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; let confirm = true;
if (!isNewSharee) { if (!isNewSharee) {
confirm = await this.confirmMessage( 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 }, interpolate: { name: user.fullName as string, workflow: this.workflow.name },
}), }),
this.$locale.baseText('workflows.shareModal.list.delete.confirm.title', { interpolate: { name: user.fullName } }), this.$locale.baseText('workflows.shareModal.list.delete.confirm.title', { interpolate: { name: user.fullName } }),

View file

@ -1388,7 +1388,8 @@
"workflows.shareModal.select.placeholder": "Add people", "workflows.shareModal.select.placeholder": "Add people",
"workflows.shareModal.list.delete": "Remove access", "workflows.shareModal.list.delete": "Remove access",
"workflows.shareModal.list.delete.confirm.title": "Remove {name}'s access?", "workflows.shareModal.list.delete.confirm.title": "Remove {name}'s access?",
"workflows.shareModal.list.delete.confirm.message": "<strong>This might cause the workflow to stop working:</strong> 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": "<strong>This might cause the workflow to stop working:</strong> {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.confirmButtonText": "Remove access",
"workflows.shareModal.list.delete.confirm.cancelButtonText": "Cancel", "workflows.shareModal.list.delete.confirm.cancelButtonText": "Cancel",
"workflows.shareModal.onSave.success.title": "Workflow sharing settings have been saved", "workflows.shareModal.onSave.success.title": "Workflow sharing settings have been saved",