Files
FastGPT/packages/service/support/permission/evaluation/auth.ts
YeYuheng 84570bda6f fix:agent eval and doc file (#6158)
* agent eval

* eval auth

* html transofrm size

* fix: test

---------

Co-authored-by: xxyyh <2289112474@qq>
Co-authored-by: archer <545436317@qq.com>
2025-12-30 11:20:55 +08:00

81 lines
1.7 KiB
TypeScript

import { authAppByTmbId } from '../app/auth';
import {
ManagePermissionVal,
ReadPermissionVal
} from '@fastgpt/global/support/permission/constant';
import type { EvaluationSchemaType } from '@fastgpt/global/core/app/evaluation/type';
import type { AuthModeType } from '../type';
import { MongoEvaluation } from '../../../core/app/evaluation/evalSchema';
import { parseHeaderCert } from '../auth/common';
import { AppErrEnum } from '@fastgpt/global/common/error/code/app';
export const authEval = async ({
evalId,
per = ReadPermissionVal,
...props
}: AuthModeType & {
evalId: string;
}): Promise<{
evaluation: EvaluationSchemaType;
tmbId: string;
teamId: string;
}> => {
const { teamId, tmbId, isRoot } = await parseHeaderCert(props);
const evaluation = await MongoEvaluation.findOne(
{
_id: evalId,
teamId
},
'tmbId appId'
).lean();
if (!evaluation) {
return Promise.reject('Evaluation not found');
}
if (String(evaluation.tmbId) === tmbId) {
return {
teamId,
tmbId,
evaluation
};
}
try {
// App read per
if (per === ReadPermissionVal) {
await authAppByTmbId({
tmbId,
appId: evaluation.appId,
per: ReadPermissionVal,
isRoot
});
return {
teamId,
tmbId,
evaluation
};
}
// Write per
await authAppByTmbId({
tmbId,
appId: evaluation.appId,
per: ManagePermissionVal,
isRoot
});
} catch (error) {
// If app does not exist, allow operation (app was deleted, allow eval cleanup)
if (error !== AppErrEnum.unExist) {
throw error;
}
}
return {
teamId,
tmbId,
evaluation
};
};