mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 08:25:07 +00:00

* chore: usePagination hook type * feat: chat log show outlinkuid or tmb avatar and name * fix: ts error for pagination * feat: auth root
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { TeamTmbItemType } from '@fastgpt/global/support/user/team/type';
|
|
import { parseHeaderCert } from '../controller';
|
|
import { getTmbInfoByTmbId } from '../../user/team/controller';
|
|
import { TeamErrEnum } from '@fastgpt/global/common/error/code/team';
|
|
import { AuthModeType, AuthResponseType } from '../type';
|
|
import { NullPermission } from '@fastgpt/global/support/permission/constant';
|
|
import { TeamPermission } from '@fastgpt/global/support/permission/user/controller';
|
|
|
|
/* auth user role */
|
|
export async function authUserPer(props: AuthModeType): Promise<
|
|
AuthResponseType & {
|
|
tmb: TeamTmbItemType;
|
|
}
|
|
> {
|
|
const result = await parseHeaderCert(props);
|
|
const tmb = await getTmbInfoByTmbId({ tmbId: result.tmbId });
|
|
|
|
if (result.isRoot) {
|
|
return {
|
|
...result,
|
|
permission: new TeamPermission({
|
|
isOwner: true
|
|
}),
|
|
tmb
|
|
};
|
|
}
|
|
if (!tmb.permission.checkPer(props.per ?? NullPermission)) {
|
|
return Promise.reject(TeamErrEnum.unAuthTeam);
|
|
}
|
|
|
|
return {
|
|
...result,
|
|
permission: tmb.permission,
|
|
tmb
|
|
};
|
|
}
|