@@ -18,6 +18,7 @@ import core, { Doc, matchQuery, Ref, Timestamp } from '@hcengineering/core'
1818import { Execution , parseContext } from '@hcengineering/process'
1919import { ProcessControl } from '@hcengineering/server-process'
2020import { 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
415425export async function CurrentUser (
0 commit comments