mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
fix: alldataset get dataset without folders. omit the permission check (#3047)
This commit is contained in:
@@ -3,100 +3,31 @@ import { MongoDataset } from '@fastgpt/service/core/dataset/schema';
|
|||||||
import { getVectorModel } from '@fastgpt/service/core/ai/model';
|
import { getVectorModel } from '@fastgpt/service/core/ai/model';
|
||||||
import type { DatasetSimpleItemType } from '@fastgpt/global/core/dataset/type.d';
|
import type { DatasetSimpleItemType } from '@fastgpt/global/core/dataset/type.d';
|
||||||
import { NextAPI } from '@/service/middleware/entry';
|
import { NextAPI } from '@/service/middleware/entry';
|
||||||
import {
|
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||||
PerResourceTypeEnum,
|
|
||||||
ReadPermissionVal
|
|
||||||
} from '@fastgpt/global/support/permission/constant';
|
|
||||||
import { MongoResourcePermission } from '@fastgpt/service/support/permission/schema';
|
|
||||||
import { DatasetPermission } from '@fastgpt/global/support/permission/dataset/controller';
|
|
||||||
import { authUserPer } from '@fastgpt/service/support/permission/user/auth';
|
import { authUserPer } from '@fastgpt/service/support/permission/user/auth';
|
||||||
import { DatasetDefaultPermissionVal } from '@fastgpt/global/support/permission/dataset/constant';
|
import { DatasetTypeEnum } from '@fastgpt/global/core/dataset/constants';
|
||||||
import { getGroupsByTmbId } from '@fastgpt/service/support/permission/memberGroup/controllers';
|
|
||||||
import { getGroupPer } from '@fastgpt/service/support/permission/controller';
|
|
||||||
|
|
||||||
/* get all dataset by teamId or tmbId */
|
/* get all dataset by teamId or tmbId */
|
||||||
async function handler(req: NextApiRequest): Promise<DatasetSimpleItemType[]> {
|
async function handler(req: NextApiRequest): Promise<DatasetSimpleItemType[]> {
|
||||||
const {
|
const { teamId } = await authUserPer({
|
||||||
teamId,
|
|
||||||
tmbId,
|
|
||||||
permission: myPer
|
|
||||||
} = await authUserPer({
|
|
||||||
req,
|
req,
|
||||||
authToken: true,
|
authToken: true,
|
||||||
authApiKey: true,
|
authApiKey: true,
|
||||||
per: ReadPermissionVal
|
per: ReadPermissionVal
|
||||||
});
|
});
|
||||||
|
|
||||||
const myGroupIds = (
|
const myDatasets = await MongoDataset.find({
|
||||||
await getGroupsByTmbId({
|
teamId,
|
||||||
tmbId,
|
type: {
|
||||||
teamId
|
$ne: DatasetTypeEnum.folder
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.sort({
|
||||||
|
updateTime: -1
|
||||||
})
|
})
|
||||||
).map((item) => String(item._id));
|
.lean();
|
||||||
|
|
||||||
const [myDatasets, perList] = await Promise.all([
|
return myDatasets.map((item) => ({
|
||||||
MongoDataset.find({
|
|
||||||
teamId
|
|
||||||
})
|
|
||||||
.sort({
|
|
||||||
updateTime: -1
|
|
||||||
})
|
|
||||||
.lean(),
|
|
||||||
MongoResourcePermission.find({
|
|
||||||
resourceType: PerResourceTypeEnum.dataset,
|
|
||||||
teamId,
|
|
||||||
resourceId: {
|
|
||||||
$exists: true
|
|
||||||
}
|
|
||||||
}).lean()
|
|
||||||
]);
|
|
||||||
|
|
||||||
const filterDatasets = myDatasets
|
|
||||||
.map((dataset) => {
|
|
||||||
const per = (() => {
|
|
||||||
const myPerList = perList.filter(
|
|
||||||
(item) =>
|
|
||||||
String(item.tmbId) === String(tmbId) || myGroupIds.includes(String(item.groupId))
|
|
||||||
);
|
|
||||||
|
|
||||||
const getPer = (id: string) => {
|
|
||||||
const tmbPer = myPerList.find(
|
|
||||||
(item) => String(item.resourceId) === id && !!item.tmbId
|
|
||||||
)?.permission;
|
|
||||||
const groupPer = getGroupPer(
|
|
||||||
myPerList
|
|
||||||
.filter(
|
|
||||||
(item) =>
|
|
||||||
String(item.resourceId) === id && myGroupIds.includes(String(item.groupId))
|
|
||||||
)
|
|
||||||
.map((item) => item.permission)
|
|
||||||
);
|
|
||||||
|
|
||||||
return new DatasetPermission({
|
|
||||||
per: tmbPer ?? groupPer ?? DatasetDefaultPermissionVal,
|
|
||||||
isOwner: String(dataset.tmbId) === String(tmbId) || myPer.isOwner
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const parentDataset = myDatasets.find(
|
|
||||||
(item) => String(item._id) === String(dataset.parentId)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (dataset.inheritPermission && dataset.parentId && parentDataset) {
|
|
||||||
return getPer(parentDataset._id);
|
|
||||||
} else {
|
|
||||||
return getPer(dataset._id);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
return {
|
|
||||||
...dataset,
|
|
||||||
permission: per
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.filter((app) => app.permission.hasReadPer);
|
|
||||||
|
|
||||||
return filterDatasets.map((item) => ({
|
|
||||||
_id: item._id,
|
_id: item._id,
|
||||||
avatar: item.avatar,
|
avatar: item.avatar,
|
||||||
name: item.name,
|
name: item.name,
|
||||||
|
Reference in New Issue
Block a user