This commit is contained in:
Archer
2023-11-15 11:36:25 +08:00
committed by GitHub
parent 592e1a93a2
commit bfd8be5df0
181 changed files with 2499 additions and 1552 deletions

View File

@@ -1,5 +1,7 @@
import { AuthUserTypeEnum } from '@fastgpt/global/support/permission/constant';
import { parseHeaderCert } from '../controller';
import { AuthModeType } from '../type';
import { authOutLinkValid } from './outLink';
export const authCert = async (props: AuthModeType) => {
const result = await parseHeaderCert(props);
@@ -10,3 +12,22 @@ export const authCert = async (props: AuthModeType) => {
canWrite: true
};
};
export async function authCertAndShareId({
shareId,
...props
}: AuthModeType & { shareId?: string }) {
if (!shareId) {
return authCert(props);
}
const { app } = await authOutLinkValid({ shareId });
return {
teamId: String(app.teamId),
tmbId: String(app.tmbId),
authType: AuthUserTypeEnum.outLink,
apikey: '',
isOwner: false,
canWrite: false
};
}

View File

@@ -27,11 +27,11 @@ export async function authDataset({
}
> {
const result = await parseHeaderCert(props);
const { userId, teamId, tmbId } = result;
const { teamId, tmbId } = result;
const { role } = await getTeamInfoByTmbId({ tmbId });
const { dataset, isOwner, canWrite } = await (async () => {
const dataset = (await MongoDataset.findOne({ _id: datasetId, teamId }))?.toJSON();
const dataset = (await MongoDataset.findOne({ _id: datasetId, teamId }))?.toObject();
if (!dataset) {
return Promise.reject(DatasetErrEnum.unAuthDataset);

View File

@@ -6,7 +6,6 @@ import { getTeamInfoByTmbId } from '../../user/team/controller';
import { MongoOpenApi } from '../../openapi/schema';
import { OpenApiErrEnum } from '@fastgpt/global/common/error/code/openapi';
import { TeamMemberRoleEnum } from '@fastgpt/global/support/user/team/constant';
import { PermissionTypeEnum } from '@fastgpt/global/support/permission/constant';
export async function authOpenApiKeyCrud({
id,

View File

@@ -37,13 +37,11 @@ export async function authUserRole(props: AuthModeType): Promise<
teamOwner: boolean;
}
> {
const { userId, teamId, tmbId } = await parseHeaderCert(props);
const { role: userRole, canWrite } = await getTeamInfoByTmbId({ tmbId });
const result = await parseHeaderCert(props);
const { role: userRole, canWrite } = await getTeamInfoByTmbId({ tmbId: result.tmbId });
return {
userId,
teamId,
tmbId,
...result,
isOwner: true,
role: userRole,
teamOwner: userRole === TeamMemberRoleEnum.owner,