mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-18 09:24:03 +00:00

* refactor: permission role * refactor: permission type * fix: permission manage * fix: group owner cannot be deleted * chore: common per map * chore: openapi * chore: rename * fix: type error * chore: app chat log permission * chore: add initv4112
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import { type PermissionValueType } from './type';
|
|
import { NullRoleVal, PermissionTypeEnum } from './constant';
|
|
import type { Permission } from './controller';
|
|
|
|
/* team public source, or owner source in team */
|
|
export function mongoRPermission({
|
|
teamId,
|
|
tmbId,
|
|
permission
|
|
}: {
|
|
teamId: string;
|
|
tmbId: string;
|
|
permission: Permission;
|
|
}) {
|
|
if (permission.isOwner) {
|
|
return {
|
|
teamId
|
|
};
|
|
}
|
|
return {
|
|
teamId,
|
|
$or: [{ permission: PermissionTypeEnum.public }, { tmbId }]
|
|
};
|
|
}
|
|
export function mongoOwnerPermission({ teamId, tmbId }: { teamId: string; tmbId: string }) {
|
|
return {
|
|
teamId,
|
|
tmbId
|
|
};
|
|
}
|
|
|
|
// return permission-related schema to define the schema of resources
|
|
export function getPermissionSchema(defaultPermission: PermissionValueType = NullRoleVal) {
|
|
return {
|
|
defaultPermission: {
|
|
type: Number,
|
|
default: defaultPermission
|
|
},
|
|
inheritPermission: {
|
|
type: Boolean,
|
|
default: true
|
|
}
|
|
};
|
|
}
|
|
|
|
export const sumPer = (...per: PermissionValueType[]) => {
|
|
if (per.length === 0) {
|
|
// prevent sum 0 value, to fallback to default value
|
|
return undefined;
|
|
}
|
|
return per.reduce((acc, cur) => acc | cur, 0);
|
|
};
|