Skip to content

Commit

Permalink
feat: improve get admin role memberIDs implement. (#2666)
Browse files Browse the repository at this point in the history
* feat: implement GetSpecifiedUserGroupRequestInfo interface.

* update mongo config.

* feat: improve get admin role memberIDs implement.

* remove unused contents.

* remove unused contents.

* remove todo implement.
  • Loading branch information
mo3et authored Sep 26, 2024
1 parent 80a46b3 commit b9217f7
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 40 deletions.
21 changes: 9 additions & 12 deletions internal/rpc/group/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
}
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions pkg/common/storage/cache/cachekey/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion pkg/common/storage/cache/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions pkg/common/storage/cache/redis/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions pkg/common/storage/controller/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion pkg/common/storage/database/group_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions pkg/common/storage/database/mgo/group_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down

0 comments on commit b9217f7

Please sign in to comment.