Skip to content

Commit

Permalink
Dataset Permission (#1786)
Browse files Browse the repository at this point in the history
* feat: dataset controllers

feat: dataset schema

fix: add missing type to dataset schema
Signed-off-by: FinleyGe <[email protected]>

* feat: dataset list api

Signed-off-by: FinleyGe <[email protected]>

* chore: all dataset api

Signed-off-by: FinleyGe <[email protected]>

* feat: new auth dataset method

Signed-off-by: FinleyGe <[email protected]>

* chore: use new auth method in detail, paths.
feat: add new param defaultPermission to create api

Signed-off-by: FinleyGe <[email protected]>

* chore: app auth params

Signed-off-by: FinleyGe <[email protected]>

* chore: use new auth method

Signed-off-by: FinleyGe <[email protected]>

* feat: new auth collection and file method

Signed-off-by: FinleyGe <[email protected]>

* chore: dataset collection api new auth

Signed-off-by: FinleyGe <[email protected]>

* chore: create/*.ts auth

Signed-off-by: FinleyGe <[email protected]>

* chore: dataset auth

Signed-off-by: FinleyGe <[email protected]>

* fix: import paths

Signed-off-by: FinleyGe <[email protected]>

* feat: dataset collaborator

Signed-off-by: FinleyGe <[email protected]>

* chore: dataset frontend

feat: dataset list frontend

feat: dataset detail
Signed-off-by: FinleyGe <[email protected]>

* feat: finish the dataset permission

fix: ts errors
Signed-off-by: FinleyGe <[email protected]>

* fix: empty response of collection api

Signed-off-by: FinleyGe <[email protected]>

* chore: adjust the code

* chore: adjust the code

* chore: i18n

* fix: ts error

* fix: fe CollectionCard permission

---------

Signed-off-by: FinleyGe <[email protected]>
  • Loading branch information
FinleyGe authored Jun 20, 2024
1 parent 2b25e3c commit 980b4d3
Show file tree
Hide file tree
Showing 71 changed files with 12,343 additions and 9,925 deletions.
7 changes: 6 additions & 1 deletion packages/global/common/error/code/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { ErrType } from '../errorCode';
const startCode = 507000;
export enum CommonErrEnum {
fileNotFound = 'fileNotFound',
unAuthFile = 'unAuthFile'
unAuthFile = 'unAuthFile',
missingParams = 'missingParams'
}
const datasetErr = [
{
Expand All @@ -14,6 +15,10 @@ const datasetErr = [
{
statusText: CommonErrEnum.unAuthFile,
message: 'error.unAuthFile'
},
{
statusText: CommonErrEnum.missingParams,
message: 'error.missingParams'
}
];
export default datasetErr.reduce((acc, cur, index) => {
Expand Down
5 changes: 5 additions & 0 deletions packages/global/common/error/code/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ErrType } from '../errorCode';

/* dataset: 501000 */
export enum DatasetErrEnum {
unExist = 'unExistDataset',
unAuthDataset = 'unAuthDataset',
unCreateCollection = 'unCreateCollection',
unAuthDatasetCollection = 'unAuthDatasetCollection',
Expand All @@ -11,6 +12,10 @@ export enum DatasetErrEnum {
unLinkCollection = 'unLinkCollection'
}
const datasetErr = [
{
statusText: DatasetErrEnum.unExist,
message: 'core.dataset.error.unExistDataset'
},
{
statusText: DatasetErrEnum.unAuthDataset,
message: 'core.dataset.error.unAuthDataset'
Expand Down
3 changes: 2 additions & 1 deletion packages/global/core/dataset/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ export type DatasetUpdateBody = {
name?: string;
avatar?: string;
intro?: string;
permission?: DatasetSchemaType['permission'];
permission?: DatasetSchemaType['permission']; // TODO: Should be deleted.
agentModel?: LLMModelItemType;
status?: DatasetSchemaType['status'];

websiteConfig?: DatasetSchemaType['websiteConfig'];
externalReadUrl?: DatasetSchemaType['externalReadUrl'];
defaultPermission?: DatasetSchemaType['defaultPermission'];
};

/* ================= collection ===================== */
Expand Down
11 changes: 11 additions & 0 deletions packages/global/core/dataset/collaborator.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { UpdateClbPermissionProps } from '../../support/permission/collaborator';
import { PermissionValueType } from '../../support/permission/type';

export type UpdateDatasetCollaboratorBody = UpdateClbPermissionProps & {
datasetId: string;
};

export type DatasetCollaboratorDeleteParams = {
datasetId: string;
tmbId: string;
};
16 changes: 9 additions & 7 deletions packages/global/core/dataset/type.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PermissionValueType } from 'support/permission/type';
import type { LLMModelItemType, VectorModelItemType } from '../../core/ai/model.d';
import { PermissionTypeEnum } from '../../support/permission/constant';
import { PushDatasetDataChunkProps } from './api';
Expand All @@ -8,6 +9,8 @@ import {
SearchScoreTypeEnum,
TrainingModeEnum
} from './constants';
import { DatasetPermission } from '../../support/permission/dataset/controller';
import { Permission } from '../../support/permission/controller';

/* schema */
export type DatasetSchemaType = {
Expand All @@ -24,14 +27,15 @@ export type DatasetSchemaType = {
intro: string;
type: DatasetTypeEnum;
status: `${DatasetStatusEnum}`;
permission: `${PermissionTypeEnum}`;
permission: DatasetPermission;

// metadata
websiteConfig?: {
url: string;
selector: string;
};
externalReadUrl?: string;
defaultPermission: PermissionValueType;
};

export type DatasetCollectionSchemaType = {
Expand Down Expand Up @@ -132,24 +136,22 @@ export type DatasetListItemType = {
name: string;
intro: string;
type: DatasetTypeEnum;
isOwner: boolean;
canWrite: boolean;
permission: `${PermissionTypeEnum}`;
permission: DatasetPermission;
vectorModel: VectorModelItemType;
defaultPermission: PermissionValueType;
};

export type DatasetItemType = Omit<DatasetSchemaType, 'vectorModel' | 'agentModel'> & {
vectorModel: VectorModelItemType;
agentModel: LLMModelItemType;
isOwner: boolean;
canWrite: boolean;
};

/* ================= collection ===================== */
export type DatasetCollectionItemType = CollectionWithDatasetType & {
canWrite: boolean;
sourceName: string;
sourceId?: string;
file?: DatasetFileSchema;
permission: DatasetPermission;
};

/* ================= data ===================== */
Expand Down
20 changes: 20 additions & 0 deletions packages/global/support/permission/dataset/constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { NullPermission, PermissionKeyEnum, PermissionList } from '../constant';

export enum DatasetPermissionKeyEnum {}

export const DatasetPermissionList = {
[PermissionKeyEnum.read]: {
...PermissionList[PermissionKeyEnum.read],
description: '可查看知识库内容'
},
[PermissionKeyEnum.write]: {
...PermissionList[PermissionKeyEnum.write],
description: '可增加和变更知识库内容'
},
[PermissionKeyEnum.manage]: {
...PermissionList[PermissionKeyEnum.manage],
description: '可管理整个知识库数据和信息'
}
};

export const DatasetDefaultPermission = NullPermission;
14 changes: 14 additions & 0 deletions packages/global/support/permission/dataset/controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { NullPermission } from '../constant';
import { PerConstructPros, Permission } from '../controller';
export class DatasetPermission extends Permission {
constructor(props?: PerConstructPros) {
if (!props) {
props = {
per: NullPermission
};
} else if (!props?.per) {
props.per = NullPermission;
}
super(props);
}
}
7 changes: 6 additions & 1 deletion packages/service/core/dataset/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
TeamMemberCollectionName
} from '@fastgpt/global/support/user/team/constant';
import { PermissionTypeEnum, PermissionTypeMap } from '@fastgpt/global/support/permission/constant';
import { DatasetDefaultPermission } from '@fastgpt/global/support/permission/dataset/constant';

export const DatasetCollectionName = 'datasets';

Expand Down Expand Up @@ -90,7 +91,11 @@ const DatasetSchema = new Schema({
}
}
},
externalReadUrl: String
externalReadUrl: String,
defaultPermission: {
type: Number,
default: DatasetDefaultPermission
}
});

try {
Expand Down
1 change: 0 additions & 1 deletion packages/service/core/workflow/dispatch/plugin/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
if (source === PluginSourceEnum.personal) {
await authAppByTmbId({
appId: pluginId,
teamId: workflowApp.teamId,
tmbId: workflowApp.tmbId,
per: ReadPermissionVal
});
Expand Down
2 changes: 0 additions & 2 deletions packages/service/core/workflow/dispatch/tools/runApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { ChatItemType } from '@fastgpt/global/core/chat/type.d';
import type { ModuleDispatchProps } from '@fastgpt/global/core/workflow/type/index.d';
import { SelectAppItemType } from '@fastgpt/global/core/workflow/type/index.d';
import { dispatchWorkFlow } from '../index';
import { MongoApp } from '../../../../core/app/schema';
import { responseWrite } from '../../../../common/response';
import { ChatRoleEnum } from '@fastgpt/global/core/chat/constants';
import { SseResponseEventEnum } from '@fastgpt/global/core/workflow/runtime/constants';
Expand Down Expand Up @@ -48,7 +47,6 @@ export const dispatchAppRequest = async (props: Props): Promise<Response> => {
// 检查该工作流的tmb是否有调用该app的权限(不是校验对话的人,是否有权限)
const { app: appData } = await authAppByTmbId({
appId: app.id,
teamId: workflowApp.teamId,
tmbId: workflowApp.tmbId,
per: ReadPermissionVal
});
Expand Down
7 changes: 2 additions & 5 deletions packages/service/support/permission/app/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ import { AuthResponseType } from '../type/auth.d';
import { PermissionValueType } from '@fastgpt/global/support/permission/type';

export const authAppByTmbId = async ({
teamId,
tmbId,
appId,
per
}: {
teamId: string;
tmbId: string;
appId: string;
per: PermissionValueType;
}) => {
const { permission: tmbPer } = await getTmbInfoByTmbId({ tmbId });
const { teamId, permission: tmbPer } = await getTmbInfoByTmbId({ tmbId });

const app = await (async () => {
// get app and per
Expand Down Expand Up @@ -68,10 +66,9 @@ export const authApp = async ({
}
> => {
const result = await parseHeaderCert(props);
const { teamId, tmbId } = result;
const { tmbId } = result;

const { app } = await authAppByTmbId({
teamId,
tmbId,
appId,
per
Expand Down
Loading

0 comments on commit 980b4d3

Please sign in to comment.