mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-05 20:11:14 +08:00
fix: group level change logic (#2730)
This commit is contained in:
parent
0b612c13c6
commit
a2110e416a
@ -1526,29 +1526,61 @@ func (g *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbgroup.SetGr
|
|||||||
case 0:
|
case 0:
|
||||||
if !isAppManagerUid {
|
if !isAppManagerUid {
|
||||||
roleLevel := dbMembers[opUserIndex].RoleLevel
|
roleLevel := dbMembers[opUserIndex].RoleLevel
|
||||||
if roleLevel != constant.GroupOwner {
|
var (
|
||||||
switch roleLevel {
|
dbSelf = &model.GroupMember{}
|
||||||
case constant.GroupAdmin:
|
reqSelf *pbgroup.SetGroupMemberInfo
|
||||||
for _, member := range dbMembers {
|
)
|
||||||
if member.RoleLevel == constant.GroupOwner {
|
switch roleLevel {
|
||||||
return nil, errs.ErrNoPermission.WrapMsg("admin can not change group owner")
|
case constant.GroupOwner:
|
||||||
}
|
for _, member := range dbMembers {
|
||||||
if member.RoleLevel == constant.GroupAdmin && member.UserID != opUserID {
|
if member.UserID == opUserID {
|
||||||
return nil, errs.ErrNoPermission.WrapMsg("admin can not change other group admin")
|
dbSelf = member
|
||||||
}
|
break
|
||||||
}
|
}
|
||||||
case constant.GroupOrdinaryUsers:
|
}
|
||||||
for _, member := range dbMembers {
|
case constant.GroupAdmin:
|
||||||
if !(member.RoleLevel == constant.GroupOrdinaryUsers && member.UserID == opUserID) {
|
for _, member := range dbMembers {
|
||||||
return nil, errs.ErrNoPermission.WrapMsg("ordinary users can not change other role level")
|
if member.UserID == opUserID {
|
||||||
}
|
dbSelf = member
|
||||||
}
|
}
|
||||||
default:
|
if member.RoleLevel == constant.GroupOwner {
|
||||||
for _, member := range dbMembers {
|
return nil, errs.ErrNoPermission.WrapMsg("admin can not change group owner")
|
||||||
if member.RoleLevel >= roleLevel {
|
|
||||||
return nil, errs.ErrNoPermission.WrapMsg("can not change higher role level")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if member.RoleLevel == constant.GroupAdmin && member.UserID != opUserID {
|
||||||
|
return nil, errs.ErrNoPermission.WrapMsg("admin can not change other group admin")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case constant.GroupOrdinaryUsers:
|
||||||
|
for _, member := range dbMembers {
|
||||||
|
if member.UserID == opUserID {
|
||||||
|
dbSelf = member
|
||||||
|
}
|
||||||
|
if !(member.RoleLevel == constant.GroupOrdinaryUsers && member.UserID == opUserID) {
|
||||||
|
return nil, errs.ErrNoPermission.WrapMsg("ordinary users can not change other role level")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
for _, member := range dbMembers {
|
||||||
|
if member.UserID == opUserID {
|
||||||
|
dbSelf = member
|
||||||
|
}
|
||||||
|
if member.RoleLevel >= roleLevel {
|
||||||
|
return nil, errs.ErrNoPermission.WrapMsg("can not change higher role level")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, member := range req.Members {
|
||||||
|
if member.UserID == opUserID {
|
||||||
|
reqSelf = member
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if reqSelf != nil && reqSelf.RoleLevel != nil {
|
||||||
|
if reqSelf.RoleLevel.GetValue() > dbSelf.RoleLevel {
|
||||||
|
return nil, errs.ErrNoPermission.WrapMsg("can not improve role level by self")
|
||||||
|
}
|
||||||
|
if roleLevel == constant.GroupOwner {
|
||||||
|
return nil, errs.ErrArgs.WrapMsg("group owner can not change own role level") // Prevent the absence of a group owner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user