Commit 267902ed by shenjunjie

Merge branch 'feature' into 'release'

用户权限编辑调整

See merge request !529
parents 376dfc3c 4aee9fd3
...@@ -39,4 +39,8 @@ public class CustomException extends RuntimeException { ...@@ -39,4 +39,8 @@ public class CustomException extends RuntimeException {
return exception; return exception;
} }
public String getErrorMessage(){
return errorMessage;
}
} }
...@@ -34,9 +34,9 @@ public class ExceptionCatch { ...@@ -34,9 +34,9 @@ public class ExceptionCatch {
Exception exception = customException.getException(); Exception exception = customException.getException();
//记录日志 //记录日志
if (null == exception) { if (null == exception) {
log.info("catch exception-custom:{}", resultCode.message()); log.info("catch exception-custom:{}", customException.getErrorMessage());
} else { } else {
log.error("catch exception-custom:{}", resultCode.message(), exception); log.error("catch exception-custom:{}", customException.getErrorMessage(), exception);
} }
return new ResponseResult(resultCode, Collections.EMPTY_LIST); return new ResponseResult(resultCode, Collections.EMPTY_LIST);
} }
......
...@@ -89,7 +89,18 @@ public class ResponseResult { ...@@ -89,7 +89,18 @@ public class ResponseResult {
* @return 操作失败带返回数据 * @return 操作失败带返回数据
*/ */
public static ResponseResult failure(String message) { public static ResponseResult failure(String message) {
ResponseResult responseResult = new ResponseResult(CommonCodeEnum.FAIL, null); return failure(message, CommonCodeEnum.FAIL);
}
/**
* 操作失败带返回数据
*
* @param message 失败信息
* @param commonCodeEnum 失败类型
* @return 操作失败带返回数据
*/
public static ResponseResult failure(String message, CommonCodeEnum commonCodeEnum) {
ResponseResult responseResult = new ResponseResult(commonCodeEnum, null);
responseResult.setMessage(message); responseResult.setMessage(message);
return responseResult; return responseResult;
} }
......
...@@ -146,16 +146,11 @@ public class UserServiceImpl implements UserService { ...@@ -146,16 +146,11 @@ public class UserServiceImpl implements UserService {
@Override @Override
public ResponseResult addUser(UserDTO userDTO) { public ResponseResult addUser(UserDTO userDTO) {
if (Objects.isNull(userDTO.getRoleId()) || userDTO.getRoleId() < RoleEnum.ADMIN.getState()) { if (!checkPermissionExceptSuperAdmin(userDTO.getRoleId())) {
// 抛出用户权限设置错误异常 // 抛出用户权限设置错误异常
ExceptionCast.cast(CommonCodeEnum.UN_AUTHORISE); return ResponseResult.failure("权限不足,无权操作", CommonCodeEnum.UN_AUTHORISE);
} }
int roleId = UserThreadLocal.getRoleId();
String nickname = UserThreadLocal.getNickname(); String nickname = UserThreadLocal.getNickname();
// 只有超管能设置管理员
if (roleId != RoleEnum.SUPER_ADMIN.getState() && userDTO.getRoleId() <= RoleEnum.ADMIN.getState()) {
ExceptionCast.cast(CommonCodeEnum.UN_AUTHORISE);
}
// 有密码则通过用户中心注册 // 有密码则通过用户中心注册
CenterUser centerUser = null; CenterUser centerUser = null;
if (null != userDTO.getPassword()) { if (null != userDTO.getPassword()) {
...@@ -192,7 +187,7 @@ public class UserServiceImpl implements UserService { ...@@ -192,7 +187,7 @@ public class UserServiceImpl implements UserService {
} else { } else {
if (roles.stream().map(UserRole::getProjectId).collect(Collectors.toList()).contains(userDTO.getProjectId())) { if (roles.stream().map(UserRole::getProjectId).collect(Collectors.toList()).contains(userDTO.getProjectId())) {
// 抛出用户权限设置错误异常 // 抛出用户权限设置错误异常
ExceptionCast.cast(CommonCodeEnum.INVALID_PARAM, "用户权限设置重复"); return ResponseResult.failure("用户权限设置重复", CommonCodeEnum.INVALID_PARAM);
} }
} }
roles.add(UserRole.createFromUserDto(userDTO)); roles.add(UserRole.createFromUserDto(userDTO));
...@@ -222,6 +217,10 @@ public class UserServiceImpl implements UserService { ...@@ -222,6 +217,10 @@ public class UserServiceImpl implements UserService {
if (null == user) { if (null == user) {
ExceptionCast.cast(CommonCodeEnum.INVALID_PARAM); ExceptionCast.cast(CommonCodeEnum.INVALID_PARAM);
} }
if (!checkPermissionExceptSuperAdmin(userDTO.getRoleId())) {
// 抛出用户权限设置错误异常
ExceptionCast.cast(CommonCodeEnum.UN_AUTHORISE);
}
List<UserRole> roles = user.getRoles(); List<UserRole> roles = user.getRoles();
user.getRoles().stream().filter(userRoles -> userRoles.getProjectId().equals(userDTO.getProjectId())).findAny().ifPresent(userRole -> { user.getRoles().stream().filter(userRoles -> userRoles.getProjectId().equals(userDTO.getProjectId())).findAny().ifPresent(userRole -> {
// 更新原userRole // 更新原userRole
...@@ -485,4 +484,17 @@ public class UserServiceImpl implements UserService { ...@@ -485,4 +484,17 @@ public class UserServiceImpl implements UserService {
UserThreadLocal.set(userInfo); UserThreadLocal.set(userInfo);
} }
/**
* 添加超管以外的用户权限校验
*
* @param roleId
*/
private boolean checkPermissionExceptSuperAdmin(Integer roleId) {
if (Objects.isNull(roleId)) {
return false;
}
// 不能设置超级管理员以及比自身权限大的用户
return roleId != RoleEnum.SUPER_ADMIN.getState() && UserThreadLocal.getRoleId() <= roleId;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment