Skip to content

Commit 8069c7d

Browse files
authored
Fix process roles (#10203)
Signed-off-by: Denis Bykhov <[email protected]>
1 parent 6b40532 commit 8069c7d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

server-plugins/process-resources/src/transform.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import core, { Doc, matchQuery, Ref, Timestamp } from '@hcengineering/core'
1818
import { Execution, parseContext } from '@hcengineering/process'
1919
import { ProcessControl } from '@hcengineering/server-process'
2020
import { getContextValue } from './utils'
21+
import cardPlugin from '@hcengineering/card'
2122

2223
// #region ArrayReduce
2324

@@ -408,8 +409,17 @@ export async function RoleContext (
408409
): Promise<Ref<Employee>[]> {
409410
const targetRole = props.target
410411
if (targetRole === undefined) return []
411-
const users = await control.client.findAll(contact.class.UserRole, { role: targetRole })
412-
return users.map((it) => it.user)
412+
const targetCard =
413+
control.cache.get(execution.card) ?? (await control.client.findOne(cardPlugin.class.Card, { _id: execution.card }))
414+
if (targetCard === undefined) return []
415+
const targetSpace =
416+
control.cache.get(targetCard.space) ?? (await control.client.findOne(core.class.Space, { _id: targetCard.space }))
417+
if (targetSpace === undefined) return []
418+
const mixin = control.client.getHierarchy().as(targetSpace, core.mixin.SpacesTypeData)
419+
const accs = (mixin as any)[targetRole]
420+
if (accs === undefined || accs.length === 0) return []
421+
const users = await control.client.findAll(contact.mixin.Employee, { personUuid: { $in: accs } })
422+
return users.map((it) => it._id)
413423
}
414424

415425
export async function CurrentUser (

0 commit comments

Comments
 (0)