mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-24 22:03:54 +00:00

* feat: dataset controllers feat: dataset schema fix: add missing type to dataset schema Signed-off-by: FinleyGe <m13203533462@163.com> * feat: dataset list api Signed-off-by: FinleyGe <m13203533462@163.com> * chore: all dataset api Signed-off-by: FinleyGe <m13203533462@163.com> * feat: new auth dataset method Signed-off-by: FinleyGe <m13203533462@163.com> * chore: use new auth method in detail, paths. feat: add new param defaultPermission to create api Signed-off-by: FinleyGe <m13203533462@163.com> * chore: app auth params Signed-off-by: FinleyGe <m13203533462@163.com> * chore: use new auth method Signed-off-by: FinleyGe <m13203533462@163.com> * feat: new auth collection and file method Signed-off-by: FinleyGe <m13203533462@163.com> * chore: dataset collection api new auth Signed-off-by: FinleyGe <m13203533462@163.com> * chore: create/*.ts auth Signed-off-by: FinleyGe <m13203533462@163.com> * chore: dataset auth Signed-off-by: FinleyGe <m13203533462@163.com> * fix: import paths Signed-off-by: FinleyGe <m13203533462@163.com> * feat: dataset collaborator Signed-off-by: FinleyGe <m13203533462@163.com> * chore: dataset frontend feat: dataset list frontend feat: dataset detail Signed-off-by: FinleyGe <m13203533462@163.com> * feat: finish the dataset permission fix: ts errors Signed-off-by: FinleyGe <m13203533462@163.com> * fix: empty response of collection api Signed-off-by: FinleyGe <m13203533462@163.com> * chore: adjust the code * chore: adjust the code * chore: i18n * fix: ts error * fix: fe CollectionCard permission --------- Signed-off-by: FinleyGe <m13203533462@163.com>
83 lines
2.0 KiB
TypeScript
83 lines
2.0 KiB
TypeScript
/* Auth app permission */
|
|
import { MongoApp } from '../../../core/app/schema';
|
|
import { AppDetailType } from '@fastgpt/global/core/app/type.d';
|
|
import { AuthPropsType } from '../type/auth.d';
|
|
import { parseHeaderCert } from '../controller';
|
|
import { PerResourceTypeEnum } from '@fastgpt/global/support/permission/constant';
|
|
import { AppErrEnum } from '@fastgpt/global/common/error/code/app';
|
|
import { getTmbInfoByTmbId } from '../../user/team/controller';
|
|
import { getResourcePermission } from '../controller';
|
|
import { AppPermission } from '@fastgpt/global/support/permission/app/controller';
|
|
import { AuthResponseType } from '../type/auth.d';
|
|
import { PermissionValueType } from '@fastgpt/global/support/permission/type';
|
|
|
|
export const authAppByTmbId = async ({
|
|
tmbId,
|
|
appId,
|
|
per
|
|
}: {
|
|
tmbId: string;
|
|
appId: string;
|
|
per: PermissionValueType;
|
|
}) => {
|
|
const { teamId, permission: tmbPer } = await getTmbInfoByTmbId({ tmbId });
|
|
|
|
const app = await (async () => {
|
|
// get app and per
|
|
const [app, rp] = await Promise.all([
|
|
MongoApp.findOne({ _id: appId, teamId }).lean(),
|
|
getResourcePermission({
|
|
teamId,
|
|
tmbId,
|
|
resourceId: appId,
|
|
resourceType: PerResourceTypeEnum.app
|
|
}) // this could be null
|
|
]);
|
|
|
|
if (!app) {
|
|
return Promise.reject(AppErrEnum.unExist);
|
|
}
|
|
|
|
const isOwner = tmbPer.isOwner || String(app.tmbId) === tmbId;
|
|
const Per = new AppPermission({ per: rp?.permission ?? app.defaultPermission, isOwner });
|
|
|
|
if (!Per.checkPer(per)) {
|
|
return Promise.reject(AppErrEnum.unAuthApp);
|
|
}
|
|
|
|
return {
|
|
...app,
|
|
permission: Per
|
|
};
|
|
})();
|
|
|
|
return { app };
|
|
};
|
|
|
|
export const authApp = async ({
|
|
appId,
|
|
per,
|
|
...props
|
|
}: AuthPropsType & {
|
|
appId: string;
|
|
}): Promise<
|
|
AuthResponseType & {
|
|
app: AppDetailType;
|
|
}
|
|
> => {
|
|
const result = await parseHeaderCert(props);
|
|
const { tmbId } = result;
|
|
|
|
const { app } = await authAppByTmbId({
|
|
tmbId,
|
|
appId,
|
|
per
|
|
});
|
|
|
|
return {
|
|
...result,
|
|
permission: app.permission,
|
|
app
|
|
};
|
|
};
|