mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-10-05 17:46:37 +08:00
fix: ensure group sync grants all tunnel-group tunnels
This commit is contained in:
@@ -30,6 +30,7 @@ import com.admin.service.UserService;
|
|||||||
import com.admin.service.UserTunnelService;
|
import com.admin.service.UserTunnelService;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -158,6 +159,7 @@ public class GroupServiceImpl implements GroupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public R assignTunnelsToGroup(TunnelGroupAssignTunnelsDto dto) {
|
public R assignTunnelsToGroup(TunnelGroupAssignTunnelsDto dto) {
|
||||||
TunnelGroup group = tunnelGroupMapper.selectById(dto.getGroupId());
|
TunnelGroup group = tunnelGroupMapper.selectById(dto.getGroupId());
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
@@ -274,6 +276,7 @@ public class GroupServiceImpl implements GroupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public R assignUsersToGroup(UserGroupAssignUsersDto dto) {
|
public R assignUsersToGroup(UserGroupAssignUsersDto dto) {
|
||||||
UserGroup group = userGroupMapper.selectById(dto.getGroupId());
|
UserGroup group = userGroupMapper.selectById(dto.getGroupId());
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
@@ -336,6 +339,7 @@ public class GroupServiceImpl implements GroupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public R assignGroupPermission(GroupPermissionAssignDto dto) {
|
public R assignGroupPermission(GroupPermissionAssignDto dto) {
|
||||||
UserGroup userGroup = userGroupMapper.selectById(dto.getUserGroupId());
|
UserGroup userGroup = userGroupMapper.selectById(dto.getUserGroupId());
|
||||||
if (userGroup == null) {
|
if (userGroup == null) {
|
||||||
@@ -448,11 +452,12 @@ public class GroupServiceImpl implements GroupService {
|
|||||||
UserTunnel userTunnel = pairUserTunnelMap.get(pairKey);
|
UserTunnel userTunnel = pairUserTunnelMap.get(pairKey);
|
||||||
if (userTunnel == null) {
|
if (userTunnel == null) {
|
||||||
userTunnel = createGroupManagedUserTunnel(userId, tunnelId, user);
|
userTunnel = createGroupManagedUserTunnel(userId, tunnelId, user);
|
||||||
|
Long userTunnelId = resolveUserTunnelId(userTunnel, userId, tunnelId);
|
||||||
pairUserTunnelMap.put(pairKey, userTunnel);
|
pairUserTunnelMap.put(pairKey, userTunnel);
|
||||||
createGrant(userGroupId, tunnelGroupId, userTunnel.getId().longValue(), true, now);
|
createGrant(userGroupId, tunnelGroupId, userTunnelId, true, now);
|
||||||
currentGrantUserTunnelIds.add(userTunnel.getId().longValue());
|
currentGrantUserTunnelIds.add(userTunnelId);
|
||||||
totalGrantCountMap.put(userTunnel.getId().longValue(), 1L);
|
totalGrantCountMap.put(userTunnelId, 1L);
|
||||||
groupManagedUserTunnelIds.add(userTunnel.getId().longValue());
|
groupManagedUserTunnelIds.add(userTunnelId);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -497,10 +502,32 @@ public class GroupServiceImpl implements GroupService {
|
|||||||
userTunnel.setNum(user.getNum());
|
userTunnel.setNum(user.getNum());
|
||||||
userTunnel.setFlowResetTime(user.getFlowResetTime());
|
userTunnel.setFlowResetTime(user.getFlowResetTime());
|
||||||
userTunnel.setExpTime(user.getExpTime());
|
userTunnel.setExpTime(user.getExpTime());
|
||||||
userTunnelService.save(userTunnel);
|
boolean saved = userTunnelService.save(userTunnel);
|
||||||
|
if (!saved) {
|
||||||
|
throw new IllegalStateException("创建用户隧道权限失败: userId=" + userId + ", tunnelId=" + tunnelId);
|
||||||
|
}
|
||||||
return userTunnel;
|
return userTunnel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Long resolveUserTunnelId(UserTunnel userTunnel, Long userId, Long tunnelId) {
|
||||||
|
if (userTunnel.getId() != null) {
|
||||||
|
return userTunnel.getId().longValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
UserTunnel persisted = userTunnelService.getOne(
|
||||||
|
new QueryWrapper<UserTunnel>()
|
||||||
|
.eq("user_id", userId.intValue())
|
||||||
|
.eq("tunnel_id", tunnelId.intValue())
|
||||||
|
.orderByDesc("id")
|
||||||
|
.last("LIMIT 1")
|
||||||
|
);
|
||||||
|
if (persisted == null || persisted.getId() == null) {
|
||||||
|
throw new IllegalStateException("获取用户隧道权限ID失败: userId=" + userId + ", tunnelId=" + tunnelId);
|
||||||
|
}
|
||||||
|
userTunnel.setId(persisted.getId());
|
||||||
|
return persisted.getId().longValue();
|
||||||
|
}
|
||||||
|
|
||||||
private void createGrant(Long userGroupId, Long tunnelGroupId, Long userTunnelId, boolean createdByGroup, long createdTime) {
|
private void createGrant(Long userGroupId, Long tunnelGroupId, Long userTunnelId, boolean createdByGroup, long createdTime) {
|
||||||
int exists = groupPermissionGrantMapper.selectCount(new QueryWrapper<GroupPermissionGrant>()
|
int exists = groupPermissionGrantMapper.selectCount(new QueryWrapper<GroupPermissionGrant>()
|
||||||
.eq("user_group_id", userGroupId)
|
.eq("user_group_id", userGroupId)
|
||||||
|
|||||||
Reference in New Issue
Block a user