Skip to content

Commit e5134c7

Browse files
committed
fix: app & dataset auth
1 parent 804e9d5 commit e5134c7

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

packages/service/support/permission/app/auth.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { MongoApp } from '../../../core/app/schema';
33
import { type AppDetailType } from '@fastgpt/global/core/app/type.d';
44
import {
5+
NullRoleVal,
56
PerResourceTypeEnum,
67
ReadPermissionVal,
78
ReadRoleVal
@@ -18,6 +19,7 @@ import { type AuthModeType, type AuthResponseType } from '../type';
1819
import { splitCombinePluginId } from '@fastgpt/global/core/app/plugin/utils';
1920
import { AppReadChatLogPerVal } from '@fastgpt/global/support/permission/app/constant';
2021
import { parseHeaderCert } from '../auth/common';
22+
import { sumPer } from '@fastgpt/global/support/permission/utils';
2123

2224
export const authPluginByTmbId = async ({
2325
tmbId,
@@ -93,15 +95,24 @@ export const authAppByTmbId = async ({
9395
const isGetParentClb =
9496
app.inheritPermission && !AppFolderTypeList.includes(app.type) && !!app.parentId;
9597

96-
const Per = new AppPermission({
97-
role: await getTmbPermission({
98+
const [folderPer = NullRoleVal, myPer = NullRoleVal] = await Promise.all([
99+
isGetParentClb
100+
? getTmbPermission({
101+
teamId,
102+
tmbId,
103+
resourceId: app.parentId!,
104+
resourceType: PerResourceTypeEnum.dataset
105+
})
106+
: NullRoleVal,
107+
getTmbPermission({
98108
teamId,
99109
tmbId,
100-
resourceId: isGetParentClb ? app.parentId! : app._id,
101-
resourceType: PerResourceTypeEnum.app
102-
}),
103-
isOwner
104-
});
110+
resourceId: appId,
111+
resourceType: PerResourceTypeEnum.dataset
112+
})
113+
]);
114+
115+
const Per = new AppPermission({ role: sumPer(folderPer, myPer), isOwner });
105116

106117
if (!Per.checkPer(per)) {
107118
return Promise.reject(AppErrEnum.unAuthApp);

packages/service/support/permission/dataset/auth.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { getTmbInfoByTmbId } from '../../user/team/controller';
99
import { MongoDataset } from '../../../core/dataset/schema';
1010
import {
1111
NullPermissionVal,
12+
NullRoleVal,
1213
PerResourceTypeEnum
1314
} from '@fastgpt/global/support/permission/constant';
1415
import { DatasetErrEnum } from '@fastgpt/global/common/error/code/dataset';
@@ -22,6 +23,7 @@ import { DataSetDefaultRoleVal } from '@fastgpt/global/support/permission/datase
2223
import { getDatasetImagePreviewUrl } from '../../../core/dataset/image/utils';
2324
import { i18nT } from '../../../../web/i18n/utils';
2425
import { parseHeaderCert } from '../auth/common';
26+
import { sumPer } from '@fastgpt/global/support/permission/utils';
2527

2628
export const authDatasetByTmbId = async ({
2729
tmbId,
@@ -65,16 +67,24 @@ export const authDatasetByTmbId = async ({
6567
const isGetParentClb =
6668
dataset.inheritPermission && dataset.type !== DatasetTypeEnum.folder && !!dataset.parentId;
6769

68-
// get dataset permission or inherit permission from parent folder.
69-
const Per = new DatasetPermission({
70-
role: await getTmbPermission({
70+
const [folderPer = NullRoleVal, myPer = NullRoleVal] = await Promise.all([
71+
isGetParentClb
72+
? getTmbPermission({
73+
teamId,
74+
tmbId,
75+
resourceId: dataset.parentId!,
76+
resourceType: PerResourceTypeEnum.dataset
77+
})
78+
: NullRoleVal,
79+
getTmbPermission({
7180
teamId,
7281
tmbId,
73-
resourceId: isGetParentClb ? dataset.parentId! : datasetId,
82+
resourceId: datasetId,
7483
resourceType: PerResourceTypeEnum.dataset
75-
}),
76-
isOwner
77-
});
84+
})
85+
]);
86+
87+
const Per = new DatasetPermission({ role: sumPer(folderPer, myPer), isOwner });
7888

7989
if (!Per.checkPer(per)) {
8090
return Promise.reject(DatasetErrEnum.unAuthDataset);

0 commit comments

Comments
 (0)