diff --git a/projects/app/src/pages/api/core/app/list.ts b/projects/app/src/pages/api/core/app/list.ts index 34c36dd65409..7f3f5ce1338a 100644 --- a/projects/app/src/pages/api/core/app/list.ts +++ b/projects/app/src/pages/api/core/app/list.ts @@ -157,26 +157,30 @@ async function handler(req: ApiRequestProps): Promise item.permission) ); - // Count app collaborators - const clbCount = perList.filter( - (item) => String(item.resourceId) === String(app._id) - ).length; + return new AppPermission({ + per: tmbPer ?? groupPer ?? AppDefaultPermissionVal, + isOwner: String(app.tmbId) === String(tmbId) || teamPer.isOwner + }); + }; - return { - Per: new AppPermission({ - per: tmbPer ?? groupPer ?? AppDefaultPermissionVal, - isOwner: String(app.tmbId) === String(tmbId) || teamPer.isOwner - }), - privateApp: AppFolderTypeList.includes(app.type) ? clbCount <= 1 : clbCount === 0 - }; + const getClbCount = (appId: string) => { + return perList.filter((item) => String(item.resourceId) === String(appId)).length; }; - // Inherit app - if (app.inheritPermission && app.parentId && !AppFolderTypeList.includes(app.type)) { - return getPer(String(app.parentId)); - } else { - return getPer(String(app._id)); + // Inherit app, check parent folder clb + if (!AppFolderTypeList.includes(app.type) && app.parentId && app.inheritPermission) { + return { + Per: getPer(String(app.parentId)), + privateApp: getClbCount(String(app.parentId)) <= 1 + }; } + + return { + Per: getPer(String(app._id)), + privateApp: AppFolderTypeList.includes(app.type) + ? getClbCount(String(app._id)) <= 1 + : getClbCount(String(app._id)) === 0 + }; })(); return { diff --git a/projects/app/src/pages/api/core/dataset/list.ts b/projects/app/src/pages/api/core/dataset/list.ts index d8674bed5e58..6e404e0117f9 100644 --- a/projects/app/src/pages/api/core/dataset/list.ts +++ b/projects/app/src/pages/api/core/dataset/list.ts @@ -127,29 +127,33 @@ async function handler(req: ApiRequestProps) { .filter((item) => String(item.resourceId) === datasetId && !!item.groupId) .map((item) => item.permission) ); - - const clbCount = perList.filter( - (item) => String(item.resourceId) === String(dataset._id) - ).length; - - return { - Per: new DatasetPermission({ - per: tmbPer ?? groupPer ?? DatasetDefaultPermissionVal, - isOwner: String(dataset.tmbId) === String(tmbId) || teamPer.isOwner - }), - privateDataset: dataset.type === 'folder' ? clbCount <= 1 : clbCount === 0 - }; + return new DatasetPermission({ + per: tmbPer ?? groupPer ?? DatasetDefaultPermissionVal, + isOwner: String(dataset.tmbId) === String(tmbId) || teamPer.isOwner + }); + }; + const getClbCount = (datasetId: string) => { + return perList.filter((item) => String(item.resourceId) === String(datasetId)).length; }; + // inherit if ( dataset.inheritPermission && dataset.parentId && dataset.type !== DatasetTypeEnum.folder ) { - return getPer(String(dataset.parentId)); - } else { - return getPer(String(dataset._id)); + return { + Per: getPer(String(dataset.parentId)), + privateDataset: getClbCount(String(dataset.parentId)) <= 1 + }; } + return { + Per: getPer(String(dataset._id)), + privateDataset: + dataset.type === DatasetTypeEnum.folder + ? getClbCount(String(dataset._id)) <= 1 + : getClbCount(String(dataset._id)) === 0 + }; })(); return {