@@ -192,25 +192,31 @@ export const checkHierarchicalScope = async (ruleTarget: Target,
192
192
}
193
193
const reducedHRScopes = context ?. subject ?. hierarchical_scopes ?. filter ( ( hrObj ) => hrObj ?. role === ruleRole ) ;
194
194
for ( let [ resourceId , owners ] of resourceIdOwnersMap ) {
195
- // validate scoping Entity first
196
- let ownerInstances : string [ ] = [ ] ;
197
- const entityMatch = owners ?. some ( ( ownerObj ) => {
198
- return reducedUserRoleAssocs ?. some ( ( roleObj ) => {
199
- if ( roleObj ?. attributes ?. some ( ( roleAttributeObject ) => roleAttributeObject ?. id === urns . get ( 'roleScopingEntity' )
200
- && ownerObj ?. id === urns . get ( 'ownerEntity' ) && ownerObj . value === ruleRoleScopingEntity && ownerObj . value === roleAttributeObject ?. value ) ) {
201
- ownerObj ?. attributes ?. forEach ( ( obj ) => ownerInstances . push ( obj . value ) ) ;
202
- return true ;
203
- }
204
- } ) ;
205
- } ) ;
195
+ const ownerInstances : string [ ] = owners . filter (
196
+ owner => reducedUserRoleAssocs ?. some ( ( roleObj ) => {
197
+ return roleObj ?. attributes ?. some (
198
+ ( roleAttributeObject ) => roleAttributeObject ?. id === urns . get ( 'roleScopingEntity' )
199
+ && owner ?. id === urns . get ( 'ownerEntity' )
200
+ && owner ?. value === ruleRoleScopingEntity
201
+ && owner ?. value === roleAttributeObject ?. value
202
+ ) ;
203
+ }
204
+ )
205
+ ) . flatMap (
206
+ owner => owner ?. attributes ?. filter (
207
+ attr => attr ?. id === urns . get ( 'ownerInstance' )
208
+ ) . map (
209
+ attr => attr ?. value
210
+ )
211
+ ) ;
206
212
// validate the ownerInstance from HR scope tree for matched scoping entity
207
- if ( entityMatch && ownerInstances ?. length > 0 ) {
208
- traverse ( reducedHRScopes ) . forEach ( ( node : any ) => { // depth-first search
213
+ traverse ( reducedHRScopes ) . forEach (
214
+ ( node : any ) => { // depth-first search
209
215
if ( ownerInstances . includes ( node ?. id ) ) {
210
216
deleteMapEntries . push ( resourceId ) ;
211
217
}
212
- } ) ;
213
- }
218
+ }
219
+ ) ;
214
220
}
215
221
}
216
222
0 commit comments