mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(core): revert blocking workflow update on interim change (#4437)
⏪ Revert "feat(core): block workflow update on interim change (#4397)"
This reverts commit cddd012a2f
.
This commit is contained in:
parent
b296fb06f3
commit
07adc2d2dc
7
packages/cli/src/requests.d.ts
vendored
7
packages/cli/src/requests.d.ts
vendored
|
@ -56,12 +56,7 @@ export declare namespace WorkflowRequest {
|
||||||
|
|
||||||
type Delete = Get;
|
type Delete = Get;
|
||||||
|
|
||||||
type Update = AuthenticatedRequest<
|
type Update = AuthenticatedRequest<{ id: string }, {}, RequestBody>;
|
||||||
{ id: string },
|
|
||||||
{},
|
|
||||||
RequestBody & { updatedAt: string },
|
|
||||||
{ forceSave?: string }
|
|
||||||
>;
|
|
||||||
|
|
||||||
type NewName = AuthenticatedRequest<{}, {}, {}, { name?: string }>;
|
type NewName = AuthenticatedRequest<{}, {}, {}, { name?: string }>;
|
||||||
|
|
||||||
|
|
|
@ -329,7 +329,6 @@ workflowsController.patch(
|
||||||
`/:id`,
|
`/:id`,
|
||||||
ResponseHelper.send(async (req: WorkflowRequest.Update) => {
|
ResponseHelper.send(async (req: WorkflowRequest.Update) => {
|
||||||
const { id: workflowId } = req.params;
|
const { id: workflowId } = req.params;
|
||||||
const { forceSave } = req.query;
|
|
||||||
|
|
||||||
const updateData = new WorkflowEntity();
|
const updateData = new WorkflowEntity();
|
||||||
const { tags, ...rest } = req.body;
|
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
|
// check credentials for old format
|
||||||
await WorkflowHelpers.replaceInvalidCredentials(updateData);
|
await WorkflowHelpers.replaceInvalidCredentials(updateData);
|
||||||
|
|
||||||
|
|
|
@ -706,7 +706,10 @@ export const emptyPackage = () => {
|
||||||
// workflow
|
// workflow
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
export function makeWorkflow(options?: {
|
export function makeWorkflow({
|
||||||
|
withPinData,
|
||||||
|
withCredential,
|
||||||
|
}: {
|
||||||
withPinData: boolean;
|
withPinData: boolean;
|
||||||
withCredential?: { id: string; name: string };
|
withCredential?: { id: string; name: string };
|
||||||
}) {
|
}) {
|
||||||
|
@ -721,9 +724,9 @@ export function makeWorkflow(options?: {
|
||||||
position: [740, 240],
|
position: [740, 240],
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options?.withCredential) {
|
if (withCredential) {
|
||||||
node.credentials = {
|
node.credentials = {
|
||||||
spotifyApi: options.withCredential,
|
spotifyApi: withCredential,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -732,7 +735,7 @@ export function makeWorkflow(options?: {
|
||||||
workflow.connections = {};
|
workflow.connections = {};
|
||||||
workflow.nodes = [node];
|
workflow.nodes = [node];
|
||||||
|
|
||||||
if (options?.withPinData) {
|
if (withPinData) {
|
||||||
workflow.pinData = MOCK_PINDATA;
|
workflow.pinData = MOCK_PINDATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -295,153 +295,3 @@ describe('POST /workflows', () => {
|
||||||
expect(usedCredentials).toHaveLength(1);
|
expect(usedCredentials).toHaveLength(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('PATCH /workflows/:id', () => {
|
|
||||||
it('should block owner update on interim update by member', 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('should block member update on interim update by owner', 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',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should block owner activation on interim activation by member', 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 activates workflow
|
|
||||||
|
|
||||||
const memberGetResponse = await authAgent(member).get(`/workflows/${id}`);
|
|
||||||
const { updatedAt: memberLastKnownDate } = memberGetResponse.body.data;
|
|
||||||
|
|
||||||
await authAgent(member)
|
|
||||||
.patch(`/workflows/${id}`)
|
|
||||||
.send({ active: true, updatedAt: memberLastKnownDate });
|
|
||||||
|
|
||||||
// owner blocked from activating workflow
|
|
||||||
|
|
||||||
const activationAttemptResponse = await authAgent(owner)
|
|
||||||
.patch(`/workflows/${id}`)
|
|
||||||
.send({ active: true, updatedAt: ownerLastKnownDate });
|
|
||||||
|
|
||||||
expect(activationAttemptResponse.status).toBe(400);
|
|
||||||
expect(activationAttemptResponse.body.message).toContain(
|
|
||||||
'cannot be saved because it was changed by another user',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should block member activation on interim activation by owner', 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 activates workflow
|
|
||||||
|
|
||||||
await authAgent(owner)
|
|
||||||
.patch(`/workflows/${id}`)
|
|
||||||
.send({ active: true, updatedAt: ownerSecondUpdateDate });
|
|
||||||
|
|
||||||
// member blocked from activating workflow
|
|
||||||
|
|
||||||
const updateAttemptResponse = await authAgent(member)
|
|
||||||
.patch(`/workflows/${id}`)
|
|
||||||
.send({ active: true, updatedAt: memberLastKnownDate });
|
|
||||||
|
|
||||||
expect(updateAttemptResponse.status).toBe(400);
|
|
||||||
expect(updateAttemptResponse.body.message).toContain(
|
|
||||||
'cannot be saved because it was changed by another user',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
|
@ -268,7 +268,6 @@ export interface IWorkflowData {
|
||||||
settings?: IWorkflowSettings;
|
settings?: IWorkflowSettings;
|
||||||
tags?: string[];
|
tags?: string[];
|
||||||
pinData?: IPinData;
|
pinData?: IPinData;
|
||||||
updatedAt?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IWorkflowDataUpdate {
|
export interface IWorkflowDataUpdate {
|
||||||
|
@ -280,7 +279,6 @@ export interface IWorkflowDataUpdate {
|
||||||
active?: boolean;
|
active?: boolean;
|
||||||
tags?: ITag[] | string[]; // string[] when store or requested, ITag[] from API response
|
tags?: ITag[] | string[]; // string[] when store or requested, ITag[] from API response
|
||||||
pinData?: IPinData;
|
pinData?: IPinData;
|
||||||
updatedAt?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IWorkflowToShare extends IWorkflowDataUpdate {
|
export interface IWorkflowToShare extends IWorkflowDataUpdate {
|
||||||
|
|
|
@ -10,15 +10,7 @@
|
||||||
</template>
|
</template>
|
||||||
<div :class="$style.cardDescription">
|
<div :class="$style.cardDescription">
|
||||||
<n8n-text color="text-light" size="small">
|
<n8n-text color="text-light" size="small">
|
||||||
<span v-show="data">
|
<span v-show="data">{{$locale.baseText('workflows.item.updated')}} <time-ago :date="data.updatedAt" /> | </span>
|
||||||
<span v-if="data.updatedAt === -1">
|
|
||||||
{{ $locale.baseText('workflows.item.neverUpdated') }} |
|
|
||||||
</span>
|
|
||||||
<span v-else>
|
|
||||||
{{ $locale.baseText('workflows.item.updated') }}
|
|
||||||
<time-ago :date="data.updatedAt" /> |
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
<span v-show="data" class="mr-2xs">{{$locale.baseText('workflows.item.created')}} {{ formattedCreatedAtDate }} </span>
|
<span v-show="data" class="mr-2xs">{{$locale.baseText('workflows.item.created')}} {{ formattedCreatedAtDate }} </span>
|
||||||
<span v-if="areTagsEnabled && data.tags && data.tags.length > 0" v-show="data">
|
<span v-if="areTagsEnabled && data.tags && data.tags.length > 0" v-show="data">
|
||||||
<n8n-tags
|
<n8n-tags
|
||||||
|
|
|
@ -519,8 +519,7 @@ export default mixins(
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const workflow = await this.restApi().updateWorkflow(this.$route.params.name, data);
|
await this.restApi().updateWorkflow(this.$route.params.name, data);
|
||||||
this.$store.commit('setWorkflowUpdatedAt', workflow.updatedAt);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$showError(
|
this.$showError(
|
||||||
error,
|
error,
|
||||||
|
|
|
@ -400,7 +400,6 @@ export const workflowHelpers = mixins(
|
||||||
active: this.$store.getters.isActive,
|
active: this.$store.getters.isActive,
|
||||||
settings: this.$store.getters.workflowSettings,
|
settings: this.$store.getters.workflowSettings,
|
||||||
tags: this.$store.getters.workflowTags,
|
tags: this.$store.getters.workflowTags,
|
||||||
updatedAt: this.$store.getters.workflowUpdatedAt,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const workflowId = this.$store.getters.workflowId;
|
const workflowId = this.$store.getters.workflowId;
|
||||||
|
@ -661,9 +660,6 @@ export const workflowHelpers = mixins(
|
||||||
const isCurrentWorkflow = workflowId === this.$store.getters.workflowId;
|
const isCurrentWorkflow = workflowId === this.$store.getters.workflowId;
|
||||||
if (isCurrentWorkflow) {
|
if (isCurrentWorkflow) {
|
||||||
data = await this.getWorkflowDataToSave();
|
data = await this.getWorkflowDataToSave();
|
||||||
} else {
|
|
||||||
const { updatedAt } = await this.restApi().getWorkflow(workflowId);
|
|
||||||
data.updatedAt = updatedAt as string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (active !== undefined) {
|
if (active !== undefined) {
|
||||||
|
@ -671,7 +667,6 @@ export const workflowHelpers = mixins(
|
||||||
}
|
}
|
||||||
|
|
||||||
const workflow = await this.restApi().updateWorkflow(workflowId, data);
|
const workflow = await this.restApi().updateWorkflow(workflowId, data);
|
||||||
this.$store.commit('setWorkflowUpdatedAt', workflow.updatedAt);
|
|
||||||
|
|
||||||
if (isCurrentWorkflow) {
|
if (isCurrentWorkflow) {
|
||||||
this.$store.commit('setActive', !!workflow.active);
|
this.$store.commit('setActive', !!workflow.active);
|
||||||
|
@ -719,7 +714,6 @@ export const workflowHelpers = mixins(
|
||||||
|
|
||||||
this.$store.commit('setStateDirty', false);
|
this.$store.commit('setStateDirty', false);
|
||||||
this.$store.commit('removeActiveAction', 'workflowSaving');
|
this.$store.commit('removeActiveAction', 'workflowSaving');
|
||||||
this.$store.commit('setWorkflowUpdatedAt', workflowData.updatedAt);
|
|
||||||
this.$externalHooks().run('workflow.afterUpdate', { workflowData });
|
this.$externalHooks().run('workflow.afterUpdate', { workflowData });
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1287,7 +1287,6 @@
|
||||||
"workflows.item.open": "Open",
|
"workflows.item.open": "Open",
|
||||||
"workflows.item.duplicate": "Duplicate",
|
"workflows.item.duplicate": "Duplicate",
|
||||||
"workflows.item.delete": "Delete",
|
"workflows.item.delete": "Delete",
|
||||||
"workflows.item.neverUpdated": "Never updated",
|
|
||||||
"workflows.item.updated": "Last updated",
|
"workflows.item.updated": "Last updated",
|
||||||
"workflows.item.created": "Created",
|
"workflows.item.created": "Created",
|
||||||
"workflows.item.owner": "Owner",
|
"workflows.item.owner": "Owner",
|
||||||
|
|
|
@ -465,13 +465,6 @@ export const store = new Vuex.Store({
|
||||||
state.workflow.id = id;
|
state.workflow.id = id;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* @warning Do not mutate `updatedAt` in `state.workflow` client-side.
|
|
||||||
*/
|
|
||||||
setWorkflowUpdatedAt (state, updatedAt: string) {
|
|
||||||
state.workflow.updatedAt = updatedAt;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Name
|
// Name
|
||||||
setWorkflowName(state, data) {
|
setWorkflowName(state, data) {
|
||||||
if (data.setStateDirty === true) {
|
if (data.setStateDirty === true) {
|
||||||
|
@ -1015,9 +1008,6 @@ export const store = new Vuex.Store({
|
||||||
workflowId: (state): string => {
|
workflowId: (state): string => {
|
||||||
return state.workflow.id;
|
return state.workflow.id;
|
||||||
},
|
},
|
||||||
workflowUpdatedAt (state): string | number {
|
|
||||||
return state.workflow.updatedAt;
|
|
||||||
},
|
|
||||||
|
|
||||||
workflowSettings: (state): IWorkflowSettings => {
|
workflowSettings: (state): IWorkflowSettings => {
|
||||||
if (state.workflow.settings === undefined) {
|
if (state.workflow.settings === undefined) {
|
||||||
|
|
|
@ -715,7 +715,6 @@ export default mixins(
|
||||||
|
|
||||||
this.$store.commit('setActive', data.active || false);
|
this.$store.commit('setActive', data.active || false);
|
||||||
this.$store.commit('setWorkflowId', workflowId);
|
this.$store.commit('setWorkflowId', workflowId);
|
||||||
this.$store.commit('setWorkflowUpdatedAt', data.updatedAt);
|
|
||||||
this.$store.commit('setWorkflowName', { newName: data.name, setStateDirty: false });
|
this.$store.commit('setWorkflowName', { newName: data.name, setStateDirty: false });
|
||||||
this.$store.commit('setWorkflowSettings', data.settings || {});
|
this.$store.commit('setWorkflowSettings', data.settings || {});
|
||||||
this.$store.commit('setWorkflowPinData', data.pinData || {});
|
this.$store.commit('setWorkflowPinData', data.pinData || {});
|
||||||
|
|
Loading…
Reference in a new issue