fix(core): revert blocking workflow updates on interim changes (no-changelog) (#4396)

 Revert "feat(core): block workflow update on interim change (#4374)"

This reverts commit e83b9bd983.
This commit is contained in:
Iván Ovejero
2022-10-20 17:55:21 +02:00
committed by GitHub
parent ef1198324d
commit 69848b54db
8 changed files with 8 additions and 116 deletions

View File

@@ -56,12 +56,7 @@ export declare namespace WorkflowRequest {
type Delete = Get;
type Update = AuthenticatedRequest<
{ id: string },
{},
RequestBody & { updatedAt: string },
{ forceSave?: string }
>;
type Update = AuthenticatedRequest<{ id: string }, {}, RequestBody>;
type NewName = AuthenticatedRequest<{}, {}, {}, { name?: string }>;

View File

@@ -329,7 +329,6 @@ workflowsController.patch(
`/:id`,
ResponseHelper.send(async (req: WorkflowRequest.Update) => {
const { id: workflowId } = req.params;
const { forceSave } = req.query;
const updateData = new WorkflowEntity();
const { tags, ...rest } = req.body;
@@ -356,22 +355,6 @@ workflowsController.patch(
);
}
const lastKnownDate = new Date(req.body.updatedAt).getTime();
const storedDate = new Date(shared.workflow.updatedAt).getTime();
if (!forceSave && lastKnownDate !== storedDate) {
LoggerProxy.info(
'User was blocked from updating a workflow that was changed by another user',
{ workflowId, userId: req.user.id },
);
throw new ResponseHelper.ResponseError(
`Workflow ID ${workflowId} cannot be saved because it was changed by another user.`,
undefined,
400,
);
}
// check credentials for old format
await WorkflowHelpers.replaceInvalidCredentials(updateData);

View File

@@ -706,7 +706,10 @@ export const emptyPackage = () => {
// workflow
// ----------------------------------
export function makeWorkflow(options?: {
export function makeWorkflow({
withPinData,
withCredential,
}: {
withPinData: boolean;
withCredential?: { id: string; name: string };
}) {
@@ -721,9 +724,9 @@ export function makeWorkflow(options?: {
position: [740, 240],
};
if (options?.withCredential) {
if (withCredential) {
node.credentials = {
spotifyApi: options.withCredential,
spotifyApi: withCredential,
};
}
@@ -732,7 +735,7 @@ export function makeWorkflow(options?: {
workflow.connections = {};
workflow.nodes = [node];
if (options?.withPinData) {
if (withPinData) {
workflow.pinData = MOCK_PINDATA;
}

View File

@@ -294,78 +294,4 @@ describe('POST /workflows', () => {
const usedCredentials = await testDb.getCredentialUsageInWorkflow(response.body.data.id);
expect(usedCredentials).toHaveLength(1);
});
it('PATCH /workflows/:id should be blocked on interim change - owner blocked', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
const member = await testDb.createUser({ globalRole: globalMemberRole });
// owner creates and shares workflow
const createResponse = await authAgent(owner).post('/workflows').send(makeWorkflow());
const { id, updatedAt: ownerLastKnownDate } = createResponse.body.data;
await authAgent(owner)
.put(`/workflows/${id}/share`)
.send({ shareWithIds: [member.id] });
// member accesses and updates workflow
const memberGetResponse = await authAgent(member).get(`/workflows/${id}`);
const { updatedAt: memberLastKnownDate } = memberGetResponse.body.data;
await authAgent(member)
.patch(`/workflows/${id}`)
.send({ name: 'Update by member', updatedAt: memberLastKnownDate });
// owner blocked from updating workflow
const updateAttemptResponse = await authAgent(owner)
.patch(`/workflows/${id}`)
.send({ name: 'Update attempt by owner', updatedAt: ownerLastKnownDate });
expect(updateAttemptResponse.status).toBe(400);
expect(updateAttemptResponse.body.message).toContain(
'cannot be saved because it was changed by another user',
);
});
it('PATCH /workflows/:id should be blocked on interim change - member blocked', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
const member = await testDb.createUser({ globalRole: globalMemberRole });
// owner creates, updates and shares workflow
const createResponse = await authAgent(owner).post('/workflows').send(makeWorkflow());
const { id, updatedAt: ownerFirstUpdateDate } = createResponse.body.data;
const updateResponse = await authAgent(owner)
.patch(`/workflows/${id}`)
.send({ name: 'Update by owner', updatedAt: ownerFirstUpdateDate });
const { updatedAt: ownerSecondUpdateDate } = updateResponse.body.data;
await authAgent(owner)
.put(`/workflows/${id}/share`)
.send({ shareWithIds: [member.id] });
// member accesses workflow
const memberGetResponse = await authAgent(member).get(`/workflows/${id}`);
const { updatedAt: memberLastKnownDate } = memberGetResponse.body.data;
// owner re-updates workflow
await authAgent(owner)
.patch(`/workflows/${id}`)
.send({ name: 'Owner update again', updatedAt: ownerSecondUpdateDate });
// member blocked from updating workflow
const updateAttemptResponse = await authAgent(member)
.patch(`/workflows/${id}`)
.send({ name: 'Update attempt by member', updatedAt: memberLastKnownDate });
expect(updateAttemptResponse.status).toBe(400);
expect(updateAttemptResponse.body.message).toContain(
'cannot be saved because it was changed by another user',
);
});
});