fix(core): Add optional context parameter to track creation source for workflows, credentials, and projects (#18736)

Co-authored-by: r00gm <raul00gm@gmail.com>
This commit is contained in:
Csaba Tuncsik
2025-08-27 10:50:53 +02:00
committed by GitHub
parent e665cbf278
commit 98bde4f478
20 changed files with 173 additions and 22 deletions

View File

@@ -822,6 +822,25 @@ describe('POST /credentials', () => {
expect(sharedCredential.credentials.name).toBe(payload.name);
});
test('should create cred with uiContext parameter', async () => {
const payload = { ...randomCredentialPayload(), uiContext: 'credentials_list' };
const response = await authMemberAgent.post('/credentials').send(payload);
expect(response.statusCode).toBe(200);
const { id, name, type } = response.body.data;
expect(name).toBe(payload.name);
expect(type).toBe(payload.type);
const credential = await getCredentialById(id);
a.ok(credential);
expect(credential.name).toBe(payload.name);
expect(credential.type).toBe(payload.type);
});
test('should fail with invalid inputs', async () => {
for (const invalidPayload of INVALID_PAYLOADS) {
const response = await authOwnerAgent.post('/credentials').send(invalidPayload);

View File

@@ -398,6 +398,23 @@ describe('POST /projects/', () => {
}
});
test('should create a team project with context parameter', async () => {
const ownerUser = await createOwner();
const ownerAgent = testServer.authAgentFor(ownerUser);
const resp = await ownerAgent.post('/projects/').send({
name: 'Test Team Project with Context',
uiContext: 'universal_button',
});
expect(resp.status).toBe(200);
const respProject = resp.body.data as Project;
expect(respProject.name).toEqual('Test Team Project with Context');
expect(async () => {
await findProject(respProject.id);
}).not.toThrow();
expect(resp.body.data.role).toBe('project:admin');
});
test('should allow to create a team projects if below the quota', async () => {
testServer.license.setQuota('quota:maxTeamProjects', 1);
const ownerUser = await createOwner();

View File

@@ -145,6 +145,38 @@ describe('POST /workflows', () => {
);
});
test('should create workflow with uiContext parameter', async () => {
const payload = {
name: 'testing with context',
nodes: [
{
id: 'uuid-1234',
parameters: {},
name: 'Start',
type: 'n8n-nodes-base.start',
typeVersion: 1,
position: [240, 300],
},
],
connections: {},
staticData: null,
settings: {},
active: false,
uiContext: 'workflow_list',
};
const response = await authMemberAgent.post('/workflows').send(payload);
expect(response.statusCode).toBe(200);
const {
data: { id, name },
} = response.body;
expect(id).toBeDefined();
expect(name).toBe('testing with context');
});
test('should create workflow history version when licensed', async () => {
license.enable('feat:workflowHistory');
const payload = {