mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-05 20:11:14 +08:00
feat: improve get admin role memberIDs implement. (#2666)
* feat: implement GetSpecifiedUserGroupRequestInfo interface. * update mongo config. * feat: improve get admin role memberIDs implement. * remove unused contents. * remove unused contents. * remove todo implement.
This commit is contained in:
parent
80a46b329d
commit
b9217f76ce
@ -66,11 +66,6 @@ type groupServer struct {
|
||||
webhookClient *webhook.Client
|
||||
}
|
||||
|
||||
func (s *groupServer) GetSpecifiedUserGroupRequestInfo(ctx context.Context, req *pbgroup.GetSpecifiedUserGroupRequestInfoReq) (*pbgroup.GetSpecifiedUserGroupRequestInfoResp, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
RpcConfig config.Group
|
||||
RedisConfig config.Redis
|
||||
@ -1756,14 +1751,21 @@ func (g *groupServer) GetGroupUsersReqApplicationList(ctx context.Context, req *
|
||||
func (g *groupServer) GetSpecifiedUserGroupRequestInfo(ctx context.Context, req *pbgroup.GetSpecifiedUserGroupRequestInfoReq) (*pbgroup.GetSpecifiedUserGroupRequestInfoResp, error) {
|
||||
opUserID := mcontext.GetOpUserID(ctx)
|
||||
|
||||
owners, err := g.db.FindGroupsOwner(ctx, []string{req.GroupID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if req.UserID != opUserID {
|
||||
req.UserID = mcontext.GetOpUserID(ctx)
|
||||
memberIDs, err := g.db.GetGroupAdminLevelMemberIDs(ctx, req.GroupID)
|
||||
adminIDs, err := g.db.GetGroupRoleLevelMemberIDs(ctx, req.GroupID, constant.GroupAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !datautil.Contain(req.UserID, memberIDs...) {
|
||||
adminIDs = append(adminIDs, owners[0].UserID)
|
||||
|
||||
if !datautil.Contain(req.UserID, adminIDs...) {
|
||||
return nil, errs.ErrNoPermission.WrapMsg("opUser no permission")
|
||||
}
|
||||
}
|
||||
@ -1786,11 +1788,6 @@ func (g *groupServer) GetSpecifiedUserGroupRequestInfo(ctx context.Context, req
|
||||
return nil, err
|
||||
}
|
||||
|
||||
owners, err := g.db.FindGroupsOwner(ctx, []string{req.GroupID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
groupMemberNum, err := g.db.MapGroupMemberNum(ctx, []string{req.GroupID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
4
pkg/common/storage/cache/cachekey/group.go
vendored
4
pkg/common/storage/cache/cachekey/group.go
vendored
@ -61,10 +61,6 @@ func GetGroupRoleLevelMemberIDsKey(groupID string, roleLevel int32) string {
|
||||
return GroupRoleLevelMemberIDsKey + groupID + "-" + strconv.Itoa(int(roleLevel))
|
||||
}
|
||||
|
||||
func GetGroupAdminLevelMemberIDsKey(groupID string) string {
|
||||
return GroupAdminLevelMemberIDsKey + groupID
|
||||
}
|
||||
|
||||
func GetGroupMemberMaxVersionKey(groupID string) string {
|
||||
return GroupMemberMaxVersionKey + groupID
|
||||
}
|
||||
|
1
pkg/common/storage/cache/group.go
vendored
1
pkg/common/storage/cache/group.go
vendored
@ -49,7 +49,6 @@ type GroupCache interface {
|
||||
FindGroupMemberUser(ctx context.Context, groupIDs []string, userID string) ([]*model.GroupMember, error)
|
||||
|
||||
GetGroupRoleLevelMemberIDs(ctx context.Context, groupID string, roleLevel int32) ([]string, error)
|
||||
GetGroupAdminLevelMemberIDs(ctx context.Context, groupID string) ([]string, error)
|
||||
GetGroupOwner(ctx context.Context, groupID string) (*model.GroupMember, error)
|
||||
GetGroupsOwner(ctx context.Context, groupIDs []string) ([]*model.GroupMember, error)
|
||||
DelGroupRoleLevel(groupID string, roleLevel []int32) GroupCache
|
||||
|
10
pkg/common/storage/cache/redis/group.go
vendored
10
pkg/common/storage/cache/redis/group.go
vendored
@ -111,10 +111,6 @@ func (g *GroupCacheRedis) getGroupRoleLevelMemberIDsKey(groupID string, roleLeve
|
||||
return cachekey.GetGroupRoleLevelMemberIDsKey(groupID, roleLevel)
|
||||
}
|
||||
|
||||
func (g *GroupCacheRedis) getGroupAdminLevelMemberIDsKey(groupID string) string {
|
||||
return cachekey.GetGroupAdminLevelMemberIDsKey(groupID)
|
||||
}
|
||||
|
||||
func (g *GroupCacheRedis) getGroupMemberMaxVersionKey(groupID string) string {
|
||||
return cachekey.GetGroupMemberMaxVersionKey(groupID)
|
||||
}
|
||||
@ -332,12 +328,6 @@ func (g *GroupCacheRedis) GetGroupRoleLevelMemberIDs(ctx context.Context, groupI
|
||||
})
|
||||
}
|
||||
|
||||
func (g *GroupCacheRedis) GetGroupAdminLevelMemberIDs(ctx context.Context, groupID string) ([]string, error) {
|
||||
return getCache(ctx, g.rcClient, g.getGroupAdminLevelMemberIDsKey(groupID), g.expireTime, func(ctx context.Context) ([]string, error) {
|
||||
return g.groupMemberDB.FindAdminLevelUserIDs(ctx, groupID)
|
||||
})
|
||||
}
|
||||
|
||||
func (g *GroupCacheRedis) GetGroupRoleLevelMemberInfo(ctx context.Context, groupID string, roleLevel int32) ([]*model.GroupMember, error) {
|
||||
userIDs, err := g.GetGroupRoleLevelMemberIDs(ctx, groupID, roleLevel)
|
||||
if err != nil {
|
||||
|
@ -71,8 +71,6 @@ type GroupDatabase interface {
|
||||
PageGroupRequest(ctx context.Context, groupIDs []string, pagination pagination.Pagination) (int64, []*model.GroupRequest, error)
|
||||
// GetGroupRoleLevelMemberIDs retrieves user IDs of group members with a specific role level.
|
||||
GetGroupRoleLevelMemberIDs(ctx context.Context, groupID string, roleLevel int32) ([]string, error)
|
||||
// GetGroupAdminLevelMemberIDs retrieves user IDs of group members with an admin role level.
|
||||
GetGroupAdminLevelMemberIDs(ctx context.Context, groupID string) ([]string, error)
|
||||
|
||||
// PageGetJoinGroup paginates through groups that a user has joined.
|
||||
PageGetJoinGroup(ctx context.Context, userID string, pagination pagination.Pagination) (total int64, totalGroupMembers []*model.GroupMember, err error)
|
||||
@ -182,10 +180,6 @@ func (g *groupDatabase) GetGroupRoleLevelMemberIDs(ctx context.Context, groupID
|
||||
return g.cache.GetGroupRoleLevelMemberIDs(ctx, groupID, roleLevel)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) GetGroupAdminLevelMemberIDs(ctx context.Context, groupID string) ([]string, error) {
|
||||
return g.cache.GetGroupAdminLevelMemberIDs(ctx, groupID)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) CreateGroup(ctx context.Context, groups []*model.Group, groupMembers []*model.GroupMember) error {
|
||||
if len(groups)+len(groupMembers) == 0 {
|
||||
return nil
|
||||
|
@ -34,7 +34,6 @@ type GroupMember interface {
|
||||
TakeOwner(ctx context.Context, groupID string) (groupMember *model.GroupMember, err error)
|
||||
SearchMember(ctx context.Context, keyword string, groupID string, pagination pagination.Pagination) (total int64, groupList []*model.GroupMember, err error)
|
||||
FindRoleLevelUserIDs(ctx context.Context, groupID string, roleLevel int32) ([]string, error)
|
||||
FindAdminLevelUserIDs(ctx context.Context, groupID string) ([]string, error)
|
||||
FindUserJoinedGroupID(ctx context.Context, userID string) (groupIDs []string, err error)
|
||||
TakeGroupMemberNum(ctx context.Context, groupID string) (count int64, err error)
|
||||
FindUserManagedGroupID(ctx context.Context, userID string) (groupIDs []string, err error)
|
||||
|
@ -187,12 +187,6 @@ func (g *GroupMemberMgo) FindRoleLevelUserIDs(ctx context.Context, groupID strin
|
||||
return mongoutil.Find[string](ctx, g.coll, bson.M{"group_id": groupID, "role_level": roleLevel}, options.Find().SetProjection(bson.M{"_id": 0, "user_id": 1}))
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) FindAdminLevelUserIDs(ctx context.Context, groupID string) ([]string, error) {
|
||||
return mongoutil.Find[string](ctx, g.coll,
|
||||
bson.M{"group_id": groupID, "role_level": bson.M{"$gte": constant.GroupAdmin}},
|
||||
options.Find().SetProjection(bson.M{"_id": 0, "user_id": 1}))
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) SearchMember(ctx context.Context, keyword string, groupID string, pagination pagination.Pagination) (int64, []*model.GroupMember, error) {
|
||||
filter := bson.M{"group_id": groupID, "nickname": bson.M{"$regex": keyword}}
|
||||
return mongoutil.FindPage[*model.GroupMember](ctx, g.coll, filter, pagination, options.Find().SetSort(g.memberSort()))
|
||||
|
Loading…
x
Reference in New Issue
Block a user