Commit 9f4aa316 by Finley Ge Committed by GitHub

fix: app/dataset auth (#3021)

parent 8e4084f7
...@@ -120,47 +120,39 @@ async function handler(req: ApiRequestProps<ListAppBody>): Promise<AppListItemTy ...@@ -120,47 +120,39 @@ async function handler(req: ApiRequestProps<ListAppBody>): Promise<AppListItemTy
const filterApps = myApps const filterApps = myApps
.map((app) => { .map((app) => {
const { Per, privateApp } = (() => { const { Per, privateApp } = (() => {
// Inherit app const myPerList = perList.filter(
if (app.inheritPermission && ParentApp && !AppFolderTypeList.includes(app.type)) { (item) =>
const tmbPer = perList.find( String(item.tmbId) === String(tmbId) || myGroupIds.includes(String(item.groupId))
(item) => String(item.resourceId) === String(ParentApp._id) && !!item.tmbId );
const getPer = (id: string) => {
const tmbPer = myPerList.find(
(item) => String(item.resourceId) === id && !!item.tmbId
)?.permission; )?.permission;
const groupPer = getGroupPer( const groupPer = getGroupPer(
perList myPerList
.filter( .filter(
(item) => (item) =>
String(item.resourceId) === String(ParentApp._id) && String(item.resourceId) === id && myGroupIds.includes(String(item.groupId))
myGroupIds.includes(String(item.groupId))
) )
.map((item) => item.permission) .map((item) => item.permission)
); );
const clbCount = perList.filter((item) => String(item.resourceId) === id).length;
return { return {
Per: new AppPermission({ Per: new AppPermission({
per: tmbPer ?? groupPer ?? AppDefaultPermissionVal, per: tmbPer ?? groupPer ?? AppDefaultPermissionVal,
isOwner: String(app.tmbId) === String(tmbId) || myPer.isOwner isOwner: String(app.tmbId) === String(tmbId) || myPer.isOwner
}), }),
privateApp: privateApp: AppFolderTypeList.includes(app.type) ? clbCount <= 1 : clbCount === 0
perList.filter((item) => String(item.resourceId) === String(app._id)).length <= 1
}; };
} else {
const tmbPer = perList.find(
(item) => String(item.resourceId) === String(app._id) && !!item.tmbId
)?.permission;
const group = perList.filter(
(item) =>
String(item.resourceId) === String(app._id) &&
myGroupIds.includes(String(item.groupId))
);
const groupPer = getGroupPer(group.map((item) => item.permission));
return {
Per: new AppPermission({
per: tmbPer ?? groupPer ?? AppDefaultPermissionVal,
isOwner: String(app.tmbId) === String(tmbId) || myPer.isOwner
}),
privateApp:
perList.filter((item) => String(item.resourceId) === String(app._id)).length <= 1
}; };
// Inherit app
if (app.inheritPermission && ParentApp && !AppFolderTypeList.includes(app.type)) {
return getPer(String(ParentApp._id));
} else {
return getPer(String(app._id));
} }
})(); })();
......
...@@ -103,50 +103,39 @@ async function handler(req: ApiRequestProps<GetDatasetListBody>) { ...@@ -103,50 +103,39 @@ async function handler(req: ApiRequestProps<GetDatasetListBody>) {
const filterDatasets = myDatasets const filterDatasets = myDatasets
.map((dataset) => { .map((dataset) => {
const { Per, privateDataset } = (() => { const { Per, privateDataset } = (() => {
// inherit const myPerList = perList.filter(
if (dataset.inheritPermission && parentDataset && dataset.type !== DatasetTypeEnum.folder) {
const tmbPer = perList.find(
(item) => String(item.resourceId) === String(parentDataset._id) && !!item.tmbId
)?.permission;
const groupPer = getGroupPer(
perList
.filter(
(item) => (item) =>
String(item.resourceId) === String(parentDataset._id) && String(item.tmbId) === String(tmbId) || myGroupIds.includes(String(item.groupId))
myGroupIds.includes(String(item.groupId))
)
.map((item) => item.permission)
); );
return {
Per: new DatasetPermission({ const getPer = (id: string) => {
per: tmbPer ?? groupPer ?? DatasetDefaultPermissionVal, const tmbPer = myPerList.find(
isOwner: String(parentDataset.tmbId) === tmbId || myPer.isOwner (item) => String(item.resourceId) === id && !!item.tmbId
}),
privateDataset:
perList.filter((item) => String(item.resourceId) === String(dataset._id)).length <= 1
};
} else {
const tmbPer = perList.find(
(item) =>
String(item.resourceId) === String(dataset._id) && !!item.tmbId && !!item.permission
)?.permission; )?.permission;
const groupPer = getGroupPer( const groupPer = getGroupPer(
perList myPerList
.filter( .filter(
(item) => (item) =>
String(item.resourceId) === String(dataset._id) && String(item.resourceId) === id && myGroupIds.includes(String(item.groupId))
myGroupIds.includes(String(item.groupId))
) )
.map((item) => item.permission) .map((item) => item.permission)
); );
const clbCount = perList.filter((item) => String(item.resourceId) === id).length;
return { return {
Per: new DatasetPermission({ Per: new DatasetPermission({
per: tmbPer ?? groupPer ?? DatasetDefaultPermissionVal, per: tmbPer ?? groupPer ?? DatasetDefaultPermissionVal,
isOwner: String(dataset.tmbId) === tmbId || myPer.isOwner isOwner: String(dataset.tmbId) === String(tmbId) || myPer.isOwner
}), }),
privateDataset: privateDataset: dataset.type === 'folder' ? clbCount <= 1 : clbCount === 0
perList.filter((item) => String(item.resourceId) === String(dataset._id)).length <= 1 };
}; };
// inherit
if (dataset.inheritPermission && parentDataset && dataset.type !== DatasetTypeEnum.folder) {
return getPer(String(parentDataset._id));
} else {
return getPer(String(dataset._id));
} }
})(); })();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment