Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion foundations/core/packages/core/src/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('$')) {
Expand Down
13 changes: 8 additions & 5 deletions plugins/process-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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] = {
Expand All @@ -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] = {
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions server-plugins/process-resources/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import core, {
Class,
Data,
Doc,
DocumentUpdate,
fillDefaults,
findProperty,
generateId,
Expand Down Expand Up @@ -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
}
Expand Down
Loading