Skip to content

Commit

Permalink
perf: private app check (#3376)
Browse files Browse the repository at this point in the history
* perf: private app check

* perf: clb count
  • Loading branch information
c121914yu authored Dec 11, 2024
1 parent c0135f5 commit 4b9b0db
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
36 changes: 20 additions & 16 deletions projects/app/src/pages/api/core/app/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,26 +157,30 @@ async function handler(req: ApiRequestProps<ListAppBody>): Promise<AppListItemTy
.map((item) => 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 {
Expand Down
34 changes: 19 additions & 15 deletions projects/app/src/pages/api/core/dataset/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,29 +127,33 @@ async function handler(req: ApiRequestProps<GetDatasetListBody>) {
.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 {
Expand Down

0 comments on commit 4b9b0db

Please sign in to comment.