ezqms-1121: fix deleted doc states (#6112)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2024-07-22 19:57:37 +04:00 committed by GitHub
parent 434163f00a
commit 93b798c99b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 1 deletions

View File

@ -22,6 +22,15 @@ export function createModel (builder: Builder): void {
}
})
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverDocuments.trigger.OnDocDeleted,
txMatch: {
_class: core.class.TxUpdateDoc,
objectClass: documents.class.ControlledDocument,
'operations.state': DocumentState.Deleted
}
})
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverDocuments.trigger.OnDocPlannedEffectiveDateChanged,
txMatch: {

View File

@ -31,9 +31,11 @@ import documents, {
calcRank,
type DocumentTraining,
getEffectiveDocUpdate,
getDocumentId
getDocumentId,
type DocumentRequest
} from '@hcengineering/controlled-documents'
import training, { type TrainingRequest, TrainingState } from '@hcengineering/training'
import { RequestStatus } from '@hcengineering/request'
/**
* @public
@ -351,6 +353,26 @@ export async function OnDocHasBecomeEffective (
]
}
export async function OnDocDeleted (tx: TxUpdateDoc<ControlledDocument>, control: TriggerControl): Promise<Tx[]> {
const requests = await control.findAll(documents.class.DocumentRequest, {
attachedTo: tx.objectId,
status: RequestStatus.Active
})
const cancelTxes = requests.map((request) =>
control.txFactory.createTxUpdateDoc<DocumentRequest>(request._class, request.space, request._id, {
status: RequestStatus.Cancelled
})
)
await control.apply([
...cancelTxes,
control.txFactory.createTxUpdateDoc<ControlledDocument>(tx.objectClass, tx.objectSpace, tx.objectId, {
controlledState: undefined
})
])
return []
}
export async function OnDocPlannedEffectiveDateChanged (
tx: TxUpdateDoc<ControlledDocument>,
control: TriggerControl
@ -446,6 +468,7 @@ export async function documentTextPresenter (doc: ControlledDocument): Promise<s
export default async () => ({
trigger: {
OnCollaborativeSectionDeleted,
OnDocDeleted,
OnDocPlannedEffectiveDateChanged,
OnDocApprovalRequestApproved,
OnDocHasBecomeEffective,

View File

@ -19,6 +19,7 @@ export const serverDocumentsId = 'server-documents' as Plugin
export default plugin(serverDocumentsId, {
trigger: {
OnCollaborativeSectionDeleted: '' as Resource<TriggerFunc>,
OnDocDeleted: '' as Resource<TriggerFunc>,
OnDocPlannedEffectiveDateChanged: '' as Resource<TriggerFunc>,
OnDocApprovalRequestApproved: '' as Resource<TriggerFunc>,
OnDocHasBecomeEffective: '' as Resource<TriggerFunc>,