mirror of
https://github.com/hcengineering/platform.git
synced 2026-08-17 18:05:42 +02:00
Fix fieldChangesCheck (#10550)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
@@ -436,7 +436,10 @@ export abstract class TxProcessor implements WithTx {
|
||||
}
|
||||
|
||||
static txHasUpdate<T extends Doc>(tx: TxUpdateDoc<T>, attribute: string): boolean {
|
||||
const ops = tx.operations
|
||||
return TxProcessor.hasUpdate(tx.operations, attribute)
|
||||
}
|
||||
|
||||
static hasUpdate<T extends Doc>(ops: DocumentUpdate<T>, attribute: string): boolean {
|
||||
if ((ops as any)[attribute] !== undefined) return true
|
||||
for (const op in ops) {
|
||||
if (op.startsWith('$')) {
|
||||
|
||||
@@ -20,12 +20,14 @@ import core, {
|
||||
type Client,
|
||||
type Doc,
|
||||
type DocumentQuery,
|
||||
type DocumentUpdate,
|
||||
generateId,
|
||||
matchQuery,
|
||||
type Ref,
|
||||
type RefTo,
|
||||
type Space,
|
||||
type TxOperations,
|
||||
TxProcessor,
|
||||
type Type
|
||||
} from '@hcengineering/core'
|
||||
import { getResource, type IntlString, PlatformError, Severity, Status } from '@hcengineering/platform'
|
||||
@@ -207,9 +209,9 @@ export function getContext (
|
||||
}
|
||||
}
|
||||
const allRelations = client.getModel().findAllSync(core.class.Association, {})
|
||||
const descendants = new Set(client.getHierarchy().getDescendants(process.masterTag))
|
||||
const ancestors = new Set(client.getHierarchy().getAncestors(process.masterTag))
|
||||
|
||||
const relationsA = allRelations.filter((it) => descendants.has(it.classA))
|
||||
const relationsA = allRelations.filter((it) => ancestors.has(it.classA))
|
||||
for (const rel of relationsA) {
|
||||
if (['object', 'array'].includes(category) && client.getHierarchy().isDerived(rel.classB, target)) {
|
||||
relations[rel.nameB] = {
|
||||
@@ -231,7 +233,7 @@ export function getContext (
|
||||
}
|
||||
}
|
||||
|
||||
const relationsB = allRelations.filter((it) => descendants.has(it.classB))
|
||||
const relationsB = allRelations.filter((it) => ancestors.has(it.classB))
|
||||
for (const rel of relationsB) {
|
||||
if (['object', 'array'].includes(category) && client.getHierarchy().isDerived(rel.classA, target)) {
|
||||
relations[rel.nameA] = {
|
||||
@@ -683,8 +685,9 @@ export function fieldChangesCheck (
|
||||
): boolean {
|
||||
const doc = context.card
|
||||
if (doc === undefined) return false
|
||||
const param = Object.keys(params)[0]
|
||||
if (!Object.keys(context.operations ?? {}).includes(param)) return false
|
||||
const operations = (context.operations ?? {}) as DocumentUpdate<Doc>
|
||||
const target = Object.keys(params)[0]
|
||||
if (!TxProcessor.hasUpdate(operations, target)) return false
|
||||
const res = matchQuery([doc], params, doc._class, client.getHierarchy(), true)
|
||||
return res.length > 0
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import core, {
|
||||
Class,
|
||||
Data,
|
||||
Doc,
|
||||
DocumentUpdate,
|
||||
fillDefaults,
|
||||
findProperty,
|
||||
generateId,
|
||||
@@ -169,9 +170,9 @@ export function FieldChangedCheck (
|
||||
const process = control.client.getModel().findObject(execution.process)
|
||||
if (process === undefined) return false
|
||||
if (context.operations === undefined) return false
|
||||
const changedFields = Object.keys(context.operations)
|
||||
const operations = context.operations as DocumentUpdate<Doc>
|
||||
const target = Object.keys(params)[0]
|
||||
if (!changedFields.includes(target)) return false
|
||||
if (!TxProcessor.hasUpdate(operations, target)) return false
|
||||
const res = matchQuery([context.card], params, process.masterTag, control.client.getHierarchy(), true)
|
||||
return res.length > 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user