mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
fix(editor): Remove unknown credentials on pasting workflow (#7582)
https://linear.app/n8n/issue/PAY-881
This commit is contained in:
parent
81f43805aa
commit
d633753687
|
@ -34,10 +34,10 @@ describe('Canvas Node Manipulation and Navigation', () => {
|
|||
WorkflowPage.actions.addNodeToCanvas(SWITCH_NODE_NAME, true, true);
|
||||
|
||||
for (let i = 0; i < desiredOutputs; i++) {
|
||||
cy.contains('Add Routing Rule').click()
|
||||
cy.contains('Add Routing Rule').click();
|
||||
}
|
||||
|
||||
NDVDialog.actions.close()
|
||||
NDVDialog.actions.close();
|
||||
for (let i = 0; i < desiredOutputs; i++) {
|
||||
WorkflowPage.getters.canvasNodePlusEndpointByName(SWITCH_NODE_NAME, i).click({ force: true });
|
||||
WorkflowPage.getters.nodeCreatorSearchBar().should('be.visible');
|
||||
|
@ -51,7 +51,9 @@ describe('Canvas Node Manipulation and Navigation', () => {
|
|||
cy.reload();
|
||||
cy.waitForLoad();
|
||||
// Make sure outputless switch was connected correctly
|
||||
cy.get(`[data-target-node="${SWITCH_NODE_NAME}1"][data-source-node="${EDIT_FIELDS_SET_NODE_NAME}3"]`).should('be.visible');
|
||||
cy.get(
|
||||
`[data-target-node="${SWITCH_NODE_NAME}1"][data-source-node="${EDIT_FIELDS_SET_NODE_NAME}3"]`,
|
||||
).should('be.visible');
|
||||
// Make sure all connections are there after reload
|
||||
for (let i = 0; i < desiredOutputs; i++) {
|
||||
const setName = `${EDIT_FIELDS_SET_NODE_NAME}${i > 0 ? i : ''}`;
|
||||
|
@ -179,7 +181,7 @@ describe('Canvas Node Manipulation and Navigation', () => {
|
|||
.canvasNodes()
|
||||
.last()
|
||||
.should('have.css', 'left', '740px')
|
||||
.should('have.css', 'top', '320px')
|
||||
.should('have.css', 'top', '320px');
|
||||
});
|
||||
|
||||
it('should zoom in', () => {
|
||||
|
@ -350,5 +352,17 @@ describe('Canvas Node Manipulation and Navigation', () => {
|
|||
cy.waitForLoad();
|
||||
WorkflowPage.getters.canvasNodes().should('have.length', 2);
|
||||
cy.get('.rect-input-endpoint.jtk-endpoint-connected').should('have.length', 1);
|
||||
})
|
||||
});
|
||||
|
||||
it('should remove unknown credentials on pasting workflow', () => {
|
||||
cy.fixture('workflow-with-unknown-credentials.json').then((data) => {
|
||||
cy.get('body').paste(JSON.stringify(data));
|
||||
|
||||
WorkflowPage.getters.canvasNodes().should('have.have.length', 2);
|
||||
|
||||
WorkflowPage.actions.openNode('n8n');
|
||||
cy.get('[class*=hasIssues]').should('have.length', 1);
|
||||
NDVDialog.actions.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
52
cypress/fixtures/workflow-with-unknown-credentials.json
Normal file
52
cypress/fixtures/workflow-with-unknown-credentials.json
Normal file
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"meta": {
|
||||
"instanceId": "123"
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"parameters": {
|
||||
"resource": "credential",
|
||||
"name": "123",
|
||||
"credentialTypeName": "123"
|
||||
},
|
||||
"id": "a01f79f6-e8c3-44c5-be5e-4bc482e23172",
|
||||
"name": "n8n",
|
||||
"type": "n8n-nodes-base.n8n",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
540,
|
||||
240
|
||||
],
|
||||
"credentials": {
|
||||
"n8nApi": {
|
||||
"id": "10",
|
||||
"name": "n8n account"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {},
|
||||
"id": "acdd1bdc-c642-4ea6-ad67-f4201b640cfa",
|
||||
"name": "When clicking \"Execute Workflow\"",
|
||||
"type": "n8n-nodes-base.manualTrigger",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
300,
|
||||
240
|
||||
]
|
||||
}
|
||||
],
|
||||
"connections": {
|
||||
"When clicking \"Execute Workflow\"": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "n8n",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1677,6 +1677,8 @@ export default defineComponent({
|
|||
});
|
||||
}
|
||||
|
||||
this.removeUnknownCredentials(workflowData);
|
||||
|
||||
const currInstanceId = this.rootStore.instanceId;
|
||||
|
||||
const nodeGraph = JSON.stringify(
|
||||
|
@ -1756,6 +1758,23 @@ export default defineComponent({
|
|||
this.showError(error, this.$locale.baseText('nodeView.showError.importWorkflowData.title'));
|
||||
}
|
||||
},
|
||||
|
||||
removeUnknownCredentials(workflow: IWorkflowToShare) {
|
||||
if (!workflow?.nodes) return;
|
||||
|
||||
for (const node of workflow.nodes) {
|
||||
if (!node.credentials) continue;
|
||||
|
||||
for (const [name, credential] of Object.entries(node.credentials)) {
|
||||
if (credential.id === null) continue;
|
||||
|
||||
if (!this.credentialsStore.getCredentialById(credential.id)) {
|
||||
delete node.credentials[name];
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onDragOver(event: DragEvent) {
|
||||
event.preventDefault();
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue