系统变量增加组权限管理
This commit is contained in:
parent
d0da908ea7
commit
9173b256fa
@ -72,6 +72,12 @@ public class GroupConfigController {
|
|||||||
return groupConfigService.getAllGroupConfigList(namespaceIds);
|
return groupConfigService.getAllGroupConfigList(namespaceIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@LoginRequired
|
||||||
|
@PostMapping("/all/group/list")
|
||||||
|
public List<GroupConfigResponseVO> getAllGroupList() {
|
||||||
|
return groupConfigService.getAllGroupList();
|
||||||
|
}
|
||||||
|
|
||||||
@LoginRequired
|
@LoginRequired
|
||||||
@GetMapping("/all/group-name/list")
|
@GetMapping("/all/group-name/list")
|
||||||
public List<String> getAllGroupNameList() {
|
public List<String> getAllGroupNameList() {
|
||||||
|
@ -5,6 +5,8 @@ import jakarta.validation.constraints.NotNull;
|
|||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class SystemVariableRequestVO {
|
public class SystemVariableRequestVO {
|
||||||
|
|
||||||
@ -27,4 +29,6 @@ public class SystemVariableRequestVO {
|
|||||||
|
|
||||||
@Size(max = 256, message = "描述长度不能超过256个字符")
|
@Size(max = 256, message = "描述长度不能超过256个字符")
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
private List<UserPermissionRequestVO> permissions;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.aizuda.snailjob.server.web.model.response;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class SystemVariableResponseVO {
|
public class SystemVariableResponseVO {
|
||||||
@ -24,6 +25,8 @@ public class SystemVariableResponseVO {
|
|||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
private List<PermissionsResponseVO> permissions;
|
||||||
|
|
||||||
private LocalDateTime createDt;
|
private LocalDateTime createDt;
|
||||||
|
|
||||||
private LocalDateTime updateDt;
|
private LocalDateTime updateDt;
|
||||||
|
@ -43,4 +43,7 @@ public interface GroupConfigService {
|
|||||||
boolean deleteByGroupName(String groupName);
|
boolean deleteByGroupName(String groupName);
|
||||||
|
|
||||||
Map<String, GroupConfigResponseVO> getGroupNameCns(Set<String> uniqueGroupNames);
|
Map<String, GroupConfigResponseVO> getGroupNameCns(Set<String> uniqueGroupNames);
|
||||||
}
|
|
||||||
|
List<GroupConfigResponseVO> getAllGroupList();
|
||||||
|
|
||||||
|
}
|
@ -254,6 +254,14 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
return groupConfigResponses;
|
return groupConfigResponses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GroupConfigResponseVO> getAllGroupList() {
|
||||||
|
UserSessionVO userSessionVO = UserSessionUtils.currentUserSession();
|
||||||
|
List<String> namespaceIds = new ArrayList<>();
|
||||||
|
namespaceIds.add(userSessionVO.getNamespaceId());
|
||||||
|
return getAllGroupConfigList(namespaceIds);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getAllGroupNameList() {
|
public List<String> getAllGroupNameList() {
|
||||||
|
|
||||||
@ -266,7 +274,7 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
List<GroupConfig> groupConfigs = groupConfigAccess.list(new LambdaQueryWrapper<GroupConfig>()
|
List<GroupConfig> groupConfigs = groupConfigAccess.list(new LambdaQueryWrapper<GroupConfig>()
|
||||||
.eq(GroupConfig::getNamespaceId, userSessionVO.getNamespaceId())
|
.eq(GroupConfig::getNamespaceId, userSessionVO.getNamespaceId())
|
||||||
.select(GroupConfig::getGroupName));
|
.select(GroupConfig::getGroupName));
|
||||||
|
//TODO ?
|
||||||
return StreamUtils.toList(groupConfigs, GroupConfig::getGroupName);
|
return StreamUtils.toList(groupConfigs, GroupConfig::getGroupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,9 @@ import com.aizuda.snailjob.server.common.exception.SnailJobServerException;
|
|||||||
import com.aizuda.snailjob.server.web.model.base.PageResult;
|
import com.aizuda.snailjob.server.web.model.base.PageResult;
|
||||||
import com.aizuda.snailjob.server.web.model.request.SystemVariableQueryVO;
|
import com.aizuda.snailjob.server.web.model.request.SystemVariableQueryVO;
|
||||||
import com.aizuda.snailjob.server.web.model.request.SystemVariableRequestVO;
|
import com.aizuda.snailjob.server.web.model.request.SystemVariableRequestVO;
|
||||||
|
import com.aizuda.snailjob.server.web.model.request.UserPermissionRequestVO;
|
||||||
import com.aizuda.snailjob.server.web.model.request.UserSessionVO;
|
import com.aizuda.snailjob.server.web.model.request.UserSessionVO;
|
||||||
|
import com.aizuda.snailjob.server.web.model.response.PermissionsResponseVO;
|
||||||
import com.aizuda.snailjob.server.web.model.response.SystemVariableResponseVO;
|
import com.aizuda.snailjob.server.web.model.response.SystemVariableResponseVO;
|
||||||
import com.aizuda.snailjob.server.web.service.SystemVariableService;
|
import com.aizuda.snailjob.server.web.service.SystemVariableService;
|
||||||
import com.aizuda.snailjob.server.web.util.UserSessionUtils;
|
import com.aizuda.snailjob.server.web.util.UserSessionUtils;
|
||||||
@ -21,10 +23,9 @@ import org.springframework.beans.BeanUtils;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Map;
|
import java.util.stream.Stream;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@ -54,14 +55,24 @@ public class SystemVariableServiceImpl implements SystemVariableService {
|
|||||||
systemVariable.setSystemUserId(userSession.getId());
|
systemVariable.setSystemUserId(userSession.getId());
|
||||||
systemVariable.setNamespaceId(userSession.getNamespaceId());
|
systemVariable.setNamespaceId(userSession.getNamespaceId());
|
||||||
// 设置 groupNames
|
// 设置 groupNames
|
||||||
if (userSession.isAdmin()) {
|
// if (userSession.isAdmin()) {
|
||||||
// admin用户创建的变量,设置为空或特殊标识,表示所有组都可见
|
// // admin用户创建的变量,设置为空或特殊标识,表示所有组都可见
|
||||||
|
// systemVariable.setGroupNames("");
|
||||||
|
// } else {
|
||||||
|
// // 普通用户创建的变量,存储用户所属的组名
|
||||||
|
// List<String> userGroupNames = userSession.getGroupNames();
|
||||||
|
// systemVariable.setGroupNames(String.join(",", userGroupNames));
|
||||||
|
// }
|
||||||
|
// 增加组权限管理++
|
||||||
|
List<UserPermissionRequestVO> groupNameList = requestVO.getPermissions();
|
||||||
|
if (CollUtil.isEmpty(groupNameList)) {
|
||||||
systemVariable.setGroupNames("");
|
systemVariable.setGroupNames("");
|
||||||
} else {
|
|
||||||
// 普通用户创建的变量,存储用户所属的组名
|
|
||||||
List<String> userGroupNames = userSession.getGroupNames();
|
|
||||||
systemVariable.setGroupNames(String.join(",", userGroupNames));
|
|
||||||
}
|
}
|
||||||
|
String groupNames = groupNameList.stream()
|
||||||
|
.map(UserPermissionRequestVO::getGroupName)
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
|
|
||||||
|
systemVariable.setGroupNames(groupNames);
|
||||||
|
|
||||||
Assert.isTrue(1 == systemVariableMapper.insert(systemVariable),
|
Assert.isTrue(1 == systemVariableMapper.insert(systemVariable),
|
||||||
() -> new SnailJobServerException("添加系统变量失败"));
|
() -> new SnailJobServerException("添加系统变量失败"));
|
||||||
@ -96,6 +107,16 @@ public class SystemVariableServiceImpl implements SystemVariableService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<UserPermissionRequestVO> groupNameList = requestVO.getPermissions();
|
||||||
|
if (CollUtil.isEmpty(groupNameList)) {
|
||||||
|
existingVariable.setGroupNames("");
|
||||||
|
}
|
||||||
|
String groupNames = groupNameList.stream()
|
||||||
|
.map(UserPermissionRequestVO::getGroupName)
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
|
|
||||||
|
existingVariable.setGroupNames(groupNames);
|
||||||
|
|
||||||
BeanUtils.copyProperties(requestVO, existingVariable);
|
BeanUtils.copyProperties(requestVO, existingVariable);
|
||||||
Assert.isTrue(1 == systemVariableMapper.updateById(existingVariable),
|
Assert.isTrue(1 == systemVariableMapper.updateById(existingVariable),
|
||||||
() -> new SnailJobServerException("更新系统变量失败"));
|
() -> new SnailJobServerException("更新系统变量失败"));
|
||||||
@ -148,7 +169,7 @@ public class SystemVariableServiceImpl implements SystemVariableService {
|
|||||||
w.or().like(SystemVariable::getGroupNames, groupName);
|
w.or().like(SystemVariable::getGroupNames, groupName);
|
||||||
}
|
}
|
||||||
// admin创建的变量(通过查询admin用户ID)
|
// admin创建的变量(通过查询admin用户ID)
|
||||||
w.or().exists("SELECT 1 FROM sj_system_user su WHERE su.id = sj_system_variable.system_user_id AND su.role = 2");
|
// w.or().exists("SELECT 1 FROM sj_system_user su WHERE su.id = sj_system_variable.system_user_id AND su.role = 2");
|
||||||
// return w;
|
// return w;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -160,6 +181,11 @@ public class SystemVariableServiceImpl implements SystemVariableService {
|
|||||||
.map(this::convertToResponseVO)
|
.map(this::convertToResponseVO)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
responseList.forEach(vo -> {
|
||||||
|
if(vo.getGroupNames() != null) {
|
||||||
|
vo.setPermissions(safeConvert(vo.getGroupNames(),vo.getNamespaceId()));
|
||||||
|
}
|
||||||
|
});
|
||||||
return new PageResult<>(pageDTO, responseList);
|
return new PageResult<>(pageDTO, responseList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,4 +272,20 @@ public class SystemVariableServiceImpl implements SystemVariableService {
|
|||||||
BeanUtils.copyProperties(systemVariable, responseVO);
|
BeanUtils.copyProperties(systemVariable, responseVO);
|
||||||
return responseVO;
|
return responseVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<PermissionsResponseVO> safeConvert(String namesStr, String namespaceId) {
|
||||||
|
return Optional.ofNullable(namesStr)
|
||||||
|
.map(str -> Arrays.stream(str.split(",")))
|
||||||
|
.orElseGet(Stream::empty)
|
||||||
|
.filter(name -> !name.trim().isEmpty())
|
||||||
|
.map(name -> {
|
||||||
|
PermissionsResponseVO vo = new PermissionsResponseVO();
|
||||||
|
vo.setGroupName(name.trim());
|
||||||
|
vo.setNamespaceId(namespaceId);
|
||||||
|
vo.setNamespaceName(name.trim());
|
||||||
|
// 可设置其他默认字段值
|
||||||
|
return vo;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user