feat: org CRUD (#3380)
* feat: add org schema * feat: org manage UI * feat: OrgInfoModal * feat: org tree view * feat: org management * fix: init root org * feat: org permission for app * feat: org support for dataset * fix: disable org role control * styles: opt type signatures * fix: remove unused permission * feat: delete org collaborator
This commit is contained in:
58
packages/service/support/permission/auth/org.ts
Normal file
58
packages/service/support/permission/auth/org.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { TeamPermission } from '@fastgpt/global/support/permission/user/controller';
|
||||
import { AuthModeType, AuthResponseType } from '../type';
|
||||
import { parseHeaderCert } from '../controller';
|
||||
import { getTmbInfoByTmbId } from '../../user/team/controller';
|
||||
import { TeamErrEnum } from '@fastgpt/global/common/error/code/team';
|
||||
|
||||
export const authOrgMember = async ({
|
||||
orgIds,
|
||||
req,
|
||||
authToken = false,
|
||||
authRoot = false,
|
||||
authApiKey = false
|
||||
}: {
|
||||
orgIds: string | string[];
|
||||
} & AuthModeType): Promise<AuthResponseType> => {
|
||||
const result = await parseHeaderCert({ req, authToken, authApiKey, authRoot });
|
||||
const { teamId, tmbId, isRoot } = result;
|
||||
if (isRoot) {
|
||||
return {
|
||||
teamId,
|
||||
tmbId,
|
||||
userId: result.userId,
|
||||
appId: result.appId,
|
||||
apikey: result.apikey,
|
||||
isRoot,
|
||||
authType: result.authType,
|
||||
permission: new TeamPermission({ isOwner: true })
|
||||
};
|
||||
}
|
||||
|
||||
if (!Array.isArray(orgIds)) {
|
||||
orgIds = [orgIds];
|
||||
}
|
||||
|
||||
// const promises = orgIds.map((orgId) => getOrgMemberRole({ orgId, tmbId }));
|
||||
|
||||
const tmb = await getTmbInfoByTmbId({ tmbId });
|
||||
if (tmb.permission.hasManagePer) {
|
||||
return {
|
||||
...result,
|
||||
permission: tmb.permission
|
||||
};
|
||||
}
|
||||
|
||||
return Promise.reject(TeamErrEnum.unAuthTeam);
|
||||
|
||||
// const targetRole = OrgMemberRole[role];
|
||||
// for (const orgRole of orgRoles) {
|
||||
// if (!orgRole || checkOrgRole(orgRole, targetRole)) {
|
||||
// return Promise.reject(TeamErrEnum.unAuthTeam);
|
||||
// }
|
||||
// }
|
||||
|
||||
// return {
|
||||
// ...result,
|
||||
// permission: tmb.permission
|
||||
// };
|
||||
};
|
||||
Reference in New Issue
Block a user