mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
fix(editor): Prevent node renaming to restricted JS method names (#16270)
This commit is contained in:
@@ -7,7 +7,7 @@ import type {
|
||||
INodeConnections,
|
||||
WorkflowExecuteMode,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionTypes, NodeHelpers } from 'n8n-workflow';
|
||||
import { NodeConnectionTypes, NodeHelpers, UserError } from 'n8n-workflow';
|
||||
import { useCanvasOperations } from '@/composables/useCanvasOperations';
|
||||
import type { CanvasConnection, CanvasNode } from '@/types';
|
||||
import { CanvasConnectionMode } from '@/types';
|
||||
@@ -1041,6 +1041,35 @@ describe('useCanvasOperations', () => {
|
||||
|
||||
expect(ndvStore.activeNodeName).toBe(oldName);
|
||||
});
|
||||
|
||||
it('should show error toast when renameNode throws an error', async () => {
|
||||
const workflowsStore = mockedStore(useWorkflowsStore);
|
||||
const ndvStore = mockedStore(useNDVStore);
|
||||
const toast = useToast();
|
||||
const oldName = 'Old Node';
|
||||
const newName = 'New Node';
|
||||
const errorMessage = 'Node name already exists';
|
||||
const errorDescription = 'Please choose a different name';
|
||||
|
||||
const workflowObject = createTestWorkflowObject();
|
||||
workflowObject.renameNode = vi.fn().mockImplementation(() => {
|
||||
const error = new UserError(errorMessage, { description: errorDescription });
|
||||
throw error;
|
||||
});
|
||||
workflowsStore.getCurrentWorkflow.mockReturnValue(workflowObject);
|
||||
workflowsStore.getNodeByName = vi.fn().mockReturnValue({ name: oldName });
|
||||
ndvStore.activeNodeName = oldName;
|
||||
|
||||
const { renameNode } = useCanvasOperations();
|
||||
await renameNode(oldName, newName);
|
||||
|
||||
expect(workflowObject.renameNode).toHaveBeenCalledWith(oldName, newName);
|
||||
expect(toast.showMessage).toHaveBeenCalledWith({
|
||||
type: 'error',
|
||||
title: errorMessage,
|
||||
message: errorDescription,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('revertRenameNode', () => {
|
||||
|
||||
@@ -301,7 +301,16 @@ export function useCanvasOperations() {
|
||||
|
||||
// Rename the node and update the connections
|
||||
const workflow = workflowsStore.getCurrentWorkflow(true);
|
||||
workflow.renameNode(currentName, newName);
|
||||
try {
|
||||
workflow.renameNode(currentName, newName);
|
||||
} catch (error) {
|
||||
toast.showMessage({
|
||||
type: 'error',
|
||||
title: error.message,
|
||||
message: error.description,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (trackHistory) {
|
||||
historyStore.pushCommandToUndo(new RenameNodeCommand(currentName, newName, Date.now()));
|
||||
|
||||
Reference in New Issue
Block a user