2023-11-08 07:29:39 -08:00
|
|
|
import Container from 'typedi';
|
2022-11-09 06:25:00 -08:00
|
|
|
import { v4 as uuid } from 'uuid';
|
2024-06-03 07:57:04 -07:00
|
|
|
import { ApplicationError, WorkflowActivationError, type INode } from 'n8n-workflow';
|
2023-03-17 09:24:05 -07:00
|
|
|
|
2024-05-31 00:40:03 -07:00
|
|
|
import config from '@/config';
|
2024-08-27 07:44:32 -07:00
|
|
|
import type { Project } from '@/databases/entities/project';
|
2024-08-27 08:24:20 -07:00
|
|
|
import { ProjectRepository } from '@/databases/repositories/project.repository';
|
2024-08-27 07:44:32 -07:00
|
|
|
import type { User } from '@/databases/entities/User';
|
2024-08-27 08:24:20 -07:00
|
|
|
import { WorkflowHistoryRepository } from '@/databases/repositories/workflow-history.repository';
|
2024-08-22 02:10:37 -07:00
|
|
|
import { ActiveWorkflowManager } from '@/active-workflow-manager';
|
|
|
|
import { License } from '@/license';
|
|
|
|
import { UserManagementMailer } from '@/user-management/email';
|
2024-05-31 00:40:03 -07:00
|
|
|
import type { WorkflowWithSharingsMetaDataAndCredentials } from '@/workflows/workflows.types';
|
2024-01-17 01:16:13 -08:00
|
|
|
|
|
|
|
import { mockInstance } from '../../shared/mocking';
|
|
|
|
import * as utils from '../shared/utils/';
|
2024-08-28 04:59:27 -07:00
|
|
|
import * as testDb from '../shared/test-db';
|
2024-01-17 01:16:13 -08:00
|
|
|
import type { SaveCredentialFunction } from '../shared/types';
|
|
|
|
import { makeWorkflow } from '../shared/utils/';
|
|
|
|
import { randomCredentialPayload } from '../shared/random';
|
|
|
|
import { affixRoleToSaveCredential, shareCredentialWithUsers } from '../shared/db/credentials';
|
2024-06-03 07:57:04 -07:00
|
|
|
import { createAdmin, createOwner, createUser, createUserShell } from '../shared/db/users';
|
2024-01-17 01:16:13 -08:00
|
|
|
import { createWorkflow, getWorkflowSharing, shareWorkflowWithUsers } from '../shared/db/workflows';
|
2024-05-17 01:53:15 -07:00
|
|
|
import { createTag } from '../shared/db/tags';
|
2024-05-31 00:40:03 -07:00
|
|
|
import type { SuperAgentTest } from '../shared/types';
|
2024-06-03 07:57:04 -07:00
|
|
|
import { createTeamProject, linkUserToProject } from '../shared/db/projects';
|
|
|
|
import { WorkflowRepository } from '@/databases/repositories/workflow.repository';
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
let owner: User;
|
2024-06-03 07:57:04 -07:00
|
|
|
let admin: User;
|
2024-05-17 01:53:15 -07:00
|
|
|
let ownerPersonalProject: Project;
|
2023-03-17 09:24:05 -07:00
|
|
|
let member: User;
|
2024-05-17 01:53:15 -07:00
|
|
|
let memberPersonalProject: Project;
|
2023-03-17 09:24:05 -07:00
|
|
|
let anotherMember: User;
|
2024-05-17 01:53:15 -07:00
|
|
|
let anotherMemberPersonalProject: Project;
|
2023-03-17 09:24:05 -07:00
|
|
|
let authOwnerAgent: SuperAgentTest;
|
|
|
|
let authMemberAgent: SuperAgentTest;
|
|
|
|
let authAnotherMemberAgent: SuperAgentTest;
|
2022-10-13 02:55:58 -07:00
|
|
|
let saveCredential: SaveCredentialFunction;
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
let projectRepository: ProjectRepository;
|
2024-06-03 07:57:04 -07:00
|
|
|
let workflowRepository: WorkflowRepository;
|
2024-05-17 01:53:15 -07:00
|
|
|
|
2024-05-06 08:54:05 -07:00
|
|
|
const activeWorkflowManager = mockInstance(ActiveWorkflowManager);
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-01-23 04:58:31 -08:00
|
|
|
const sharingSpy = jest.spyOn(License.prototype, 'isSharingEnabled').mockReturnValue(true);
|
2023-07-13 01:14:48 -07:00
|
|
|
const testServer = utils.setupTestServer({
|
|
|
|
endpointGroups: ['workflows'],
|
2024-06-03 07:57:04 -07:00
|
|
|
enabledFeatures: ['feat:sharing', 'feat:advancedPermissions'],
|
2023-07-13 01:14:48 -07:00
|
|
|
});
|
2023-11-30 00:23:09 -08:00
|
|
|
const license = testServer.license;
|
2024-01-23 03:03:59 -08:00
|
|
|
const mailer = mockInstance(UserManagementMailer);
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2023-07-13 01:14:48 -07:00
|
|
|
beforeAll(async () => {
|
2024-05-17 01:53:15 -07:00
|
|
|
projectRepository = Container.get(ProjectRepository);
|
2024-06-03 07:57:04 -07:00
|
|
|
workflowRepository = Container.get(WorkflowRepository);
|
2024-05-17 01:53:15 -07:00
|
|
|
|
2024-06-03 07:57:04 -07:00
|
|
|
owner = await createOwner();
|
|
|
|
admin = await createAdmin();
|
2024-05-17 01:53:15 -07:00
|
|
|
ownerPersonalProject = await projectRepository.getPersonalProjectForUserOrFail(owner.id);
|
2024-01-24 04:38:57 -08:00
|
|
|
member = await createUser({ role: 'global:member' });
|
2024-05-17 01:53:15 -07:00
|
|
|
memberPersonalProject = await projectRepository.getPersonalProjectForUserOrFail(member.id);
|
2024-01-24 04:38:57 -08:00
|
|
|
anotherMember = await createUser({ role: 'global:member' });
|
2024-05-17 01:53:15 -07:00
|
|
|
anotherMemberPersonalProject = await projectRepository.getPersonalProjectForUserOrFail(
|
|
|
|
anotherMember.id,
|
|
|
|
);
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2023-07-13 01:14:48 -07:00
|
|
|
authOwnerAgent = testServer.authAgentFor(owner);
|
|
|
|
authMemberAgent = testServer.authAgentFor(member);
|
|
|
|
authAnotherMemberAgent = testServer.authAgentFor(anotherMember);
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2024-01-24 04:38:57 -08:00
|
|
|
saveCredential = affixRoleToSaveCredential('credential:owner');
|
2022-11-11 02:14:45 -08:00
|
|
|
|
2022-10-31 02:35:24 -07:00
|
|
|
await utils.initNodeTypes();
|
2022-10-11 05:55:05 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
2024-05-06 08:54:05 -07:00
|
|
|
activeWorkflowManager.add.mockReset();
|
|
|
|
activeWorkflowManager.remove.mockReset();
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
await testDb.truncate(['Workflow', 'SharedWorkflow', 'WorkflowHistory', 'Tag']);
|
2022-10-11 05:55:05 -07:00
|
|
|
});
|
|
|
|
|
2024-01-23 03:03:59 -08:00
|
|
|
afterEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
describe('router should switch based on flag', () => {
|
|
|
|
let savedWorkflowId: string;
|
2022-11-11 02:14:45 -08:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
beforeEach(async () => {
|
|
|
|
const createWorkflowResponse = await authOwnerAgent.post('/workflows').send(makeWorkflow());
|
|
|
|
savedWorkflowId = createWorkflowResponse.body.data.id;
|
|
|
|
});
|
2022-11-11 02:14:45 -08:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('when sharing is disabled', async () => {
|
|
|
|
sharingSpy.mockReturnValueOnce(false);
|
2022-11-11 02:14:45 -08:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
await authOwnerAgent
|
|
|
|
.put(`/workflows/${savedWorkflowId}/share`)
|
2024-05-17 01:53:15 -07:00
|
|
|
.send({ shareWithIds: [memberPersonalProject.id] })
|
2023-03-17 09:24:05 -07:00
|
|
|
.expect(404);
|
|
|
|
});
|
2022-11-11 02:14:45 -08:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
test('when sharing is enabled', async () => {
|
|
|
|
await authOwnerAgent
|
|
|
|
.put(`/workflows/${savedWorkflowId}/share`)
|
2024-05-17 01:53:15 -07:00
|
|
|
.send({ shareWithIds: [memberPersonalProject.id] })
|
2023-03-17 09:24:05 -07:00
|
|
|
.expect(200);
|
|
|
|
});
|
2022-11-11 02:14:45 -08:00
|
|
|
});
|
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
describe('PUT /workflows/:workflowId/share', () => {
|
|
|
|
test('should save sharing with new users', async () => {
|
2022-10-11 07:40:39 -07:00
|
|
|
const workflow = await createWorkflow({}, owner);
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authOwnerAgent
|
2022-10-11 07:40:39 -07:00
|
|
|
.put(`/workflows/${workflow.id}/share`)
|
2024-05-17 01:53:15 -07:00
|
|
|
.send({ shareWithIds: [memberPersonalProject.id] });
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2022-10-11 07:40:39 -07:00
|
|
|
expect(response.statusCode).toBe(200);
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
const sharedWorkflows = await getWorkflowSharing(workflow);
|
2022-10-11 07:40:39 -07:00
|
|
|
expect(sharedWorkflows).toHaveLength(2);
|
2024-01-23 03:03:59 -08:00
|
|
|
expect(mailer.notifyWorkflowShared).toHaveBeenCalledTimes(1);
|
2024-05-17 01:53:15 -07:00
|
|
|
expect(mailer.notifyWorkflowShared).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
newShareeIds: [member.id],
|
|
|
|
sharer: expect.objectContaining({ id: owner.id }),
|
|
|
|
workflow: expect.objectContaining({ id: workflow.id }),
|
|
|
|
}),
|
|
|
|
);
|
2022-10-11 07:40:39 -07:00
|
|
|
});
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
test('should succeed when sharing with invalid user-id', async () => {
|
2022-10-11 07:40:39 -07:00
|
|
|
const workflow = await createWorkflow({}, owner);
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authOwnerAgent
|
2022-10-11 07:40:39 -07:00
|
|
|
.put(`/workflows/${workflow.id}/share`)
|
|
|
|
.send({ shareWithIds: [uuid()] });
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2022-10-11 07:40:39 -07:00
|
|
|
expect(response.statusCode).toBe(200);
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
const sharedWorkflows = await getWorkflowSharing(workflow);
|
2022-10-11 07:40:39 -07:00
|
|
|
expect(sharedWorkflows).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
test('should allow sharing with pending users', async () => {
|
2024-05-17 01:53:15 -07:00
|
|
|
const workflow = await createWorkflow({}, owner);
|
|
|
|
const memberShell = await createUserShell('global:member');
|
|
|
|
const memberShellPersonalProject = await projectRepository.getPersonalProjectForUserOrFail(
|
|
|
|
memberShell.id,
|
|
|
|
);
|
|
|
|
|
|
|
|
const response = await authOwnerAgent
|
|
|
|
.put(`/workflows/${workflow.id}/share`)
|
|
|
|
.send({ shareWithIds: [memberShellPersonalProject.id] });
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
|
|
|
|
const sharedWorkflows = await getWorkflowSharing(workflow);
|
|
|
|
expect(sharedWorkflows).toHaveLength(2);
|
|
|
|
expect(mailer.notifyWorkflowShared).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
test('should allow sharing with multiple users', async () => {
|
2022-10-11 07:40:39 -07:00
|
|
|
const workflow = await createWorkflow({}, owner);
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authOwnerAgent
|
2022-10-11 07:40:39 -07:00
|
|
|
.put(`/workflows/${workflow.id}/share`)
|
2024-05-17 01:53:15 -07:00
|
|
|
.send({ shareWithIds: [memberPersonalProject.id, anotherMemberPersonalProject.id] });
|
2022-10-11 07:40:39 -07:00
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
const sharedWorkflows = await getWorkflowSharing(workflow);
|
2022-10-11 07:40:39 -07:00
|
|
|
expect(sharedWorkflows).toHaveLength(3);
|
2024-01-23 03:03:59 -08:00
|
|
|
expect(mailer.notifyWorkflowShared).toHaveBeenCalledTimes(1);
|
2022-10-11 07:40:39 -07:00
|
|
|
});
|
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
test('should override sharing', async () => {
|
2022-10-11 07:40:39 -07:00
|
|
|
const workflow = await createWorkflow({}, owner);
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2022-10-11 07:40:39 -07:00
|
|
|
const response = await authOwnerAgent
|
|
|
|
.put(`/workflows/${workflow.id}/share`)
|
2024-05-17 01:53:15 -07:00
|
|
|
.send({ shareWithIds: [memberPersonalProject.id, anotherMemberPersonalProject.id] });
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2022-10-11 07:40:39 -07:00
|
|
|
expect(response.statusCode).toBe(200);
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
const sharedWorkflows = await getWorkflowSharing(workflow);
|
2022-10-11 07:40:39 -07:00
|
|
|
expect(sharedWorkflows).toHaveLength(3);
|
|
|
|
|
|
|
|
const secondResponse = await authOwnerAgent
|
|
|
|
.put(`/workflows/${workflow.id}/share`)
|
2024-05-17 01:53:15 -07:00
|
|
|
.send({ shareWithIds: [memberPersonalProject.id] });
|
2022-10-11 07:40:39 -07:00
|
|
|
expect(secondResponse.statusCode).toBe(200);
|
|
|
|
|
2023-11-08 07:29:39 -08:00
|
|
|
const secondSharedWorkflows = await getWorkflowSharing(workflow);
|
2022-10-11 07:40:39 -07:00
|
|
|
expect(secondSharedWorkflows).toHaveLength(2);
|
2024-01-29 07:15:30 -08:00
|
|
|
expect(mailer.notifyWorkflowShared).toHaveBeenCalledTimes(2);
|
2022-10-11 07:40:39 -07:00
|
|
|
});
|
2023-11-29 08:32:27 -08:00
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
test('should allow sharing by the owner of the workflow', async () => {
|
2023-11-29 08:32:27 -08:00
|
|
|
const workflow = await createWorkflow({}, member);
|
|
|
|
|
|
|
|
const response = await authMemberAgent
|
|
|
|
.put(`/workflows/${workflow.id}/share`)
|
2024-05-17 01:53:15 -07:00
|
|
|
.send({ shareWithIds: [anotherMemberPersonalProject.id] });
|
2023-11-29 08:32:27 -08:00
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
|
|
|
|
const sharedWorkflows = await getWorkflowSharing(workflow);
|
|
|
|
expect(sharedWorkflows).toHaveLength(2);
|
2024-01-23 03:03:59 -08:00
|
|
|
expect(mailer.notifyWorkflowShared).toHaveBeenCalledTimes(1);
|
2023-11-29 08:32:27 -08:00
|
|
|
});
|
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
test('should allow sharing by the instance owner', async () => {
|
2023-11-29 08:32:27 -08:00
|
|
|
const workflow = await createWorkflow({}, member);
|
|
|
|
|
|
|
|
const response = await authOwnerAgent
|
|
|
|
.put(`/workflows/${workflow.id}/share`)
|
2024-05-17 01:53:15 -07:00
|
|
|
.send({ shareWithIds: [anotherMemberPersonalProject.id] });
|
2023-11-29 08:32:27 -08:00
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
|
|
|
|
const sharedWorkflows = await getWorkflowSharing(workflow);
|
|
|
|
expect(sharedWorkflows).toHaveLength(2);
|
2024-01-23 03:03:59 -08:00
|
|
|
expect(mailer.notifyWorkflowShared).toHaveBeenCalledTimes(1);
|
2023-11-29 08:32:27 -08:00
|
|
|
});
|
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
test('should not allow sharing by another shared member', async () => {
|
2023-11-29 08:32:27 -08:00
|
|
|
const workflow = await createWorkflow({}, member);
|
|
|
|
|
|
|
|
await shareWorkflowWithUsers(workflow, [anotherMember]);
|
|
|
|
|
|
|
|
const response = await authAnotherMemberAgent
|
|
|
|
.put(`/workflows/${workflow.id}/share`)
|
2024-05-17 01:53:15 -07:00
|
|
|
.send({ shareWithIds: [anotherMemberPersonalProject.id, ownerPersonalProject.id] });
|
2023-11-29 08:32:27 -08:00
|
|
|
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
|
|
|
|
|
|
const sharedWorkflows = await getWorkflowSharing(workflow);
|
|
|
|
expect(sharedWorkflows).toHaveLength(2);
|
2024-01-23 03:03:59 -08:00
|
|
|
expect(mailer.notifyWorkflowShared).toHaveBeenCalledTimes(0);
|
2023-11-29 08:32:27 -08:00
|
|
|
});
|
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
test('should not allow sharing with self by another non-shared member', async () => {
|
2023-11-29 08:32:27 -08:00
|
|
|
const workflow = await createWorkflow({}, member);
|
|
|
|
|
|
|
|
const response = await authAnotherMemberAgent
|
|
|
|
.put(`/workflows/${workflow.id}/share`)
|
2024-05-17 01:53:15 -07:00
|
|
|
.send({ shareWithIds: [anotherMemberPersonalProject.id] });
|
2023-11-29 08:32:27 -08:00
|
|
|
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
|
|
|
|
|
|
const sharedWorkflows = await getWorkflowSharing(workflow);
|
|
|
|
expect(sharedWorkflows).toHaveLength(1);
|
2024-01-23 03:03:59 -08:00
|
|
|
expect(mailer.notifyWorkflowShared).toHaveBeenCalledTimes(0);
|
2023-11-29 08:32:27 -08:00
|
|
|
});
|
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
test('should not allow sharing by another non-shared member', async () => {
|
2023-11-29 08:32:27 -08:00
|
|
|
const workflow = await createWorkflow({}, member);
|
|
|
|
|
2024-01-24 04:38:57 -08:00
|
|
|
const tempUser = await createUser({ role: 'global:member' });
|
2024-05-17 01:53:15 -07:00
|
|
|
const tempUserPersonalProject = await projectRepository.getPersonalProjectForUserOrFail(
|
|
|
|
tempUser.id,
|
|
|
|
);
|
2023-11-29 08:32:27 -08:00
|
|
|
|
|
|
|
const response = await authAnotherMemberAgent
|
|
|
|
.put(`/workflows/${workflow.id}/share`)
|
2024-05-17 01:53:15 -07:00
|
|
|
.send({ shareWithIds: [tempUserPersonalProject.id] });
|
2023-11-29 08:32:27 -08:00
|
|
|
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
|
|
|
|
|
|
const sharedWorkflows = await getWorkflowSharing(workflow);
|
|
|
|
expect(sharedWorkflows).toHaveLength(1);
|
2024-01-23 03:03:59 -08:00
|
|
|
expect(mailer.notifyWorkflowShared).toHaveBeenCalledTimes(0);
|
2023-11-29 08:32:27 -08:00
|
|
|
});
|
2024-01-29 07:15:30 -08:00
|
|
|
|
|
|
|
test('should not call internal hooks listener for email sent if emailing is disabled', async () => {
|
|
|
|
config.set('userManagement.emails.mode', '');
|
|
|
|
|
|
|
|
const workflow = await createWorkflow({}, owner);
|
|
|
|
|
|
|
|
const response = await authOwnerAgent
|
|
|
|
.put(`/workflows/${workflow.id}/share`)
|
2024-05-17 01:53:15 -07:00
|
|
|
.send({ shareWithIds: [memberPersonalProject.id] });
|
2024-01-29 07:15:30 -08:00
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
|
|
|
|
config.set('userManagement.emails.mode', 'smtp');
|
|
|
|
});
|
2022-10-11 05:55:05 -07:00
|
|
|
});
|
|
|
|
|
2023-06-29 23:51:39 -07:00
|
|
|
describe('GET /workflows/new', () => {
|
|
|
|
[true, false].forEach((sharingEnabled) => {
|
|
|
|
test(`should return an auto-incremented name, even when sharing is ${
|
|
|
|
sharingEnabled ? 'enabled' : 'disabled'
|
|
|
|
}`, async () => {
|
|
|
|
sharingSpy.mockReturnValueOnce(sharingEnabled);
|
|
|
|
|
|
|
|
await createWorkflow({ name: 'My workflow' }, owner);
|
|
|
|
await createWorkflow({ name: 'My workflow 7' }, owner);
|
|
|
|
|
|
|
|
const response = await authOwnerAgent.get('/workflows/new');
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.data.name).toEqual('My workflow 8');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
describe('GET /workflows/:workflowId', () => {
|
|
|
|
test('should fail with invalid id due to route rule', async () => {
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authOwnerAgent.get('/workflows/potatoes');
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2022-10-13 02:55:58 -07:00
|
|
|
expect(response.statusCode).toBe(404);
|
|
|
|
});
|
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
test('should return 404 for non existing workflow', async () => {
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authOwnerAgent.get('/workflows/9001');
|
2022-10-13 02:55:58 -07:00
|
|
|
|
|
|
|
expect(response.statusCode).toBe(404);
|
2022-10-11 07:40:39 -07:00
|
|
|
});
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
test('project viewers can view workflows', async () => {
|
|
|
|
const teamProject = await createTeamProject();
|
|
|
|
await linkUserToProject(member, teamProject, 'project:viewer');
|
|
|
|
|
|
|
|
const workflow = await createWorkflow({}, teamProject);
|
|
|
|
|
|
|
|
const response = await authMemberAgent.get(`/workflows/${workflow.id}`).expect(200);
|
|
|
|
const responseWorkflow: WorkflowWithSharingsMetaDataAndCredentials = response.body.data;
|
|
|
|
|
|
|
|
expect(responseWorkflow.homeProject).toMatchObject({
|
|
|
|
id: teamProject.id,
|
|
|
|
name: teamProject.name,
|
|
|
|
type: 'team',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(responseWorkflow.sharedWithProjects).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
test('should return a workflow with owner', async () => {
|
2022-10-11 07:40:39 -07:00
|
|
|
const workflow = await createWorkflow({}, owner);
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
const response = await authOwnerAgent.get(`/workflows/${workflow.id}`).expect(200);
|
|
|
|
const responseWorkflow: WorkflowWithSharingsMetaDataAndCredentials = response.body.data;
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
expect(responseWorkflow.homeProject).toMatchObject({
|
|
|
|
id: ownerPersonalProject.id,
|
|
|
|
name: owner.createPersonalProjectName(),
|
|
|
|
type: 'personal',
|
2022-10-11 07:40:39 -07:00
|
|
|
});
|
2022-10-11 05:55:05 -07:00
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
expect(responseWorkflow.sharedWithProjects).toHaveLength(0);
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
expect((responseWorkflow as any).shared).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should return tags', async () => {
|
|
|
|
const tag = await createTag({ name: 'A' });
|
|
|
|
const workflow = await createWorkflow({ tags: [tag] }, owner);
|
|
|
|
|
|
|
|
const response = await authOwnerAgent.get(`/workflows/${workflow.id}`).expect(200);
|
|
|
|
|
|
|
|
expect(response.body.data).toMatchObject({
|
|
|
|
tags: [expect.objectContaining({ id: tag.id, name: tag.name })],
|
|
|
|
});
|
2022-10-11 07:40:39 -07:00
|
|
|
});
|
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
test('should return shared workflow with user data', async () => {
|
2022-10-11 07:40:39 -07:00
|
|
|
const workflow = await createWorkflow({}, owner);
|
2023-11-08 07:29:39 -08:00
|
|
|
await shareWorkflowWithUsers(workflow, [member]);
|
2022-10-11 07:40:39 -07:00
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
const response = await authOwnerAgent.get(`/workflows/${workflow.id}`).expect(200);
|
|
|
|
const responseWorkflow: WorkflowWithSharingsMetaDataAndCredentials = response.body.data;
|
2022-10-11 07:40:39 -07:00
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
expect(responseWorkflow.homeProject).toMatchObject({
|
|
|
|
id: ownerPersonalProject.id,
|
|
|
|
name: owner.createPersonalProjectName(),
|
|
|
|
type: 'personal',
|
2022-10-11 07:40:39 -07:00
|
|
|
});
|
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
expect(responseWorkflow.sharedWithProjects).toHaveLength(1);
|
|
|
|
expect(responseWorkflow.sharedWithProjects[0]).toMatchObject({
|
|
|
|
id: memberPersonalProject.id,
|
|
|
|
name: member.createPersonalProjectName(),
|
|
|
|
type: 'personal',
|
2022-10-11 07:40:39 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
test('should return all sharees', async () => {
|
2022-10-11 07:40:39 -07:00
|
|
|
const workflow = await createWorkflow({}, owner);
|
2023-11-08 07:29:39 -08:00
|
|
|
await shareWorkflowWithUsers(workflow, [member, anotherMember]);
|
2022-10-11 07:40:39 -07:00
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
const response = await authOwnerAgent.get(`/workflows/${workflow.id}`).expect(200);
|
|
|
|
const responseWorkflow: WorkflowWithSharingsMetaDataAndCredentials = response.body.data;
|
2022-10-11 07:40:39 -07:00
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
expect(responseWorkflow.homeProject).toMatchObject({
|
|
|
|
id: ownerPersonalProject.id,
|
|
|
|
name: owner.createPersonalProjectName(),
|
|
|
|
type: 'personal',
|
2022-10-11 07:40:39 -07:00
|
|
|
});
|
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
expect(responseWorkflow.sharedWithProjects).toHaveLength(2);
|
2022-10-11 07:40:39 -07:00
|
|
|
});
|
2022-10-31 07:08:25 -07:00
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
test('should return workflow with credentials owned by user', async () => {
|
2022-10-31 07:08:25 -07:00
|
|
|
const savedCredential = await saveCredential(randomCredentialPayload(), { user: owner });
|
|
|
|
|
|
|
|
const workflowPayload = makeWorkflow({
|
|
|
|
withPinData: false,
|
2023-01-02 08:42:32 -08:00
|
|
|
withCredential: { id: savedCredential.id, name: savedCredential.name },
|
2022-10-31 07:08:25 -07:00
|
|
|
});
|
|
|
|
const workflow = await createWorkflow(workflowPayload, owner);
|
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
const response = await authOwnerAgent.get(`/workflows/${workflow.id}`).expect(200);
|
|
|
|
const responseWorkflow: WorkflowWithSharingsMetaDataAndCredentials = response.body.data;
|
2022-10-31 07:08:25 -07:00
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
2024-05-17 01:53:15 -07:00
|
|
|
expect(responseWorkflow.usedCredentials).toMatchObject([
|
2022-10-31 07:08:25 -07:00
|
|
|
{
|
2023-01-02 08:42:32 -08:00
|
|
|
id: savedCredential.id,
|
2022-10-31 07:08:25 -07:00
|
|
|
name: savedCredential.name,
|
|
|
|
currentUserHasAccess: true,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
expect(responseWorkflow.sharedWithProjects).toHaveLength(0);
|
2022-10-31 07:08:25 -07:00
|
|
|
});
|
|
|
|
|
2024-07-09 07:25:50 -07:00
|
|
|
test.each([
|
|
|
|
['owner', () => owner],
|
|
|
|
['admin', () => admin],
|
|
|
|
])(
|
|
|
|
'should return workflow with credentials saying %s does have access even when not shared',
|
|
|
|
async (_description, getActor) => {
|
|
|
|
const actor = getActor();
|
|
|
|
const savedCredential = await saveCredential(randomCredentialPayload(), { user: member });
|
|
|
|
|
|
|
|
const workflowPayload = makeWorkflow({
|
|
|
|
withPinData: false,
|
|
|
|
withCredential: { id: savedCredential.id, name: savedCredential.name },
|
|
|
|
});
|
|
|
|
const workflow = await createWorkflow(workflowPayload, actor);
|
|
|
|
|
|
|
|
const response = await testServer
|
|
|
|
.authAgentFor(actor)
|
|
|
|
.get(`/workflows/${workflow.id}`)
|
|
|
|
.expect(200);
|
|
|
|
const responseWorkflow: WorkflowWithSharingsMetaDataAndCredentials = response.body.data;
|
|
|
|
|
|
|
|
expect(responseWorkflow.usedCredentials).toMatchObject([
|
|
|
|
{
|
|
|
|
id: savedCredential.id,
|
|
|
|
name: savedCredential.name,
|
|
|
|
currentUserHasAccess: true,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
expect(responseWorkflow.sharedWithProjects).toHaveLength(0);
|
|
|
|
},
|
|
|
|
);
|
2022-10-31 07:08:25 -07:00
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
test('should return workflow with credentials for all users with or without access', async () => {
|
2023-03-17 09:24:05 -07:00
|
|
|
const savedCredential = await saveCredential(randomCredentialPayload(), { user: member });
|
2022-10-31 07:08:25 -07:00
|
|
|
|
|
|
|
const workflowPayload = makeWorkflow({
|
|
|
|
withPinData: false,
|
2023-01-02 08:42:32 -08:00
|
|
|
withCredential: { id: savedCredential.id, name: savedCredential.name },
|
2022-10-31 07:08:25 -07:00
|
|
|
});
|
2023-03-17 09:24:05 -07:00
|
|
|
const workflow = await createWorkflow(workflowPayload, member);
|
2023-11-08 07:29:39 -08:00
|
|
|
await shareWorkflowWithUsers(workflow, [anotherMember]);
|
2022-10-31 07:08:25 -07:00
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
const responseMember1 = await authMemberAgent.get(`/workflows/${workflow.id}`).expect(200);
|
|
|
|
const member1Workflow: WorkflowWithSharingsMetaDataAndCredentials = responseMember1.body.data;
|
|
|
|
|
|
|
|
expect(member1Workflow.usedCredentials).toMatchObject([
|
2022-10-31 07:08:25 -07:00
|
|
|
{
|
2023-01-02 08:42:32 -08:00
|
|
|
id: savedCredential.id,
|
2022-10-31 07:08:25 -07:00
|
|
|
name: savedCredential.name,
|
|
|
|
currentUserHasAccess: true, // one user has access
|
|
|
|
},
|
|
|
|
]);
|
2024-05-17 01:53:15 -07:00
|
|
|
expect(member1Workflow.sharedWithProjects).toHaveLength(1);
|
2022-10-31 07:08:25 -07:00
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
const responseMember2 = await authAnotherMemberAgent
|
|
|
|
.get(`/workflows/${workflow.id}`)
|
|
|
|
.expect(200);
|
|
|
|
const member2Workflow: WorkflowWithSharingsMetaDataAndCredentials = responseMember2.body.data;
|
|
|
|
|
|
|
|
expect(member2Workflow.usedCredentials).toMatchObject([
|
2022-10-31 07:08:25 -07:00
|
|
|
{
|
2023-01-02 08:42:32 -08:00
|
|
|
id: savedCredential.id,
|
2022-10-31 07:08:25 -07:00
|
|
|
name: savedCredential.name,
|
|
|
|
currentUserHasAccess: false, // the other one doesn't
|
|
|
|
},
|
|
|
|
]);
|
2024-05-17 01:53:15 -07:00
|
|
|
expect(member2Workflow.sharedWithProjects).toHaveLength(1);
|
2022-10-31 07:08:25 -07:00
|
|
|
});
|
|
|
|
|
2024-05-27 11:41:34 -07:00
|
|
|
test('should return workflow with credentials for all users with access', async () => {
|
2023-03-17 09:24:05 -07:00
|
|
|
const savedCredential = await saveCredential(randomCredentialPayload(), { user: member });
|
2022-10-31 07:08:25 -07:00
|
|
|
// Both users have access to the credential (none is owner)
|
2023-11-08 07:29:39 -08:00
|
|
|
await shareCredentialWithUsers(savedCredential, [anotherMember]);
|
2022-10-31 07:08:25 -07:00
|
|
|
|
|
|
|
const workflowPayload = makeWorkflow({
|
|
|
|
withPinData: false,
|
2023-01-02 08:42:32 -08:00
|
|
|
withCredential: { id: savedCredential.id, name: savedCredential.name },
|
2022-10-31 07:08:25 -07:00
|
|
|
});
|
2023-03-17 09:24:05 -07:00
|
|
|
const workflow = await createWorkflow(workflowPayload, member);
|
2023-11-08 07:29:39 -08:00
|
|
|
await shareWorkflowWithUsers(workflow, [anotherMember]);
|
2022-10-31 07:08:25 -07:00
|
|
|
|
2024-05-17 01:53:15 -07:00
|
|
|
const responseMember1 = await authMemberAgent.get(`/workflows/${workflow.id}`).expect(200);
|
|
|
|
const member1Workflow: WorkflowWithSharingsMetaDataAndCredentials = responseMember1.body.data;
|
|
|
|
|
|
|
|
expect(member1Workflow.usedCredentials).toMatchObject([
|
2022-10-31 07:08:25 -07:00
|
|
|
{
|
2023-01-02 08:42:32 -08:00
|
|
|
id: savedCredential.id,
|
2022-10-31 07:08:25 -07:00
|
|
|
name: savedCredential.name,
|
|
|
|
currentUserHasAccess: true,
|
|
|
|
},
|
|
|
|
]);
|
2024-05-17 01:53:15 -07:00
|
|
|
expect(member1Workflow.sharedWithProjects).toHaveLength(1);
|
|
|
|
|
|
|
|
const responseMember2 = await authAnotherMemberAgent
|
|
|
|
.get(`/workflows/${workflow.id}`)
|
|
|
|
.expect(200);
|
|
|
|
const member2Workflow: WorkflowWithSharingsMetaDataAndCredentials = responseMember2.body.data;
|
2022-10-31 07:08:25 -07:00
|
|
|
|
|
|
|
expect(responseMember2.statusCode).toBe(200);
|
2024-05-17 01:53:15 -07:00
|
|
|
expect(member2Workflow.usedCredentials).toMatchObject([
|
2022-10-31 07:08:25 -07:00
|
|
|
{
|
2023-01-02 08:42:32 -08:00
|
|
|
id: savedCredential.id,
|
2022-10-31 07:08:25 -07:00
|
|
|
name: savedCredential.name,
|
|
|
|
currentUserHasAccess: true,
|
|
|
|
},
|
|
|
|
]);
|
2024-05-17 01:53:15 -07:00
|
|
|
expect(member2Workflow.sharedWithProjects).toHaveLength(1);
|
2022-10-31 07:08:25 -07:00
|
|
|
});
|
2024-06-20 07:43:23 -07:00
|
|
|
|
|
|
|
test('should return workflow credentials home project and shared with projects', async () => {
|
|
|
|
const savedCredential = await saveCredential(randomCredentialPayload(), { user: member });
|
|
|
|
// Both users have access to the credential (none is owner)
|
|
|
|
await shareCredentialWithUsers(savedCredential, [anotherMember]);
|
|
|
|
|
|
|
|
const workflowPayload = makeWorkflow({
|
|
|
|
withPinData: false,
|
|
|
|
withCredential: { id: savedCredential.id, name: savedCredential.name },
|
|
|
|
});
|
|
|
|
const workflow = await createWorkflow(workflowPayload, member);
|
|
|
|
await shareWorkflowWithUsers(workflow, [anotherMember]);
|
|
|
|
|
|
|
|
const responseMember1 = await authMemberAgent.get(`/workflows/${workflow.id}`).expect(200);
|
|
|
|
const member1Workflow: WorkflowWithSharingsMetaDataAndCredentials = responseMember1.body.data;
|
|
|
|
|
|
|
|
expect(member1Workflow.usedCredentials).toMatchObject([
|
|
|
|
{
|
|
|
|
id: savedCredential.id,
|
|
|
|
name: savedCredential.name,
|
|
|
|
currentUserHasAccess: true,
|
|
|
|
homeProject: {
|
|
|
|
id: memberPersonalProject.id,
|
|
|
|
},
|
|
|
|
sharedWithProjects: [{ id: anotherMemberPersonalProject.id }],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
expect(member1Workflow.sharedWithProjects).toHaveLength(1);
|
|
|
|
});
|
2022-10-11 05:55:05 -07:00
|
|
|
});
|
2022-10-13 02:55:58 -07:00
|
|
|
|
|
|
|
describe('POST /workflows', () => {
|
2024-06-06 02:55:48 -07:00
|
|
|
test('project viewers cannot create workflows', async () => {
|
|
|
|
const teamProject = await createTeamProject();
|
|
|
|
await linkUserToProject(member, teamProject, 'project:viewer');
|
|
|
|
|
|
|
|
const response = await authMemberAgent
|
|
|
|
.post('/workflows')
|
|
|
|
.send({ ...makeWorkflow(), projectId: teamProject.id });
|
|
|
|
|
|
|
|
expect(response.body).toMatchObject({
|
|
|
|
code: 400,
|
|
|
|
message: "You don't have the permissions to save the workflow in this project.",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-10-13 02:55:58 -07:00
|
|
|
it('Should create a workflow that uses no credential', async () => {
|
|
|
|
const workflow = makeWorkflow({ withPinData: false });
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authOwnerAgent.post('/workflows').send(workflow);
|
2022-10-13 02:55:58 -07:00
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
});
|
|
|
|
|
2022-10-26 06:49:43 -07:00
|
|
|
it('Should save a new workflow with credentials', async () => {
|
2022-10-13 02:55:58 -07:00
|
|
|
const savedCredential = await saveCredential(randomCredentialPayload(), { user: owner });
|
|
|
|
const workflow = makeWorkflow({
|
|
|
|
withPinData: false,
|
2023-01-02 08:42:32 -08:00
|
|
|
withCredential: { id: savedCredential.id, name: savedCredential.name },
|
2022-10-13 02:55:58 -07:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authOwnerAgent.post('/workflows').send(workflow);
|
2022-10-13 02:55:58 -07:00
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should not allow saving a workflow using credential you have no access', async () => {
|
|
|
|
// Credential belongs to owner, member cannot use it.
|
|
|
|
const savedCredential = await saveCredential(randomCredentialPayload(), { user: owner });
|
|
|
|
const workflow = makeWorkflow({
|
|
|
|
withPinData: false,
|
2023-01-02 08:42:32 -08:00
|
|
|
withCredential: { id: savedCredential.id, name: savedCredential.name },
|
2022-10-13 02:55:58 -07:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authMemberAgent.post('/workflows').send(workflow);
|
2022-10-13 02:55:58 -07:00
|
|
|
|
|
|
|
expect(response.statusCode).toBe(400);
|
|
|
|
expect(response.body.message).toBe(
|
2022-11-22 04:05:51 -08:00
|
|
|
'The workflow you are trying to save contains credentials that are not shared with you',
|
2022-10-13 02:55:58 -07:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should allow owner to save a workflow using credential owned by others', async () => {
|
|
|
|
// Credential belongs to owner, member cannot use it.
|
|
|
|
const savedCredential = await saveCredential(randomCredentialPayload(), { user: member });
|
|
|
|
const workflow = makeWorkflow({
|
|
|
|
withPinData: false,
|
2023-01-02 08:42:32 -08:00
|
|
|
withCredential: { id: savedCredential.id, name: savedCredential.name },
|
2022-10-13 02:55:58 -07:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authOwnerAgent.post('/workflows').send(workflow);
|
2022-10-13 02:55:58 -07:00
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should allow saving a workflow using a credential owned by others and shared with you', async () => {
|
2023-03-17 09:24:05 -07:00
|
|
|
const savedCredential = await saveCredential(randomCredentialPayload(), { user: member });
|
2023-11-08 07:29:39 -08:00
|
|
|
await shareCredentialWithUsers(savedCredential, [anotherMember]);
|
2022-10-13 02:55:58 -07:00
|
|
|
|
|
|
|
const workflow = makeWorkflow({
|
|
|
|
withPinData: false,
|
2023-01-02 08:42:32 -08:00
|
|
|
withCredential: { id: savedCredential.id, name: savedCredential.name },
|
2022-10-13 02:55:58 -07:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:24:05 -07:00
|
|
|
const response = await authAnotherMemberAgent.post('/workflows').send(workflow);
|
2022-10-13 02:55:58 -07:00
|
|
|
expect(response.statusCode).toBe(200);
|
2022-10-26 06:49:43 -07:00
|
|
|
});
|
2023-10-25 03:07:11 -07:00
|
|
|
|
|
|
|
test('Should create workflow history version when licensed', async () => {
|
2023-11-30 00:23:09 -08:00
|
|
|
license.enable('feat:workflowHistory');
|
2023-10-25 03:07:11 -07:00
|
|
|
const payload = {
|
|
|
|
name: 'testing',
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Start',
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [240, 300],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
connections: {},
|
|
|
|
staticData: null,
|
|
|
|
settings: {
|
|
|
|
saveExecutionProgress: true,
|
|
|
|
saveManualExecutions: true,
|
|
|
|
saveDataErrorExecution: 'all',
|
|
|
|
saveDataSuccessExecution: 'all',
|
|
|
|
executionTimeout: 3600,
|
|
|
|
timezone: 'America/New_York',
|
|
|
|
},
|
|
|
|
active: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await authOwnerAgent.post('/workflows').send(payload);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
|
|
|
|
const {
|
|
|
|
data: { id },
|
|
|
|
} = response.body;
|
|
|
|
|
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(
|
|
|
|
await Container.get(WorkflowHistoryRepository).count({ where: { workflowId: id } }),
|
|
|
|
).toBe(1);
|
|
|
|
const historyVersion = await Container.get(WorkflowHistoryRepository).findOne({
|
|
|
|
where: {
|
|
|
|
workflowId: id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(historyVersion).not.toBeNull();
|
|
|
|
expect(historyVersion!.connections).toEqual(payload.connections);
|
|
|
|
expect(historyVersion!.nodes).toEqual(payload.nodes);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Should not create workflow history version when not licensed', async () => {
|
2023-11-30 00:23:09 -08:00
|
|
|
license.disable('feat:workflowHistory');
|
2023-10-25 03:07:11 -07:00
|
|
|
const payload = {
|
|
|
|
name: 'testing',
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Start',
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [240, 300],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
connections: {},
|
|
|
|
staticData: null,
|
|
|
|
settings: {
|
|
|
|
saveExecutionProgress: true,
|
|
|
|
saveManualExecutions: true,
|
|
|
|
saveDataErrorExecution: 'all',
|
|
|
|
saveDataSuccessExecution: 'all',
|
|
|
|
executionTimeout: 3600,
|
|
|
|
timezone: 'America/New_York',
|
|
|
|
},
|
|
|
|
active: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await authOwnerAgent.post('/workflows').send(payload);
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
|
|
|
|
const {
|
|
|
|
data: { id },
|
|
|
|
} = response.body;
|
|
|
|
|
|
|
|
expect(id).toBeDefined();
|
|
|
|
expect(
|
|
|
|
await Container.get(WorkflowHistoryRepository).count({ where: { workflowId: id } }),
|
|
|
|
).toBe(0);
|
|
|
|
});
|
2022-10-26 06:49:43 -07:00
|
|
|
});
|
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
describe('PATCH /workflows/:workflowId', () => {
|
|
|
|
test('project viewers cannot update workflows', async () => {
|
|
|
|
const teamProject = await createTeamProject();
|
|
|
|
await linkUserToProject(member, teamProject, 'project:viewer');
|
|
|
|
|
|
|
|
const workflow = await createWorkflow({ name: 'WF Name' }, teamProject);
|
|
|
|
|
|
|
|
const response = await authMemberAgent
|
|
|
|
.patch(`/workflows/${workflow.id}`)
|
|
|
|
.send({ ...workflow, name: 'New Name' });
|
|
|
|
|
|
|
|
expect(response.status).toBe(403);
|
|
|
|
expect(response.body).toMatchObject({
|
|
|
|
message: 'User is missing a scope required to perform this action',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('validate credential permissions to user', () => {
|
|
|
|
it('Should succeed when saving unchanged workflow nodes', async () => {
|
|
|
|
const savedCredential = await saveCredential(randomCredentialPayload(), { user: owner });
|
|
|
|
const workflow = {
|
|
|
|
name: 'test',
|
|
|
|
active: false,
|
|
|
|
connections: {},
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
name: 'Start',
|
|
|
|
parameters: {},
|
|
|
|
position: [-20, 260],
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
credentials: {
|
|
|
|
default: {
|
|
|
|
id: savedCredential.id,
|
|
|
|
name: savedCredential.name,
|
|
|
|
},
|
2022-10-26 06:49:43 -07:00
|
|
|
},
|
|
|
|
},
|
2024-06-06 02:55:48 -07:00
|
|
|
],
|
|
|
|
};
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const createResponse = await authOwnerAgent.post('/workflows').send(workflow);
|
|
|
|
const { id, versionId } = createResponse.body.data;
|
2022-10-26 06:49:43 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const response = await authOwnerAgent.patch(`/workflows/${id}`).send({
|
|
|
|
name: 'new name',
|
|
|
|
versionId,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(response.statusCode).toBe(200);
|
2022-10-26 06:49:43 -07:00
|
|
|
});
|
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
it('Should allow owner to add node containing credential not shared with the owner', async () => {
|
|
|
|
const savedCredential = await saveCredential(randomCredentialPayload(), { user: member });
|
|
|
|
const workflow = {
|
|
|
|
name: 'test',
|
|
|
|
active: false,
|
|
|
|
connections: {},
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
name: 'Start',
|
|
|
|
parameters: {},
|
|
|
|
position: [-20, 260],
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
credentials: {
|
|
|
|
default: {
|
|
|
|
id: savedCredential.id,
|
|
|
|
name: savedCredential.name,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const createResponse = await authOwnerAgent.post('/workflows').send(workflow);
|
|
|
|
const { id, versionId } = createResponse.body.data;
|
|
|
|
|
|
|
|
const response = await authOwnerAgent.patch(`/workflows/${id}`).send({
|
|
|
|
versionId,
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
name: 'Start',
|
|
|
|
parameters: {},
|
|
|
|
position: [-20, 260],
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
credentials: {
|
|
|
|
default: {
|
|
|
|
id: savedCredential.id,
|
|
|
|
name: savedCredential.name,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2022-10-26 06:49:43 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
});
|
|
|
|
|
2024-07-03 02:42:59 -07:00
|
|
|
it.each([
|
|
|
|
[
|
|
|
|
'the owner and shared with the member',
|
|
|
|
'the owner',
|
|
|
|
async function creteWorkflow() {
|
|
|
|
const workflow = await createWorkflow({}, owner);
|
|
|
|
await shareWorkflowWithUsers(workflow, [member]);
|
|
|
|
return workflow;
|
|
|
|
},
|
|
|
|
async function createCredential() {
|
|
|
|
return await saveCredential(randomCredentialPayload(), { user: owner });
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'team 1',
|
|
|
|
'the member',
|
|
|
|
async function creteWorkflow() {
|
|
|
|
const team = await createTeamProject('Team 1', member);
|
|
|
|
return await createWorkflow({}, team);
|
|
|
|
},
|
|
|
|
async function createCredential() {
|
|
|
|
return await saveCredential(randomCredentialPayload(), { user: member });
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'team 1',
|
|
|
|
'team 2',
|
|
|
|
async function creteWorkflow() {
|
|
|
|
const team1 = await createTeamProject('Team 1', member);
|
|
|
|
return await createWorkflow({}, team1);
|
|
|
|
},
|
|
|
|
async function createCredential() {
|
|
|
|
const team2 = await createTeamProject('Team 2', member);
|
|
|
|
return await saveCredential(randomCredentialPayload(), { project: team2 });
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'the member',
|
|
|
|
'the owner',
|
|
|
|
async function creteWorkflow() {
|
|
|
|
return await createWorkflow({}, member);
|
|
|
|
},
|
|
|
|
async function createCredential() {
|
|
|
|
return await saveCredential(randomCredentialPayload(), { user: owner });
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'the member',
|
|
|
|
'team 2',
|
|
|
|
async function creteWorkflow() {
|
|
|
|
return await createWorkflow({}, member);
|
|
|
|
},
|
|
|
|
async function createCredential() {
|
|
|
|
const team2 = await createTeamProject('Team 2', member);
|
|
|
|
return await saveCredential(randomCredentialPayload(), { project: team2 });
|
|
|
|
},
|
|
|
|
],
|
|
|
|
])(
|
|
|
|
'Tamper proofing kicks in if the workflow is owned by %s, the credentials is owned by %s, and the member tries to use the credential in the workflow',
|
|
|
|
async (_workflowText, _credentialText, createWorkflow, createCredential) => {
|
|
|
|
//
|
|
|
|
// ARRANGE
|
|
|
|
//
|
|
|
|
const workflow = await createWorkflow();
|
|
|
|
const credential = await createCredential();
|
|
|
|
|
|
|
|
//
|
|
|
|
// ACT
|
|
|
|
//
|
|
|
|
const response = await authMemberAgent.patch(`/workflows/${workflow.id}`).send({
|
|
|
|
versionId: workflow.versionId,
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-12345',
|
|
|
|
name: 'Start',
|
|
|
|
parameters: {},
|
|
|
|
position: [-20, 260],
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
credentials: {
|
|
|
|
default: {
|
|
|
|
id: credential.id,
|
|
|
|
name: credential.name,
|
|
|
|
},
|
2024-06-06 02:55:48 -07:00
|
|
|
},
|
|
|
|
},
|
2024-07-03 02:42:59 -07:00
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
//
|
|
|
|
// ASSERT
|
|
|
|
//
|
|
|
|
expect(response.statusCode).toBe(400);
|
|
|
|
expect(response.body.message).toBe(
|
|
|
|
"You don't have access to the credentials in the 'Start' node. Ask the owner to share them with you.",
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
it('Should succeed but prevent modifying node attributes other than position, name and disabled', async () => {
|
|
|
|
const savedCredential = await saveCredential(randomCredentialPayload(), { user: member });
|
2022-10-26 06:49:43 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const originalNodes: INode[] = [
|
2023-03-17 09:24:05 -07:00
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
name: 'Start',
|
2024-06-06 02:55:48 -07:00
|
|
|
parameters: {
|
|
|
|
firstParam: 123,
|
|
|
|
},
|
2023-03-17 09:24:05 -07:00
|
|
|
position: [-20, 260],
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
credentials: {
|
|
|
|
default: {
|
|
|
|
id: savedCredential.id,
|
|
|
|
name: savedCredential.name,
|
2022-10-26 06:49:43 -07:00
|
|
|
},
|
|
|
|
},
|
2023-03-17 09:24:05 -07:00
|
|
|
},
|
2024-06-06 02:55:48 -07:00
|
|
|
];
|
2022-10-26 06:49:43 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const changedNodes: INode[] = [
|
2022-10-31 02:35:24 -07:00
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
2024-06-06 02:55:48 -07:00
|
|
|
name: 'End',
|
|
|
|
parameters: {
|
|
|
|
firstParam: 456,
|
|
|
|
},
|
|
|
|
position: [-20, 555],
|
|
|
|
type: 'n8n-nodes-base.no-op',
|
2022-10-31 02:35:24 -07:00
|
|
|
typeVersion: 1,
|
|
|
|
credentials: {
|
|
|
|
default: {
|
2024-06-06 02:55:48 -07:00
|
|
|
id: '200',
|
|
|
|
name: 'fake credential',
|
2022-10-31 02:35:24 -07:00
|
|
|
},
|
|
|
|
},
|
2024-06-06 02:55:48 -07:00
|
|
|
disabled: true,
|
2022-10-31 02:35:24 -07:00
|
|
|
},
|
2024-06-06 02:55:48 -07:00
|
|
|
];
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const expectedNodes: INode[] = [
|
2023-03-17 09:24:05 -07:00
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
2024-06-06 02:55:48 -07:00
|
|
|
name: 'End',
|
|
|
|
parameters: {
|
|
|
|
firstParam: 123,
|
|
|
|
},
|
|
|
|
position: [-20, 555],
|
2023-03-17 09:24:05 -07:00
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
credentials: {
|
|
|
|
default: {
|
|
|
|
id: savedCredential.id,
|
|
|
|
name: savedCredential.name,
|
2022-10-26 06:49:43 -07:00
|
|
|
},
|
|
|
|
},
|
2024-06-06 02:55:48 -07:00
|
|
|
disabled: true,
|
2023-03-17 09:24:05 -07:00
|
|
|
},
|
2024-06-06 02:55:48 -07:00
|
|
|
];
|
2022-10-26 06:49:43 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const workflow = {
|
|
|
|
name: 'test',
|
|
|
|
active: false,
|
|
|
|
connections: {},
|
|
|
|
nodes: originalNodes,
|
|
|
|
};
|
2022-10-26 06:49:43 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const createResponse = await authMemberAgent.post('/workflows').send(workflow);
|
|
|
|
const { id, versionId } = createResponse.body.data;
|
2022-10-26 06:49:43 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
await authMemberAgent
|
|
|
|
.put(`/workflows/${id}/share`)
|
|
|
|
.send({ shareWithIds: [anotherMemberPersonalProject.id] })
|
|
|
|
.expect(200);
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const response = await authAnotherMemberAgent.patch(`/workflows/${id}`).send({
|
|
|
|
versionId,
|
|
|
|
nodes: changedNodes,
|
|
|
|
});
|
2022-10-26 06:49:43 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(response.body.data.nodes).toMatchObject(expectedNodes);
|
2022-10-26 06:49:43 -07:00
|
|
|
});
|
2022-10-13 02:55:58 -07:00
|
|
|
});
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
describe('validate interim updates', () => {
|
|
|
|
it('should block owner updating workflow nodes on interim update by member', async () => {
|
|
|
|
// owner creates and shares workflow
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const createResponse = await authOwnerAgent.post('/workflows').send(makeWorkflow());
|
|
|
|
const { id, versionId: ownerVersionId } = createResponse.body.data;
|
|
|
|
await authOwnerAgent
|
|
|
|
.put(`/workflows/${id}/share`)
|
|
|
|
.send({ shareWithIds: [memberPersonalProject.id] });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
// member accesses and updates workflow name
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const memberGetResponse = await authMemberAgent.get(`/workflows/${id}`);
|
|
|
|
const { versionId: memberVersionId } = memberGetResponse.body.data;
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
await authMemberAgent
|
|
|
|
.patch(`/workflows/${id}`)
|
|
|
|
.send({ name: 'Update by member', versionId: memberVersionId });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
// owner blocked from updating workflow nodes
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const updateAttemptResponse = await authOwnerAgent
|
|
|
|
.patch(`/workflows/${id}`)
|
|
|
|
.send({ nodes: [], versionId: ownerVersionId });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
expect(updateAttemptResponse.status).toBe(400);
|
|
|
|
expect(updateAttemptResponse.body.code).toBe(100);
|
|
|
|
});
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
it('should block member updating workflow nodes on interim update by owner', async () => {
|
|
|
|
// owner creates, updates and shares workflow
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const createResponse = await authOwnerAgent.post('/workflows').send(makeWorkflow());
|
|
|
|
const { id, versionId: ownerFirstVersionId } = createResponse.body.data;
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const updateResponse = await authOwnerAgent
|
|
|
|
.patch(`/workflows/${id}`)
|
|
|
|
.send({ name: 'Update by owner', versionId: ownerFirstVersionId });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const { versionId: ownerSecondVersionId } = updateResponse.body.data;
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
await authOwnerAgent
|
|
|
|
.put(`/workflows/${id}/share`)
|
|
|
|
.send({ shareWithIds: [memberPersonalProject.id] });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
// member accesses workflow
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const memberGetResponse = await authMemberAgent.get(`/workflows/${id}`);
|
|
|
|
const { versionId: memberVersionId } = memberGetResponse.body.data;
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
// owner re-updates workflow
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
await authOwnerAgent
|
|
|
|
.patch(`/workflows/${id}`)
|
|
|
|
.send({ name: 'Owner update again', versionId: ownerSecondVersionId });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
// member blocked from updating workflow
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const updateAttemptResponse = await authMemberAgent
|
|
|
|
.patch(`/workflows/${id}`)
|
|
|
|
.send({ nodes: [], versionId: memberVersionId });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
expect(updateAttemptResponse.status).toBe(400);
|
|
|
|
expect(updateAttemptResponse.body.code).toBe(100);
|
|
|
|
});
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
it('should block owner activation on interim activation by member', async () => {
|
|
|
|
// owner creates and shares workflow
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const createResponse = await authOwnerAgent.post('/workflows').send(makeWorkflow());
|
|
|
|
const { id, versionId: ownerVersionId } = createResponse.body.data;
|
|
|
|
await authOwnerAgent
|
|
|
|
.put(`/workflows/${id}/share`)
|
|
|
|
.send({ shareWithIds: [memberPersonalProject.id] });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
// member accesses and activates workflow
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const memberGetResponse = await authMemberAgent.get(`/workflows/${id}`);
|
|
|
|
const { versionId: memberVersionId } = memberGetResponse.body.data;
|
|
|
|
await authMemberAgent
|
|
|
|
.patch(`/workflows/${id}`)
|
|
|
|
.send({ active: true, versionId: memberVersionId, name: 'Update by member' });
|
|
|
|
// owner blocked from activating workflow
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const activationAttemptResponse = await authOwnerAgent
|
|
|
|
.patch(`/workflows/${id}`)
|
|
|
|
.send({ active: true, versionId: ownerVersionId, name: 'Update by owner' });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
expect(activationAttemptResponse.status).toBe(400);
|
|
|
|
expect(activationAttemptResponse.body.code).toBe(100);
|
|
|
|
});
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
it('should block member activation on interim activation by owner', async () => {
|
|
|
|
// owner creates, updates and shares workflow
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const createResponse = await authOwnerAgent.post('/workflows').send(makeWorkflow());
|
|
|
|
const { id, versionId: ownerFirstVersionId } = createResponse.body.data;
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const updateResponse = await authOwnerAgent
|
|
|
|
.patch(`/workflows/${id}`)
|
|
|
|
.send({ name: 'Update by owner', versionId: ownerFirstVersionId });
|
|
|
|
const { versionId: ownerSecondVersionId } = updateResponse.body.data;
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
await authOwnerAgent
|
|
|
|
.put(`/workflows/${id}/share`)
|
|
|
|
.send({ shareWithIds: [memberPersonalProject.id] });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
// member accesses workflow
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const memberGetResponse = await authMemberAgent.get(`/workflows/${id}`);
|
|
|
|
const { versionId: memberVersionId } = memberGetResponse.body.data;
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
// owner activates workflow
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
await authOwnerAgent
|
|
|
|
.patch(`/workflows/${id}`)
|
|
|
|
.send({ active: true, versionId: ownerSecondVersionId, name: 'Owner update again' });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
// member blocked from activating workflow
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const updateAttemptResponse = await authMemberAgent
|
|
|
|
.patch(`/workflows/${id}`)
|
|
|
|
.send({ active: true, versionId: memberVersionId, name: 'Update by member' });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
expect(updateAttemptResponse.status).toBe(400);
|
|
|
|
expect(updateAttemptResponse.body.code).toBe(100);
|
|
|
|
});
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
it('should block member updating workflow settings on interim update by owner', async () => {
|
|
|
|
// owner creates and shares workflow
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const createResponse = await authOwnerAgent.post('/workflows').send(makeWorkflow());
|
|
|
|
const { id, versionId: ownerVersionId } = createResponse.body.data;
|
|
|
|
await authOwnerAgent
|
|
|
|
.put(`/workflows/${id}/share`)
|
|
|
|
.send({ shareWithIds: [memberPersonalProject.id] });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
// member accesses workflow
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const memberGetResponse = await authMemberAgent.get(`/workflows/${id}`);
|
|
|
|
const { versionId: memberVersionId } = memberGetResponse.body.data;
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
// owner updates workflow name
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
await authOwnerAgent
|
|
|
|
.patch(`/workflows/${id}`)
|
|
|
|
.send({ name: 'Another name', versionId: ownerVersionId });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
// member blocked from updating workflow settings
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const updateAttemptResponse = await authMemberAgent
|
|
|
|
.patch(`/workflows/${id}`)
|
|
|
|
.send({ settings: { saveManualExecutions: true }, versionId: memberVersionId });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
expect(updateAttemptResponse.status).toBe(400);
|
|
|
|
expect(updateAttemptResponse.body.code).toBe(100);
|
|
|
|
});
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
it('should block member updating workflow name on interim update by owner', async () => {
|
|
|
|
// owner creates and shares workflow
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const createResponse = await authOwnerAgent.post('/workflows').send(makeWorkflow());
|
|
|
|
const { id, versionId: ownerVersionId } = createResponse.body.data;
|
|
|
|
await authOwnerAgent
|
|
|
|
.put(`/workflows/${id}/share`)
|
|
|
|
.send({ shareWithIds: [memberPersonalProject.id] });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
// member accesses workflow
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const memberGetResponse = await authMemberAgent.get(`/workflows/${id}`).expect(200);
|
|
|
|
const { versionId: memberVersionId } = memberGetResponse.body.data;
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
// owner updates workflow settings
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
await authOwnerAgent
|
|
|
|
.patch(`/workflows/${id}`)
|
|
|
|
.send({ settings: { saveManualExecutions: true }, versionId: ownerVersionId });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
// member blocked from updating workflow name
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const updateAttemptResponse = await authMemberAgent
|
|
|
|
.patch(`/workflows/${id}`)
|
|
|
|
.send({ settings: { saveManualExecutions: true }, versionId: memberVersionId });
|
2022-10-31 02:35:24 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
expect(updateAttemptResponse.status).toBe(400);
|
|
|
|
expect(updateAttemptResponse.body.code).toBe(100);
|
|
|
|
});
|
2022-10-31 02:35:24 -07:00
|
|
|
});
|
2023-05-26 09:02:55 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
describe('workflow history', () => {
|
|
|
|
test('Should create workflow history version when licensed', async () => {
|
|
|
|
license.enable('feat:workflowHistory');
|
|
|
|
const workflow = await createWorkflow({}, owner);
|
|
|
|
const payload = {
|
|
|
|
name: 'name updated',
|
|
|
|
versionId: workflow.versionId,
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Start',
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [240, 300],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Cron',
|
|
|
|
type: 'n8n-nodes-base.cron',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [400, 300],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
connections: {},
|
|
|
|
staticData: '{"id":1}',
|
|
|
|
settings: {
|
|
|
|
saveExecutionProgress: false,
|
|
|
|
saveManualExecutions: false,
|
|
|
|
saveDataErrorExecution: 'all',
|
|
|
|
saveDataSuccessExecution: 'all',
|
|
|
|
executionTimeout: 3600,
|
|
|
|
timezone: 'America/New_York',
|
2023-10-25 03:07:11 -07:00
|
|
|
},
|
2024-06-06 02:55:48 -07:00
|
|
|
};
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const response = await authOwnerAgent.patch(`/workflows/${workflow.id}`).send(payload);
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const {
|
|
|
|
data: { id },
|
|
|
|
} = response.body;
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
expect(response.statusCode).toBe(200);
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
expect(id).toBe(workflow.id);
|
|
|
|
expect(
|
|
|
|
await Container.get(WorkflowHistoryRepository).count({ where: { workflowId: id } }),
|
|
|
|
).toBe(1);
|
|
|
|
const historyVersion = await Container.get(WorkflowHistoryRepository).findOne({
|
|
|
|
where: {
|
|
|
|
workflowId: id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(historyVersion).not.toBeNull();
|
|
|
|
expect(historyVersion!.connections).toEqual(payload.connections);
|
|
|
|
expect(historyVersion!.nodes).toEqual(payload.nodes);
|
2023-10-25 03:07:11 -07:00
|
|
|
});
|
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
test('Should not create workflow history version when not licensed', async () => {
|
|
|
|
license.disable('feat:workflowHistory');
|
|
|
|
const workflow = await createWorkflow({}, owner);
|
|
|
|
const payload = {
|
|
|
|
name: 'name updated',
|
|
|
|
versionId: workflow.versionId,
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Start',
|
|
|
|
type: 'n8n-nodes-base.start',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [240, 300],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'uuid-1234',
|
|
|
|
parameters: {},
|
|
|
|
name: 'Cron',
|
|
|
|
type: 'n8n-nodes-base.cron',
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [400, 300],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
connections: {},
|
|
|
|
staticData: '{"id":1}',
|
|
|
|
settings: {
|
|
|
|
saveExecutionProgress: false,
|
|
|
|
saveManualExecutions: false,
|
|
|
|
saveDataErrorExecution: 'all',
|
|
|
|
saveDataSuccessExecution: 'all',
|
|
|
|
executionTimeout: 3600,
|
|
|
|
timezone: 'America/New_York',
|
2023-10-25 03:07:11 -07:00
|
|
|
},
|
2024-06-06 02:55:48 -07:00
|
|
|
};
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const response = await authOwnerAgent.patch(`/workflows/${workflow.id}`).send(payload);
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const {
|
|
|
|
data: { id },
|
|
|
|
} = response.body;
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
expect(response.statusCode).toBe(200);
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
expect(id).toBe(workflow.id);
|
|
|
|
expect(
|
|
|
|
await Container.get(WorkflowHistoryRepository).count({ where: { workflowId: id } }),
|
|
|
|
).toBe(0);
|
|
|
|
});
|
2023-10-25 03:07:11 -07:00
|
|
|
});
|
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
describe('activate workflow', () => {
|
|
|
|
test('should activate workflow without changing version ID', async () => {
|
|
|
|
license.disable('feat:workflowHistory');
|
|
|
|
const workflow = await createWorkflow({}, owner);
|
|
|
|
const payload = {
|
|
|
|
versionId: workflow.versionId,
|
|
|
|
active: true,
|
|
|
|
};
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const response = await authOwnerAgent.patch(`/workflows/${workflow.id}`).send(payload);
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(activeWorkflowManager.add).toBeCalled();
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const {
|
|
|
|
data: { id, versionId, active },
|
|
|
|
} = response.body;
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
expect(id).toBe(workflow.id);
|
|
|
|
expect(versionId).toBe(workflow.versionId);
|
|
|
|
expect(active).toBe(true);
|
|
|
|
});
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
test('should deactivate workflow without changing version ID', async () => {
|
|
|
|
license.disable('feat:workflowHistory');
|
|
|
|
const workflow = await createWorkflow({ active: true }, owner);
|
|
|
|
const payload = {
|
|
|
|
versionId: workflow.versionId,
|
|
|
|
active: false,
|
|
|
|
};
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const response = await authOwnerAgent.patch(`/workflows/${workflow.id}`).send(payload);
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(activeWorkflowManager.add).not.toBeCalled();
|
|
|
|
expect(activeWorkflowManager.remove).toBeCalled();
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
const {
|
|
|
|
data: { id, versionId, active },
|
|
|
|
} = response.body;
|
2023-10-25 03:07:11 -07:00
|
|
|
|
2024-06-06 02:55:48 -07:00
|
|
|
expect(id).toBe(workflow.id);
|
|
|
|
expect(versionId).toBe(workflow.versionId);
|
|
|
|
expect(active).toBe(false);
|
|
|
|
});
|
2023-10-25 03:07:11 -07:00
|
|
|
});
|
|
|
|
});
|
2024-06-03 07:57:04 -07:00
|
|
|
|
|
|
|
describe('PUT /:workflowId/transfer', () => {
|
|
|
|
test('cannot transfer into the same project', async () => {
|
|
|
|
const destinationProject = await createTeamProject('Team Project', member);
|
|
|
|
|
|
|
|
const workflow = await createWorkflow({}, destinationProject);
|
|
|
|
|
|
|
|
await testServer
|
|
|
|
.authAgentFor(member)
|
|
|
|
.put(`/workflows/${workflow.id}/transfer`)
|
|
|
|
.send({ destinationProjectId: destinationProject.id })
|
|
|
|
.expect(400);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('cannot transfer into a personal project', async () => {
|
2024-06-04 04:54:48 -07:00
|
|
|
const sourceProject = await createTeamProject('Team Project', member);
|
2024-06-03 07:57:04 -07:00
|
|
|
|
2024-06-04 04:54:48 -07:00
|
|
|
const workflow = await createWorkflow({}, sourceProject);
|
2024-06-03 07:57:04 -07:00
|
|
|
|
|
|
|
await testServer
|
|
|
|
.authAgentFor(member)
|
|
|
|
.put(`/workflows/${workflow.id}/transfer`)
|
|
|
|
.send({ destinationProjectId: memberPersonalProject.id })
|
|
|
|
.expect(400);
|
|
|
|
});
|
|
|
|
|
2024-06-04 04:54:48 -07:00
|
|
|
test('cannot transfer somebody elses workflow', async () => {
|
2024-06-03 07:57:04 -07:00
|
|
|
const destinationProject = await createTeamProject('Team Project', member);
|
|
|
|
|
|
|
|
const workflow = await createWorkflow({}, anotherMember);
|
|
|
|
|
|
|
|
await testServer
|
|
|
|
.authAgentFor(member)
|
|
|
|
.put(`/workflows/${workflow.id}/transfer`)
|
|
|
|
.send({ destinationProjectId: destinationProject.id })
|
|
|
|
.expect(403);
|
|
|
|
});
|
|
|
|
|
2024-06-04 04:54:48 -07:00
|
|
|
test("cannot transfer if you're not a member of the destination project", async () => {
|
2024-06-03 07:57:04 -07:00
|
|
|
const destinationProject = await createTeamProject('Team Project', anotherMember);
|
|
|
|
|
|
|
|
const workflow = await createWorkflow({}, member);
|
|
|
|
|
|
|
|
await testServer
|
|
|
|
.authAgentFor(member)
|
|
|
|
.put(`/workflows/${workflow.id}/transfer`)
|
|
|
|
.send({ destinationProjectId: destinationProject.id })
|
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('project:editors cannot transfer workflows', async () => {
|
|
|
|
//
|
|
|
|
// ARRANGE
|
|
|
|
//
|
2024-06-04 04:54:48 -07:00
|
|
|
const sourceProject = await createTeamProject();
|
2024-06-03 07:57:04 -07:00
|
|
|
await linkUserToProject(member, sourceProject, 'project:editor');
|
|
|
|
|
|
|
|
const workflow = await createWorkflow({}, sourceProject);
|
|
|
|
|
2024-06-04 04:54:48 -07:00
|
|
|
const destinationProject = await createTeamProject();
|
|
|
|
await linkUserToProject(member, destinationProject, 'project:admin');
|
|
|
|
|
2024-06-03 07:57:04 -07:00
|
|
|
//
|
|
|
|
// ACT & ASSERT
|
|
|
|
//
|
|
|
|
await testServer
|
|
|
|
.authAgentFor(member)
|
|
|
|
.put(`/workflows/${workflow.id}/transfer`)
|
|
|
|
.send({ destinationProjectId: destinationProject.id })
|
|
|
|
.expect(403);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('transferring from a personal project to a team project severs all sharings', async () => {
|
|
|
|
//
|
|
|
|
// ARRANGE
|
|
|
|
//
|
|
|
|
const workflow = await createWorkflow({}, member);
|
|
|
|
|
2024-06-04 04:54:48 -07:00
|
|
|
// these sharings should be deleted by the transfer
|
2024-06-03 07:57:04 -07:00
|
|
|
await shareWorkflowWithUsers(workflow, [anotherMember, owner]);
|
|
|
|
|
|
|
|
const destinationProject = await createTeamProject('Team Project', member);
|
|
|
|
|
|
|
|
//
|
|
|
|
// ACT
|
|
|
|
//
|
|
|
|
const response = await testServer
|
|
|
|
.authAgentFor(member)
|
|
|
|
.put(`/workflows/${workflow.id}/transfer`)
|
|
|
|
.send({ destinationProjectId: destinationProject.id })
|
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
//
|
|
|
|
// ASSERT
|
|
|
|
//
|
|
|
|
expect(response.body).toEqual({});
|
|
|
|
|
|
|
|
const allSharings = await getWorkflowSharing(workflow);
|
|
|
|
expect(allSharings).toHaveLength(1);
|
2024-06-04 04:54:48 -07:00
|
|
|
expect(allSharings[0]).toMatchObject({
|
2024-06-03 07:57:04 -07:00
|
|
|
projectId: destinationProject.id,
|
|
|
|
workflowId: workflow.id,
|
|
|
|
role: 'workflow:owner',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('can transfer from team to another team project', async () => {
|
|
|
|
//
|
|
|
|
// ARRANGE
|
|
|
|
//
|
|
|
|
const sourceProject = await createTeamProject('Team Project 1', member);
|
|
|
|
const workflow = await createWorkflow({}, sourceProject);
|
|
|
|
|
2024-06-04 04:54:48 -07:00
|
|
|
const destinationProject = await createTeamProject('Team Project 2', member);
|
|
|
|
|
2024-06-03 07:57:04 -07:00
|
|
|
//
|
|
|
|
// ACT
|
|
|
|
//
|
|
|
|
const response = await testServer
|
|
|
|
.authAgentFor(member)
|
|
|
|
.put(`/workflows/${workflow.id}/transfer`)
|
|
|
|
.send({ destinationProjectId: destinationProject.id })
|
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
//
|
|
|
|
// ASSERT
|
|
|
|
//
|
|
|
|
expect(response.body).toEqual({});
|
|
|
|
|
|
|
|
const allSharings = await getWorkflowSharing(workflow);
|
|
|
|
expect(allSharings).toHaveLength(1);
|
|
|
|
expect(allSharings[0]).toMatchObject({
|
|
|
|
projectId: destinationProject.id,
|
|
|
|
workflowId: workflow.id,
|
|
|
|
role: 'workflow:owner',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test.each([
|
|
|
|
['owners', () => owner],
|
|
|
|
['admins', () => admin],
|
|
|
|
])(
|
|
|
|
'global %s can always transfer from any personal or team project into any team project',
|
|
|
|
async (_name, actor) => {
|
|
|
|
//
|
|
|
|
// ARRANGE
|
|
|
|
//
|
|
|
|
const sourceProject = await createTeamProject('Source Project', member);
|
|
|
|
const teamWorkflow = await createWorkflow({}, sourceProject);
|
2024-06-04 04:54:48 -07:00
|
|
|
|
2024-06-03 07:57:04 -07:00
|
|
|
const personalWorkflow = await createWorkflow({}, member);
|
|
|
|
|
2024-06-04 04:54:48 -07:00
|
|
|
const destinationProject = await createTeamProject('Destination Project', member);
|
|
|
|
|
2024-06-03 07:57:04 -07:00
|
|
|
//
|
|
|
|
// ACT
|
|
|
|
//
|
|
|
|
const response1 = await testServer
|
|
|
|
.authAgentFor(actor())
|
|
|
|
.put(`/workflows/${teamWorkflow.id}/transfer`)
|
|
|
|
.send({ destinationProjectId: destinationProject.id })
|
|
|
|
.expect(200);
|
|
|
|
const response2 = await testServer
|
|
|
|
.authAgentFor(actor())
|
|
|
|
.put(`/workflows/${personalWorkflow.id}/transfer`)
|
|
|
|
.send({ destinationProjectId: destinationProject.id })
|
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
//
|
|
|
|
// ASSERT
|
|
|
|
//
|
|
|
|
expect(response1.body).toEqual({});
|
|
|
|
expect(response2.body).toEqual({});
|
|
|
|
|
|
|
|
{
|
|
|
|
const allSharings = await getWorkflowSharing(teamWorkflow);
|
|
|
|
expect(allSharings).toHaveLength(1);
|
|
|
|
expect(allSharings[0]).toMatchObject({
|
|
|
|
projectId: destinationProject.id,
|
|
|
|
workflowId: teamWorkflow.id,
|
|
|
|
role: 'workflow:owner',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const allSharings = await getWorkflowSharing(personalWorkflow);
|
|
|
|
expect(allSharings).toHaveLength(1);
|
|
|
|
expect(allSharings[0]).toMatchObject({
|
|
|
|
projectId: destinationProject.id,
|
|
|
|
workflowId: personalWorkflow.id,
|
|
|
|
role: 'workflow:owner',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
test.each([
|
|
|
|
['owners', () => owner],
|
|
|
|
['admins', () => admin],
|
|
|
|
])('global %s cannot transfer into personal projects', async (_name, actor) => {
|
|
|
|
//
|
|
|
|
// ARRANGE
|
|
|
|
//
|
|
|
|
const sourceProject = await createTeamProject('Source Project', member);
|
|
|
|
const teamWorkflow = await createWorkflow({}, sourceProject);
|
2024-06-04 04:54:48 -07:00
|
|
|
|
2024-06-03 07:57:04 -07:00
|
|
|
const personalWorkflow = await createWorkflow({}, member);
|
|
|
|
|
2024-06-04 04:54:48 -07:00
|
|
|
const destinationProject = anotherMemberPersonalProject;
|
|
|
|
|
2024-06-03 07:57:04 -07:00
|
|
|
//
|
|
|
|
// ACT & ASSERT
|
|
|
|
//
|
|
|
|
await testServer
|
|
|
|
.authAgentFor(actor())
|
|
|
|
.put(`/workflows/${teamWorkflow.id}/transfer`)
|
|
|
|
.send({ destinationProjectId: destinationProject.id })
|
|
|
|
.expect(400);
|
|
|
|
await testServer
|
|
|
|
.authAgentFor(actor())
|
|
|
|
.put(`/workflows/${personalWorkflow.id}/transfer`)
|
|
|
|
.send({ destinationProjectId: destinationProject.id })
|
|
|
|
.expect(400);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('removes and re-adds the workflow from the active workflow manager during the transfer', async () => {
|
|
|
|
//
|
|
|
|
// ARRANGE
|
|
|
|
//
|
|
|
|
const destinationProject = await createTeamProject('Team Project', member);
|
|
|
|
|
|
|
|
const workflow = await createWorkflow({ active: true }, member);
|
|
|
|
|
|
|
|
//
|
|
|
|
// ACT
|
|
|
|
//
|
|
|
|
const response = await testServer
|
|
|
|
.authAgentFor(member)
|
|
|
|
.put(`/workflows/${workflow.id}/transfer`)
|
|
|
|
.send({ destinationProjectId: destinationProject.id })
|
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
//
|
|
|
|
// ASSERT
|
|
|
|
//
|
|
|
|
expect(response.body).toEqual({});
|
|
|
|
|
|
|
|
expect(activeWorkflowManager.remove).toHaveBeenCalledWith(workflow.id);
|
|
|
|
expect(activeWorkflowManager.add).toHaveBeenCalledWith(workflow.id, 'update');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('deactivates the workflow if it cannot be added to the active workflow manager again and returns the WorkflowActivationError as data', async () => {
|
|
|
|
//
|
|
|
|
// ARRANGE
|
|
|
|
//
|
|
|
|
const destinationProject = await createTeamProject('Team Project', member);
|
|
|
|
|
|
|
|
const workflow = await createWorkflow({ active: true }, member);
|
|
|
|
|
|
|
|
activeWorkflowManager.add.mockRejectedValue(new WorkflowActivationError('Failed'));
|
|
|
|
|
|
|
|
//
|
|
|
|
// ACT
|
|
|
|
//
|
|
|
|
const response = await testServer
|
|
|
|
.authAgentFor(member)
|
|
|
|
.put(`/workflows/${workflow.id}/transfer`)
|
|
|
|
.send({ destinationProjectId: destinationProject.id })
|
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
//
|
|
|
|
// ASSERT
|
|
|
|
//
|
|
|
|
expect(response.body).toMatchObject({
|
|
|
|
data: {
|
|
|
|
error: {
|
|
|
|
message: 'Failed',
|
|
|
|
name: 'WorkflowActivationError',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(activeWorkflowManager.remove).toHaveBeenCalledWith(workflow.id);
|
|
|
|
expect(activeWorkflowManager.add).toHaveBeenCalledWith(workflow.id, 'update');
|
|
|
|
|
|
|
|
const workflowFromDB = await workflowRepository.findOneByOrFail({ id: workflow.id });
|
|
|
|
expect(workflowFromDB).toMatchObject({ active: false });
|
|
|
|
});
|
|
|
|
|
|
|
|
test('returns a 500 if the workflow cannot be activated due to an unknown error', async () => {
|
|
|
|
//
|
|
|
|
// ARRANGE
|
|
|
|
//
|
|
|
|
const destinationProject = await createTeamProject('Team Project', member);
|
|
|
|
|
|
|
|
const workflow = await createWorkflow({ active: true }, member);
|
|
|
|
|
|
|
|
activeWorkflowManager.add.mockRejectedValue(new ApplicationError('Oh no!'));
|
|
|
|
|
|
|
|
//
|
|
|
|
// ACT & ASSERT
|
|
|
|
//
|
|
|
|
await testServer
|
|
|
|
.authAgentFor(member)
|
|
|
|
.put(`/workflows/${workflow.id}/transfer`)
|
|
|
|
.send({ destinationProjectId: destinationProject.id })
|
|
|
|
.expect(500);
|
|
|
|
});
|
|
|
|
});
|
2024-06-06 02:55:48 -07:00
|
|
|
|
|
|
|
describe('POST /workflows/:workflowId/run', () => {
|
|
|
|
test('project viewers cannot run workflows', async () => {
|
|
|
|
const teamProject = await createTeamProject();
|
|
|
|
await linkUserToProject(member, teamProject, 'project:viewer');
|
|
|
|
|
|
|
|
const workflow = await createWorkflow({}, teamProject);
|
|
|
|
|
|
|
|
const response = await authMemberAgent
|
|
|
|
.post(`/workflows/${workflow.id}/run`)
|
|
|
|
.send({ workflowData: workflow });
|
|
|
|
|
|
|
|
expect(response.status).toBe(403);
|
|
|
|
expect(response.body).toMatchObject({
|
|
|
|
message: 'User is missing a scope required to perform this action',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|