fix change issue status when change assignee (#7438)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-12-12 14:07:34 +05:00 committed by GitHub
parent 59b1635afb
commit 51a55dd803
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 50 additions and 41 deletions

View File

@ -405,7 +405,7 @@ export async function OnToDoUpdate (txes: Tx[], control: TriggerControl): Promis
) )
if (funcs !== undefined) { if (funcs !== undefined) {
const func = await getResource(funcs.onDone) 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) await control.apply(control.ctx, todoRes)
} }
continue continue
@ -459,7 +459,12 @@ export async function IssueToDoFactory (actualTx: TxCUD<Issue>, control: Trigger
/** /**
* @public * @public
*/ */
export async function IssueToDoDone (control: TriggerControl, workslots: WorkSlot[], todo: ToDo): Promise<Tx[]> { export async function IssueToDoDone (
control: TriggerControl,
workslots: WorkSlot[],
todo: ToDo,
isDerived: boolean
): Promise<Tx[]> {
const res: Tx[] = [] const res: Tx[] = []
let total = 0 let total = 0
for (const workslot of workslots) { for (const workslot of workslots) {
@ -470,45 +475,47 @@ export async function IssueToDoDone (control: TriggerControl, workslots: WorkSlo
await control.findAll<Issue>(control.ctx, todo.attachedToClass, { _id: todo.attachedTo as Ref<Issue> }) await control.findAll<Issue>(control.ctx, todo.attachedToClass, { _id: todo.attachedTo as Ref<Issue> })
)[0] )[0]
if (issue !== undefined) { if (issue !== undefined) {
const project = (await control.findAll(control.ctx, task.class.Project, { _id: issue.space }))[0] if (!isDerived) {
if (project !== undefined) { const project = (await control.findAll(control.ctx, task.class.Project, { _id: issue.space }))[0]
const type = (await control.modelDb.findAll(task.class.ProjectType, { _id: project.type }))[0] if (project !== undefined) {
if (type?.classic) { const type = (await control.modelDb.findAll(task.class.ProjectType, { _id: project.type }))[0]
const taskType = (await control.modelDb.findAll(task.class.TaskType, { _id: issue.kind }))[0] if (type?.classic) {
if (taskType !== undefined) { const taskType = (await control.modelDb.findAll(task.class.TaskType, { _id: issue.kind }))[0]
const index = taskType.statuses.findIndex((p) => p === issue.status) if (taskType !== undefined) {
const index = taskType.statuses.findIndex((p) => p === issue.status)
const helpers = await control.modelDb.findAll<TodoAutomationHelper>(time.class.TodoAutomationHelper, {}) const helpers = await control.modelDb.findAll<TodoAutomationHelper>(time.class.TodoAutomationHelper, {})
const testers = await Promise.all(helpers.map((it) => getResource(it.onDoneTester))) const testers = await Promise.all(helpers.map((it) => getResource(it.onDoneTester)))
let allowed = true let allowed = true
for (const tester of testers) { for (const tester of testers) {
if (!(await tester(control, todo))) { if (!(await tester(control, todo))) {
allowed = false allowed = false
break break
}
} }
} if (index !== -1 && allowed) {
if (index !== -1 && allowed) { const nextStatus = taskType.statuses[index + 1]
const nextStatus = taskType.statuses[index + 1] if (nextStatus !== undefined) {
if (nextStatus !== undefined) { const currentStatus = taskType.statuses[index]
const currentStatus = taskType.statuses[index] const current = (await control.modelDb.findAll(core.class.Status, { _id: currentStatus }))[0]
const current = (await control.modelDb.findAll(core.class.Status, { _id: currentStatus }))[0] const next = (await control.modelDb.findAll(core.class.Status, { _id: nextStatus }))[0]
const next = (await control.modelDb.findAll(core.class.Status, { _id: nextStatus }))[0] if (
if ( current.category !== task.statusCategory.Lost &&
current.category !== task.statusCategory.Lost && next.category !== task.statusCategory.Lost &&
next.category !== task.statusCategory.Lost && current.category !== task.statusCategory.Won
current.category !== task.statusCategory.Won ) {
) { const innerTx = factory.createTxUpdateDoc(issue._class, issue.space, issue._id, {
const innerTx = factory.createTxUpdateDoc(issue._class, issue.space, issue._id, { status: nextStatus
status: nextStatus })
}) const outerTx = factory.createTxCollectionCUD(
const outerTx = factory.createTxCollectionCUD( issue.attachedToClass,
issue.attachedToClass, issue.attachedTo,
issue.attachedTo, issue.space,
issue.space, issue.collection,
issue.collection, innerTx
innerTx )
) res.push(outerTx)
res.push(outerTx) }
} }
} }
} }

View File

@ -36,7 +36,7 @@ export interface ToDoFactory extends Class<Task> {
* @public * @public
*/ */
export interface OnToDo extends Class<Doc> { export interface OnToDo extends Class<Doc> {
onDone: Resource<(control: TriggerControl, workslots: WorkSlot[], todo: ToDo) => Promise<Tx[]>> onDone: Resource<(control: TriggerControl, workslots: WorkSlot[], todo: ToDo, isDerived: boolean) => Promise<Tx[]>>
} }
/** /**
@ -49,7 +49,9 @@ export default plugin(serverTimeId, {
}, },
function: { function: {
IssueToDoFactory: '' as Resource<(tx: Tx, control: TriggerControl) => Promise<Tx[]>>, IssueToDoFactory: '' as Resource<(tx: Tx, control: TriggerControl) => Promise<Tx[]>>,
IssueToDoDone: '' as Resource<(control: TriggerControl, workslots: WorkSlot[], todo: ToDo) => Promise<Tx[]>> IssueToDoDone: '' as Resource<
(control: TriggerControl, workslots: WorkSlot[], todo: ToDo, isDerived: boolean) => Promise<Tx[]>
>
}, },
trigger: { trigger: {
OnTask: '' as Resource<TriggerFunc>, OnTask: '' as Resource<TriggerFunc>,