From 51a55dd8038a2db99274cd401fa50500b68465ff Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Thu, 12 Dec 2024 14:07:34 +0500 Subject: [PATCH] fix change issue status when change assignee (#7438) Signed-off-by: Denis Bykhov --- server-plugins/time-resources/src/index.ts | 85 ++++++++++++---------- server-plugins/time/src/index.ts | 6 +- 2 files changed, 50 insertions(+), 41 deletions(-) diff --git a/server-plugins/time-resources/src/index.ts b/server-plugins/time-resources/src/index.ts index b502e6d49f..632237b1df 100644 --- a/server-plugins/time-resources/src/index.ts +++ b/server-plugins/time-resources/src/index.ts @@ -405,7 +405,7 @@ export async function OnToDoUpdate (txes: Tx[], control: TriggerControl): Promis ) if (funcs !== undefined) { const func = await getResource(funcs.onDone) - const todoRes = await func(control, resEvents, todo) + const todoRes = await func(control, resEvents, todo, tx.space === core.space.DerivedTx) await control.apply(control.ctx, todoRes) } continue @@ -459,7 +459,12 @@ export async function IssueToDoFactory (actualTx: TxCUD, control: Trigger /** * @public */ -export async function IssueToDoDone (control: TriggerControl, workslots: WorkSlot[], todo: ToDo): Promise { +export async function IssueToDoDone ( + control: TriggerControl, + workslots: WorkSlot[], + todo: ToDo, + isDerived: boolean +): Promise { const res: Tx[] = [] let total = 0 for (const workslot of workslots) { @@ -470,45 +475,47 @@ export async function IssueToDoDone (control: TriggerControl, workslots: WorkSlo await control.findAll(control.ctx, todo.attachedToClass, { _id: todo.attachedTo as Ref }) )[0] if (issue !== undefined) { - const project = (await control.findAll(control.ctx, task.class.Project, { _id: issue.space }))[0] - if (project !== undefined) { - const type = (await control.modelDb.findAll(task.class.ProjectType, { _id: project.type }))[0] - if (type?.classic) { - const taskType = (await control.modelDb.findAll(task.class.TaskType, { _id: issue.kind }))[0] - if (taskType !== undefined) { - const index = taskType.statuses.findIndex((p) => p === issue.status) + if (!isDerived) { + const project = (await control.findAll(control.ctx, task.class.Project, { _id: issue.space }))[0] + if (project !== undefined) { + const type = (await control.modelDb.findAll(task.class.ProjectType, { _id: project.type }))[0] + if (type?.classic) { + const taskType = (await control.modelDb.findAll(task.class.TaskType, { _id: issue.kind }))[0] + if (taskType !== undefined) { + const index = taskType.statuses.findIndex((p) => p === issue.status) - const helpers = await control.modelDb.findAll(time.class.TodoAutomationHelper, {}) - const testers = await Promise.all(helpers.map((it) => getResource(it.onDoneTester))) - let allowed = true - for (const tester of testers) { - if (!(await tester(control, todo))) { - allowed = false - break + const helpers = await control.modelDb.findAll(time.class.TodoAutomationHelper, {}) + const testers = await Promise.all(helpers.map((it) => getResource(it.onDoneTester))) + let allowed = true + for (const tester of testers) { + if (!(await tester(control, todo))) { + allowed = false + break + } } - } - if (index !== -1 && allowed) { - const nextStatus = taskType.statuses[index + 1] - if (nextStatus !== undefined) { - const currentStatus = taskType.statuses[index] - const current = (await control.modelDb.findAll(core.class.Status, { _id: currentStatus }))[0] - const next = (await control.modelDb.findAll(core.class.Status, { _id: nextStatus }))[0] - if ( - current.category !== task.statusCategory.Lost && - next.category !== task.statusCategory.Lost && - current.category !== task.statusCategory.Won - ) { - const innerTx = factory.createTxUpdateDoc(issue._class, issue.space, issue._id, { - status: nextStatus - }) - const outerTx = factory.createTxCollectionCUD( - issue.attachedToClass, - issue.attachedTo, - issue.space, - issue.collection, - innerTx - ) - res.push(outerTx) + if (index !== -1 && allowed) { + const nextStatus = taskType.statuses[index + 1] + if (nextStatus !== undefined) { + const currentStatus = taskType.statuses[index] + const current = (await control.modelDb.findAll(core.class.Status, { _id: currentStatus }))[0] + const next = (await control.modelDb.findAll(core.class.Status, { _id: nextStatus }))[0] + if ( + current.category !== task.statusCategory.Lost && + next.category !== task.statusCategory.Lost && + current.category !== task.statusCategory.Won + ) { + const innerTx = factory.createTxUpdateDoc(issue._class, issue.space, issue._id, { + status: nextStatus + }) + const outerTx = factory.createTxCollectionCUD( + issue.attachedToClass, + issue.attachedTo, + issue.space, + issue.collection, + innerTx + ) + res.push(outerTx) + } } } } diff --git a/server-plugins/time/src/index.ts b/server-plugins/time/src/index.ts index f6a2878bcd..bd90da1424 100644 --- a/server-plugins/time/src/index.ts +++ b/server-plugins/time/src/index.ts @@ -36,7 +36,7 @@ export interface ToDoFactory extends Class { * @public */ export interface OnToDo extends Class { - onDone: Resource<(control: TriggerControl, workslots: WorkSlot[], todo: ToDo) => Promise> + onDone: Resource<(control: TriggerControl, workslots: WorkSlot[], todo: ToDo, isDerived: boolean) => Promise> } /** @@ -49,7 +49,9 @@ export default plugin(serverTimeId, { }, function: { IssueToDoFactory: '' as Resource<(tx: Tx, control: TriggerControl) => Promise>, - IssueToDoDone: '' as Resource<(control: TriggerControl, workslots: WorkSlot[], todo: ToDo) => Promise> + IssueToDoDone: '' as Resource< + (control: TriggerControl, workslots: WorkSlot[], todo: ToDo, isDerived: boolean) => Promise + > }, trigger: { OnTask: '' as Resource,