@@ -128,27 +128,26 @@ export class NamespaceResourcesService {
128128 return resources . map ( ( resource ) => resource . id ) ;
129129 }
130130
131- private async hasChildren (
132- namespaceId : string ,
133- parents : ResourceMetaDto [ ] ,
134- userId : string ,
135- ) : Promise < boolean > {
136- const children = await this . resourcesService . getSubResources (
137- namespaceId ,
138- parents [ 0 ] . id ,
139- ) ;
140- for ( const child of children ) {
141- const permission = await this . permissionsService . getCurrentPermission (
142- namespaceId ,
143- [ child , ...parents ] ,
144- userId ,
145- ) ;
146- if ( permission !== ResourcePermission . NO_ACCESS ) {
147- return true ;
148- }
149- }
150- return false ;
151- }
131+ // private async hasChildren(
132+ // namespaceId: string,
133+ // parents: ResourceMetaDto[],
134+ // userId: string,
135+ // ): Promise<boolean> {
136+ // const children = await this.resourcesService.getSubResources(namespaceId, [
137+ // parents[0].id,
138+ // ]);
139+ // for (const child of children) {
140+ // const permission = await this.permissionsService.getCurrentPermission(
141+ // namespaceId,
142+ // [child, ...parents],
143+ // userId,
144+ // );
145+ // if (permission !== ResourcePermission.NO_ACCESS) {
146+ // return true;
147+ // }
148+ // }
149+ // return false;
150+ // }
152151
153152 async create (
154153 userId : string ,
@@ -403,10 +402,9 @@ export class NamespaceResourcesService {
403402 if ( permission === ResourcePermission . NO_ACCESS ) {
404403 return [ ] ;
405404 }
406- const children = await this . resourcesService . getSubResources (
407- namespaceId ,
405+ const children = await this . resourcesService . getSubResources ( namespaceId , [
408406 parents [ 0 ] . id ,
409- ) ;
407+ ] ) ;
410408 const filteredChildren : ResourceMetaDto [ ] = [ ] ;
411409 for ( const child of children ) {
412410 const permission = await this . permissionsService . getCurrentPermission (
@@ -430,21 +428,42 @@ export class NamespaceResourcesService {
430428 namespaceId ,
431429 resourceId ,
432430 ) ;
433- const children = await this . getSubResourcesByParents (
431+ const children = await this . resourcesService . getSubResources ( namespaceId , [
432+ resourceId ,
433+ ] ) ;
434+ const subChildren = await this . resourcesService . getSubResources (
435+ namespaceId ,
436+ children . map ( ( child ) => child . id ) ,
437+ ) ;
438+ const resources = [ ...parents , ...children , ...subChildren ] ;
439+ const permissionMap = await this . permissionsService . getCurrentPermissions (
434440 namespaceId ,
435- parents ,
436441 userId ,
442+ resources ,
437443 ) ;
438- const resps : ChildrenMetaDto [ ] = [ ] ;
444+
445+ const hasChildrenMap = new Map < string , boolean > ( ) ;
446+ for ( const subChild of subChildren ) {
447+ if ( ! subChild . parentId ) {
448+ continue ;
449+ }
450+ const permission = permissionMap . get ( subChild . id ) ;
451+ if ( ! permission || permission === ResourcePermission . NO_ACCESS ) {
452+ continue ;
453+ }
454+ hasChildrenMap . set ( subChild . parentId , true ) ;
455+ }
456+
457+ const childrenDtos : ChildrenMetaDto [ ] = [ ] ;
439458 for ( const child of children ) {
440- const hasChildren = await this . hasChildren (
441- namespaceId ,
442- [ child , ... parents ] ,
443- userId ,
444- ) ;
445- resps . push ( new ChildrenMetaDto ( child , hasChildren ) ) ;
459+ const permission = permissionMap . get ( child . id ) ;
460+ if ( ! permission || permission === ResourcePermission . NO_ACCESS ) {
461+ continue ;
462+ }
463+ const hasChildren = hasChildrenMap . get ( child . id ) || false ;
464+ childrenDtos . push ( new ChildrenMetaDto ( child , hasChildren ) ) ;
446465 }
447- return resps ;
466+ return childrenDtos ;
448467 }
449468
450469 async getSpaceType (
0 commit comments