QFix: additional QMS status & version transition fixes (#8769)

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>
This commit is contained in:
Victor Ilyushchenko 2025-04-29 19:33:10 +03:00 committed by GitHub
parent ce66b12a92
commit b0cd5238f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 50 additions and 8 deletions

View File

@ -167,8 +167,8 @@ async function createTemplateIfNotExist (
seqNumber: 0,
sections: 0,
category,
major: 0,
minor: 1,
major: 1,
minor: 0,
commentSequence: 0,
state: DocumentState.Draft,
author: owner,

View File

@ -14,6 +14,7 @@ import {
import {
type ChangeControl,
type ControlledDocument,
ControlledDocumentState,
createChangeControl,
createDocumentTemplate,
type DocumentCategory,
@ -479,6 +480,41 @@ async function migrateInvalidDocumentState (client: MigrationClient): Promise<vo
await client.bulk(DOMAIN_DOCUMENTS, operations)
}
async function migrateInvalidPlannedEffectiveDate (client: MigrationClient): Promise<void> {
const docs = await client.find<ControlledDocument>(DOMAIN_DOCUMENTS, {
_class: documents.class.ControlledDocument,
plannedEffectiveDate: { $exists: false }
})
const operations: {
filter: MigrationDocumentQuery<ControlledDocument>
update: MigrateUpdate<ControlledDocument>
}[] = []
for (const doc of docs) {
operations.push({
filter: { _id: doc._id },
update: {
plannedEffectiveDate: 0
}
})
if (doc.state === DocumentState.Draft && doc.controlledState === ControlledDocumentState.Approved) {
operations.push({
filter: { _id: doc._id },
update: { $unset: { controlledState: true } }
})
operations.push({
filter: { _id: doc._id },
update: {
state: DocumentState.Effective,
effectiveDate: Date.now()
}
})
}
}
await client.bulk(DOMAIN_DOCUMENTS, operations)
}
export const documentsOperation: MigrateOperation = {
async migrate (client: MigrationClient, mode): Promise<void> {
await tryMigrate(mode, client, documentsId, [
@ -512,6 +548,10 @@ export const documentsOperation: MigrateOperation = {
{
state: 'migrateInvalidDocumentState',
func: migrateInvalidDocumentState
},
{
state: 'migrateInvalidPlannedEffectiveDate',
func: migrateInvalidPlannedEffectiveDate
}
])
},

View File

@ -868,8 +868,8 @@ export class HulyFormatImporter {
title: header.title,
docPrefix: header.docPrefix,
code: codeMatch?.[1],
major: 0,
minor: 1,
major: 1,
minor: 0,
state: DocumentState.Draft,
category,
author,

View File

@ -1004,7 +1004,8 @@ export class WorkspaceImporter {
changeControl: changeControlId,
commentSequence: 0,
requests: 0,
labels: 0
labels: 0,
plannedEffectiveDate: 0
},
template.id as unknown as Ref<ControlledDocument>
)
@ -1124,7 +1125,8 @@ export class WorkspaceImporter {
content: contentId,
template: templateId as unknown as Ref<DocumentTemplate>,
commentSequence: 0,
requests: 0
requests: 0,
plannedEffectiveDate: 0
},
document.id
)

View File

@ -24,6 +24,6 @@ export const $canRestoreDraft = combine(
$canCreateNewDraft,
(document, latest, canCreateNewDraft) => {
if (latest === null || document == null) return false
return canCreateNewDraft && latest._id === document._id && document.state === DocumentState.Deleted
return canCreateNewDraft && latest?._id === document._id && document.state === DocumentState.Deleted
}
)

View File

@ -355,7 +355,7 @@ export async function OnDocApprovalRequestApproved (
_id: tx.attachedTo as Ref<ControlledDocument>
})
)[0]
if (doc == null || doc.plannedEffectiveDate !== 0) {
if (doc == null || (typeof doc.plannedEffectiveDate === 'number' && doc.plannedEffectiveDate !== 0)) {
continue
}