Skip to content

Commit

Permalink
Team group (#2864)
Browse files Browse the repository at this point in the history
* feat(member-group): Team (#2616)

* feat: member-group schema define

* feat(fe): create group

* feat: add group edit modal

* feat(fe): add avatar group component

* feat: edit group
fix: permission select menu style

* feat: bio-mode support for select-member component

* fix: avatar group key unique

* feat: group manage

* feat: divide member into group and clbs

* feat: finish team permission

* chore: adjust

* fix: get clbs

* perf: groups code

* pref: member group for team (#2706)

* chore: fe adjust
fix: remove the member from groups when removing from team
feat: change the groups avatar when updating the team's avatar

* chore: DefaultGroupName as a constant string ''

* fix: create default group when create team for root

* feat: comment

* feat: 4811 init

* pref: member group for team (#2732)

* chore: default group name

* feat: get default group when get by tmbid

* feat(fe): adjust

* member ui

* fix: delete group (#2736)

* perf: init4811

* pref: member group (#2818)

* fix: update clb per then refetch clb list

* fix: calculate group permission

* feat(fe): group tag

* refactor(fe): team and group manage

* feat: manage group member

* feat: add group transfer owner modal

* feat: group manage member

* chore: adjust the file structure

* pref: member group

* chore: adjust fe style

* fix: ts error

* chore: fe adjust

* chore: fe adjust

* chore: adjust

* chore: adjust the code

* perf: i18n and schema name

* pref: member-group (#2862)

* feat: group list ordered by updateTime

* fix: transfer ownership of group when deleting member

* fix: i18n fix

* feat: can not set member as admin/owner when user is not active

* fix: GroupInfoModal hover input do not change color

* fix(fe): searchinput do not scroll

* perf: team group ui

* doc

* remove enum

---------

Co-authored-by: Finley Ge <[email protected]>
  • Loading branch information
c121914yu and FinleyGe authored Oct 9, 2024
1 parent 7afa8f0 commit 3a4b4a8
Show file tree
Hide file tree
Showing 80 changed files with 2,663 additions and 744 deletions.
23 changes: 12 additions & 11 deletions docSite/content/zh-cn/docs/development/upgrading/4811.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ weight: 813
13. 新增 - 支持工作流嵌套子应用时,可以设置`非流模式`,同时简易模式也可以选择工作流作为插件了,简易模式调用子应用时,都将强制使用非流模式。
14. 新增 - 调试模式下,子应用调用,支持返回详细运行数据。
15. 新增 - 保留所有模式下子应用嵌套调用的日志。
16. 优化 - 工作流嵌套层级限制 20 层,避免因编排不合理导致的无限死循环。
17. 优化 - 工作流 handler 性能优化。
18. 优化 - 工作流快捷键,避免调试测试时也会触发复制和回退。
19. 修复 - 工作流工具调用中修改全局变量后,无法传递到后续流程。
20. 优化 - 流输出,切换浏览器 Tab 后仍可以继续输出。
21. 优化 - 完善外部文件知识库相关 API
22. 修复 - 知识库选择权限问题。
23. 修复 - 空 chatId 发起对话,首轮携带用户选择时会异常。
24. 修复 - createDataset 接口,intro 为赋值。
25. 修复 - 对话框渲染性能问题。
26. 修复 - 工具调用历史记录存储不正确。
16. 新增 - 商业版支持团队成员组,后续将逐渐覆盖工作台和知识库权限。
17. 优化 - 工作流嵌套层级限制 20 层,避免因编排不合理导致的无限死循环。
18. 优化 - 工作流 handler 性能优化。
19. 优化 - 工作流快捷键,避免调试测试时也会触发复制和回退。
20. 修复 - 工作流工具调用中修改全局变量后,无法传递到后续流程。
21. 优化 - 流输出,切换浏览器 Tab 后仍可以继续输出。
22. 优化 - 完善外部文件知识库相关 API
23. 修复 - 知识库选择权限问题。
24. 修复 - 空 chatId 发起对话,首轮携带用户选择时会异常。
25. 修复 - createDataset 接口,intro 为赋值。
26. 修复 - 对话框渲染性能问题。
27. 修复 - 工具调用历史记录存储不正确。
27 changes: 26 additions & 1 deletion packages/global/common/error/code/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ export enum TeamErrEnum {
appAmountNotEnough = 'appAmountNotEnough',
pluginAmountNotEnough = 'pluginAmountNotEnough',
websiteSyncNotEnough = 'websiteSyncNotEnough',
reRankNotEnough = 'reRankNotEnough'
reRankNotEnough = 'reRankNotEnough',
groupNameEmpty = 'groupNameEmpty',
groupNameDuplicate = 'groupNameDuplicate',
groupNotExist = 'groupNotExist',
cannotDeleteDefaultGroup = 'cannotDeleteDefaultGroup',
userNotActive = 'userNotActive'
}

const teamErr = [
Expand Down Expand Up @@ -46,6 +51,26 @@ const teamErr = [
{
statusText: TeamErrEnum.reRankNotEnough,
message: i18nT('common:code_error.team_error.re_rank_not_enough')
},
{
statusText: TeamErrEnum.groupNameEmpty,
message: i18nT('common:code_error.team_error.group_name_empty')
},
{
statusText: TeamErrEnum.groupNotExist,
message: i18nT('common:code_error.team_error.group_not_exist')
},
{
statusText: TeamErrEnum.cannotDeleteDefaultGroup,
message: i18nT('common:code_error.team_error.cannot_delete_default_group')
},
{
statusText: TeamErrEnum.groupNameDuplicate,
message: i18nT('common:code_error.team_error.group_name_duplicate')
},
{
statusText: TeamErrEnum.userNotActive,
message: i18nT('common:code_error.team_error.user_not_active')
}
];

Expand Down
5 changes: 5 additions & 0 deletions packages/global/common/file/image/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum MongoImageTypeEnum {
datasetAvatar = 'datasetAvatar',
userAvatar = 'userAvatar',
teamAvatar = 'teamAvatar',
groupAvatar = 'groupAvatar',

chatImage = 'chatImage',
collectionImage = 'collectionImage'
Expand Down Expand Up @@ -36,6 +37,10 @@ export const mongoImageTypeMap = {
label: 'teamAvatar',
unique: true
},
[MongoImageTypeEnum.groupAvatar]: {
label: 'groupAvatar',
unique: true
},

[MongoImageTypeEnum.chatImage]: {
label: 'chatImage',
Expand Down
1 change: 1 addition & 0 deletions packages/global/common/system/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const HUMAN_ICON = `/icon/human.svg`;
export const LOGO_ICON = `/icon/logo.svg`;
export const HUGGING_FACE_ICON = `/imgs/model/huggingface.svg`;
export const DEFAULT_TEAM_AVATAR = `/imgs/avatar/defaultTeamAvatar.svg`;
16 changes: 15 additions & 1 deletion packages/global/support/permission/collaborator.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RequireAtLeastOne, RequireOnlyOne } from '../../common/type/utils';
import { Permission } from './controller';
import { PermissionValueType } from './type';

Expand All @@ -10,6 +11,19 @@ export type CollaboratorItemType = {
};

export type UpdateClbPermissionProps = {
tmbIds: string[];
members?: string[];
groups?: string[];
permission: PermissionValueType;
};

export type DeleteClbPermissionProps = RequireOnlyOne<{
tmbId: string;
groupId: string;
}>;

export type UpdatePermissionBody = {
permission: PermissionValueType;
} & RequireOnlyOne<{
memberId: string;
groupId: string;
}>;
2 changes: 1 addition & 1 deletion packages/global/support/permission/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const PermissionList: PermissionListType = {
[PermissionKeyEnum.write]: {
name: i18nT('common:permission.write'),
description: '',
value: 0b110, // 如果某个资源有特殊要求,再重写这个值
value: 0b110,
checkBoxType: 'single'
},
[PermissionKeyEnum.manage]: {
Expand Down
38 changes: 22 additions & 16 deletions packages/global/support/permission/controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { PermissionValueType } from './type';
import { PermissionListType, PermissionValueType } from './type';
import { PermissionList, NullPermission, OwnerPermissionVal } from './constant';

export type PerConstructPros = {
per?: PermissionValueType;
isOwner?: boolean;
permissionList?: PermissionListType;
};

// the Permission helper class
Expand All @@ -13,19 +14,21 @@ export class Permission {
hasManagePer: boolean;
hasWritePer: boolean;
hasReadPer: boolean;
_permissionList: PermissionListType;

constructor(props?: PerConstructPros) {
const { per = NullPermission, isOwner = false } = props || {};
const { per = NullPermission, isOwner = false, permissionList = PermissionList } = props || {};
if (isOwner) {
this.value = OwnerPermissionVal;
} else {
this.value = per;
}

this.isOwner = isOwner;
this.hasManagePer = this.checkPer(PermissionList['manage'].value);
this.hasWritePer = this.checkPer(PermissionList['write'].value);
this.hasReadPer = this.checkPer(PermissionList['read'].value);
this._permissionList = permissionList;
this.hasManagePer = this.checkPer(this._permissionList['manage'].value);
this.hasWritePer = this.checkPer(this._permissionList['write'].value);
this.hasReadPer = this.checkPer(this._permissionList['read'].value);
}

// add permission(s)
Expand All @@ -36,36 +39,39 @@ export class Permission {
// perm.add(PermissionList['read'], PermissionList['write'])
// perm.add(PermissionList['read']).add(PermissionList['write'])
addPer(...perList: PermissionValueType[]) {
for (let oer of perList) {
this.value = this.value | oer;
if (this.isOwner) {
return this;
}
for (const per of perList) {
this.value = this.value | per;
}
this.updatePermissions();
return this.value;
return this;
}

removePer(...perList: PermissionValueType[]) {
for (let per of perList) {
if (this.isOwner) {
return this.value;
}
for (const per of perList) {
this.value = this.value & ~per;
}
this.updatePermissions();
return this.value;
return this;
}

checkPer(perm: PermissionValueType): boolean {
// if the permission is owner permission, only owner has this permission.
if (perm === OwnerPermissionVal) {
return this.value === OwnerPermissionVal;
} else if (this.hasManagePer) {
// The manager has all permissions except the owner permission
return true;
}
return (this.value & perm) === perm;
}

private updatePermissions() {
this.isOwner = this.value === OwnerPermissionVal;
this.hasManagePer = this.checkPer(PermissionList['manage'].value);
this.hasWritePer = this.checkPer(PermissionList['write'].value);
this.hasReadPer = this.checkPer(PermissionList['read'].value);
this.hasManagePer = this.checkPer(this._permissionList['manage'].value);
this.hasWritePer = this.checkPer(this._permissionList['write'].value);
this.hasReadPer = this.checkPer(this._permissionList['read'].value);
}
}
23 changes: 23 additions & 0 deletions packages/global/support/permission/memberGroup/constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { PermissionKeyEnum, PermissionList } from '../constant';
import { PermissionListType } from '../type';

export enum GroupMemberRole {
owner = 'owner',
admin = 'admin',
member = 'member'
}

export const memberGroupPermissionList: PermissionListType = {
[PermissionKeyEnum.read]: {
...PermissionList[PermissionKeyEnum.read],
value: 0b100
},
[PermissionKeyEnum.write]: {
...PermissionList[PermissionKeyEnum.write],
value: 0b010
},
[PermissionKeyEnum.manage]: {
...PermissionList[PermissionKeyEnum.manage],
value: 0b001
}
};
27 changes: 27 additions & 0 deletions packages/global/support/permission/memberGroup/type.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { TeamMemberItemType } from 'support/user/team/type';
import { TeamPermission } from '../user/controller';
import { GroupMemberRole } from './constant';

type MemberGroupSchemaType = {
_id: string;
teamId: string;
name: string;
avatar: string;
updateTime: Date;
};

type GroupMemberSchemaType = {
groupId: string;
tmbId: string;
role: `${GroupMemberRole}`;
};

type MemberGroupType = MemberGroupSchemaType & {
members: {
tmbId: string;
role: `${GroupMemberRole}`;
}[]; // we can get tmb's info from other api. there is no need but only need to get tmb's id
permission: TeamPermission;
};

type MemberGroupListType = MemberGroupType[];
7 changes: 5 additions & 2 deletions packages/global/support/permission/type.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RequireOnlyOne } from '../../common/type/utils';
import { TeamMemberWithUserSchema } from '../user/team/type';
import { AuthUserTypeEnum, PermissionKeyEnum, PerResourceTypeEnum } from './constant';

Expand All @@ -20,11 +21,13 @@ export type PermissionListType<T = {}> = Record<

export type ResourcePermissionType = {
teamId: string;
tmbId: string;
resourceType: ResourceType;
permission: PermissionValueType;
resourceId: string;
};
} & RequireOnlyOne<{
tmbId: string;
groupId: string;
}>;

export type ResourcePerWithTmbWithUser = Omit<ResourcePermissionType, 'tmbId'> & {
tmbId: TeamMemberWithUserSchema;
Expand Down
15 changes: 9 additions & 6 deletions packages/global/support/permission/user/constant.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { PermissionKeyEnum, PermissionList, ReadPermissionVal } from '../constant';
import { PermissionKeyEnum } from '../constant';
import { PermissionListType } from '../type';
import { i18nT } from '../../../../web/i18n/utils';
import { PermissionList } from '../constant';
export const TeamPermissionList: PermissionListType = {
[PermissionKeyEnum.read]: {
...PermissionList[PermissionKeyEnum.read],
description: i18nT('user:permission_des.read')
value: 0b100
},
[PermissionKeyEnum.write]: {
...PermissionList[PermissionKeyEnum.write],
description: i18nT('user:permission_des.write')
value: 0b010
},
[PermissionKeyEnum.manage]: {
...PermissionList[PermissionKeyEnum.manage],
description: i18nT('user:permission_des.manage')
value: 0b001
}
};

export const TeamDefaultPermissionVal = ReadPermissionVal;
export const TeamReadPermissionVal = TeamPermissionList['read'].value;
export const TeamWritePermissionVal = TeamPermissionList['write'].value;
export const TeamManagePermissionVal = TeamPermissionList['manage'].value;
export const TeamDefaultPermissionVal = TeamReadPermissionVal;
3 changes: 2 additions & 1 deletion packages/global/support/permission/user/controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PerConstructPros, Permission } from '../controller';
import { TeamDefaultPermissionVal } from './constant';
import { TeamDefaultPermissionVal, TeamPermissionList } from './constant';

export class TeamPermission extends Permission {
constructor(props?: PerConstructPros) {
Expand All @@ -10,6 +10,7 @@ export class TeamPermission extends Permission {
} else if (!props?.per) {
props.per = TeamDefaultPermissionVal;
}
props.permissionList = TeamPermissionList;
super(props);
}
}
1 change: 0 additions & 1 deletion packages/global/support/user/team/controller.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export type UpdateTeamMemberProps = {
export type InviteMemberProps = {
teamId: string;
usernames: string[];
permission: PermissionValueType;
};
export type UpdateInviteProps = {
tmbId: string;
Expand Down
17 changes: 17 additions & 0 deletions packages/global/support/user/team/group/api.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { GroupMemberRole } from '../../../../support/permission/memberGroup/constant';

export type postCreateGroupData = {
name: string;
avatar?: string;
memberIdList?: string[];
};

export type putUpdateGroupData = {
groupId: string;
name?: string;
avatar?: string;
memberList?: {
tmbId: string;
role: `${GroupMemberRole}`;
}[];
};
1 change: 1 addition & 0 deletions packages/global/support/user/team/group/constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DefaultGroupName = 'DEFAULT_GROUP';
4 changes: 3 additions & 1 deletion packages/global/support/user/team/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export type TeamSchema = {
lastWebsiteSyncTime: Date;
};
lafAccount: LafAccountType;
defaultPermission: PermissionValueType;
notificationAccount?: string;
};

export type tagsType = {
label: string;
key: string;
};

export type TeamTagSchema = TeamTagItemType & {
_id: string;
teamId: string;
Expand All @@ -45,9 +45,11 @@ export type TeamMemberSchema = {
export type TeamMemberWithUserSchema = Omit<TeamMemberSchema, 'userId'> & {
userId: UserModelSchema;
};

export type TeamMemberWithTeamSchema = Omit<TeamMemberSchema, 'teamId'> & {
teamId: TeamSchema;
};

export type TeamMemberWithTeamAndUserSchema = Omit<TeamMemberWithTeamSchema, 'userId'> & {
userId: UserModelSchema;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/service/support/permission/app/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const authAppByTmbId = async ({
resourceId: appId,
resourceType: PerResourceTypeEnum.app
});
const Per = new AppPermission({ per: rp?.permission ?? app.defaultPermission, isOwner });
const Per = new AppPermission({ per: rp ?? app.defaultPermission, isOwner });
return {
Per,
defaultPermission: app.defaultPermission
Expand Down
Loading

0 comments on commit 3a4b4a8

Please sign in to comment.