mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-31 04:23:43 +08:00
fix: 修复群管理踢人权限过高问题
This commit is contained in:
@@ -104,6 +104,23 @@ public class GroupMemberDao extends ServiceImpl<GroupMemberMapper, GroupMember>
|
||||
GroupMember groupMember = this.lambdaQuery()
|
||||
.eq(GroupMember::getGroupId, id)
|
||||
.eq(GroupMember::getUid, uid)
|
||||
.eq(GroupMember::getRole, GroupRoleEnum.LEADER.getType())
|
||||
.one();
|
||||
return ObjectUtil.isNotNull(groupMember);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是管理员
|
||||
*
|
||||
* @param id 群组ID
|
||||
* @param uid 用户ID
|
||||
* @return 是否是管理员
|
||||
*/
|
||||
public Boolean isManager(Long id, Long uid) {
|
||||
GroupMember groupMember = this.lambdaQuery()
|
||||
.eq(GroupMember::getGroupId, id)
|
||||
.eq(GroupMember::getUid, uid)
|
||||
.eq(GroupMember::getRole, GroupRoleEnum.MANAGER.getType())
|
||||
.one();
|
||||
return ObjectUtil.isNotNull(groupMember);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.abin.mallchat.common.common.annotation.RedissonLock;
|
||||
import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq;
|
||||
import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp;
|
||||
import com.abin.mallchat.common.common.event.GroupMemberAddEvent;
|
||||
import com.abin.mallchat.common.common.exception.GroupErrorEnum;
|
||||
import com.abin.mallchat.common.common.utils.AssertUtil;
|
||||
import com.abin.mallchat.common.user.dao.UserDao;
|
||||
import com.abin.mallchat.common.user.domain.entity.User;
|
||||
@@ -196,10 +197,20 @@ public class RoomAppServiceImpl implements RoomAppService {
|
||||
RoomGroup roomGroup = roomGroupCache.get(request.getRoomId());
|
||||
AssertUtil.isNotEmpty(roomGroup, "房间号有误");
|
||||
GroupMember self = groupMemberDao.getMember(roomGroup.getId(), uid);
|
||||
AssertUtil.isNotEmpty(self, "您不是群管理");
|
||||
AssertUtil.isTrue(hasPower(self), "您不是群管理");
|
||||
GroupMember member = groupMemberDao.getMember(roomGroup.getId(), request.getUid());
|
||||
AssertUtil.isNotEmpty(self, "用户已经移除");
|
||||
AssertUtil.isNotEmpty(self, GroupErrorEnum.USER_NOT_IN_GROUP);
|
||||
// 1. 判断被移除的人是否是群主或者管理员 (群主不可以被移除,管理员只能被群主移除)
|
||||
Long removedUid = request.getUid();
|
||||
// 1.1 群主 非法操作
|
||||
AssertUtil.isFalse(groupMemberDao.isLord(roomGroup.getId(), removedUid), GroupErrorEnum.NOT_ALLOWED_FOR_REMOVE);
|
||||
// 1.2 管理员 判断是否是群主操作
|
||||
if (groupMemberDao.isManager(roomGroup.getId(), removedUid)) {
|
||||
Boolean isLord = groupMemberDao.isLord(roomGroup.getId(), uid);
|
||||
AssertUtil.isTrue(isLord, GroupErrorEnum.NOT_ALLOWED_FOR_REMOVE);
|
||||
}
|
||||
// 1.3 普通成员 判断是否有权限操作
|
||||
AssertUtil.isTrue(hasPower(self), GroupErrorEnum.NOT_ALLOWED_FOR_REMOVE);
|
||||
GroupMember member = groupMemberDao.getMember(roomGroup.getId(), removedUid);
|
||||
AssertUtil.isNotEmpty(member, "用户已经移除");
|
||||
groupMemberDao.removeById(member.getId());
|
||||
// 发送移除事件告知群成员
|
||||
List<Long> memberUidList = groupMemberCache.getMemberUidList(roomGroup.getRoomId());
|
||||
@@ -350,6 +361,7 @@ public class RoomAppServiceImpl implements RoomAppService {
|
||||
return userBatch.get(friendUid);
|
||||
}));
|
||||
}
|
||||
|
||||
private Map<Long, RoomBaseInfo> getRoomBaseInfoMap(List<Long> roomIds, Long uid) {
|
||||
Map<Long, Room> roomMap = roomCache.getBatch(roomIds);
|
||||
// 房间根据好友和群组类型分组
|
||||
|
||||
@@ -18,6 +18,7 @@ public enum GroupErrorEnum implements ErrorEnum {
|
||||
NOT_ALLOWED_OPERATION(9002, "您无权操作~"),
|
||||
MANAGE_COUNT_EXCEED(9003, "群管理员数量达到上限,请先删除后再操作~"),
|
||||
USER_NOT_IN_GROUP(9004, "非法操作,用户不存在群聊中~"),
|
||||
NOT_ALLOWED_FOR_REMOVE(9005, "非法操作,你没有移除该成员的权限"),
|
||||
;
|
||||
private final Integer code;
|
||||
private final String msg;
|
||||
|
||||
Reference in New Issue
Block a user