mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-17 08:37:59 +00:00
fix dataset auth filter (#5457)
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
import { getTmbInfoByTmbId } from '../../support/user/team/controller';
|
import { authDatasetByTmbId } from '../../support/permission/dataset/auth';
|
||||||
import { getResourcePermission } from '../../support/permission/controller';
|
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||||
import { PerResourceTypeEnum } from '@fastgpt/global/support/permission/constant';
|
|
||||||
import { DatasetPermission } from '@fastgpt/global/support/permission/dataset/controller';
|
|
||||||
|
|
||||||
// TODO: 需要优化成批量获取权限
|
// TODO: 需要优化成批量获取权限
|
||||||
export const filterDatasetsByTmbId = async ({
|
export const filterDatasetsByTmbId = async ({
|
||||||
@@ -11,26 +9,19 @@ export const filterDatasetsByTmbId = async ({
|
|||||||
datasetIds: string[];
|
datasetIds: string[];
|
||||||
tmbId: string;
|
tmbId: string;
|
||||||
}) => {
|
}) => {
|
||||||
const { teamId, permission: tmbPer } = await getTmbInfoByTmbId({ tmbId });
|
|
||||||
|
|
||||||
// First get all permissions
|
|
||||||
const permissions = await Promise.all(
|
const permissions = await Promise.all(
|
||||||
datasetIds.map(async (datasetId) => {
|
datasetIds.map(async (datasetId) => {
|
||||||
const role = await getResourcePermission({
|
try {
|
||||||
teamId,
|
await authDatasetByTmbId({
|
||||||
tmbId,
|
tmbId,
|
||||||
resourceId: datasetId,
|
datasetId,
|
||||||
resourceType: PerResourceTypeEnum.dataset
|
per: ReadPermissionVal
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
if (role === undefined) return false;
|
} catch (error) {
|
||||||
|
console.log(`Dataset ${datasetId} access denied:`, error);
|
||||||
const datasetPer = new DatasetPermission({
|
return false;
|
||||||
role,
|
}
|
||||||
isOwner: tmbPer.isOwner
|
|
||||||
});
|
|
||||||
|
|
||||||
return datasetPer.hasReadPer;
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user