mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(editor): Optionally share credentials used by the workflow when moving the workflow between projects (#12524)
Co-authored-by: Danny Martini <danny@n8n.io>
This commit is contained in:
@@ -951,6 +951,57 @@ describe('PUT /credentials/:id/share', () => {
|
||||
expect(mailer.notifyCredentialsShared).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('should ignore sharing with owner project', async () => {
|
||||
// ARRANGE
|
||||
const project = await projectService.createTeamProject(owner, { name: 'Team Project' });
|
||||
const credential = await saveCredential(randomCredentialPayload(), { project });
|
||||
|
||||
// ACT
|
||||
const response = await authOwnerAgent
|
||||
.put(`/credentials/${credential.id}/share`)
|
||||
.send({ shareWithIds: [project.id] });
|
||||
|
||||
const sharedCredentials = await Container.get(SharedCredentialsRepository).find({
|
||||
where: { credentialsId: credential.id },
|
||||
});
|
||||
|
||||
// ASSERT
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
expect(sharedCredentials).toHaveLength(1);
|
||||
expect(sharedCredentials[0].projectId).toBe(project.id);
|
||||
expect(sharedCredentials[0].role).toBe('credential:owner');
|
||||
});
|
||||
|
||||
test('should ignore sharing with project that already has it shared', async () => {
|
||||
// ARRANGE
|
||||
const project = await projectService.createTeamProject(owner, { name: 'Team Project' });
|
||||
const credential = await saveCredential(randomCredentialPayload(), { project });
|
||||
|
||||
const project2 = await projectService.createTeamProject(owner, { name: 'Team Project 2' });
|
||||
await shareCredentialWithProjects(credential, [project2]);
|
||||
|
||||
// ACT
|
||||
const response = await authOwnerAgent
|
||||
.put(`/credentials/${credential.id}/share`)
|
||||
.send({ shareWithIds: [project2.id] });
|
||||
|
||||
const sharedCredentials = await Container.get(SharedCredentialsRepository).find({
|
||||
where: { credentialsId: credential.id },
|
||||
});
|
||||
|
||||
// ASSERT
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
expect(sharedCredentials).toHaveLength(2);
|
||||
expect(sharedCredentials).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ projectId: project.id, role: 'credential:owner' }),
|
||||
expect.objectContaining({ projectId: project2.id, role: 'credential:user' }),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
test('should respond 400 if invalid payload is provided', async () => {
|
||||
const savedCredential = await saveCredential(randomCredentialPayload(), { user: owner });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user