fix: 修复SystemUserController若干bug :(
This commit is contained in:
parent
5e32dc2cd7
commit
a8a423c416
@ -1,5 +1,6 @@
|
|||||||
package com.aizuda.snailjob.server.web.controller;
|
package com.aizuda.snailjob.server.web.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
import com.aizuda.snailjob.server.common.exception.SnailJobServerException;
|
import com.aizuda.snailjob.server.common.exception.SnailJobServerException;
|
||||||
import com.aizuda.snailjob.server.web.annotation.LoginRequired;
|
import com.aizuda.snailjob.server.web.annotation.LoginRequired;
|
||||||
import com.aizuda.snailjob.server.web.annotation.LoginUser;
|
import com.aizuda.snailjob.server.web.annotation.LoginUser;
|
||||||
@ -11,6 +12,7 @@ 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.PermissionsResponseVO;
|
||||||
import com.aizuda.snailjob.server.web.model.response.SystemUserResponseVO;
|
import com.aizuda.snailjob.server.web.model.response.SystemUserResponseVO;
|
||||||
import com.aizuda.snailjob.server.web.service.SystemUserService;
|
import com.aizuda.snailjob.server.web.service.SystemUserService;
|
||||||
|
import com.aizuda.snailjob.server.web.util.UserSessionUtils;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -26,7 +28,7 @@ import java.util.List;
|
|||||||
@RestController
|
@RestController
|
||||||
public class SystemUserController {
|
public class SystemUserController {
|
||||||
|
|
||||||
private final Long SUPER_ADMIN_ID = 1L;
|
private static final Long SUPER_ADMIN_ID = 1L;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SystemUserService systemUserService;
|
private SystemUserService systemUserService;
|
||||||
@ -54,10 +56,15 @@ public class SystemUserController {
|
|||||||
return systemUserService.getSystemUserPageList(systemUserQueryVO);
|
return systemUserService.getSystemUserPageList(systemUserQueryVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@LoginRequired(role = RoleEnum.ADMIN)
|
|
||||||
@PutMapping("/user")
|
@PutMapping("/user")
|
||||||
public void update(@RequestBody @Valid SystemUserRequestVO requestVO) {
|
public void update(@RequestBody @Valid SystemUserRequestVO requestVO) {
|
||||||
if (requestVO.getId() == SUPER_ADMIN_ID && RoleEnum.isAdmin(requestVO.getRole())) {
|
// 1. 普通用户不允许修改其他用户
|
||||||
|
if (!SUPER_ADMIN_ID.equals(requestVO.getId())) {
|
||||||
|
Assert.equals(UserSessionUtils.currentUserSession().getId(), requestVO.getId(),
|
||||||
|
"普通用户不允许修改其他用户");
|
||||||
|
}
|
||||||
|
// 2. 超级管理员(id=1)不能变更为普通用户
|
||||||
|
if (SUPER_ADMIN_ID.equals(requestVO.getId()) && RoleEnum.isUser(requestVO.getRole())) {
|
||||||
throw new SnailJobServerException("不允许修改超级管理员角色");
|
throw new SnailJobServerException("不允许修改超级管理员角色");
|
||||||
}
|
}
|
||||||
systemUserService.update(requestVO);
|
systemUserService.update(requestVO);
|
||||||
@ -75,10 +82,10 @@ public class SystemUserController {
|
|||||||
return systemUserService.getSystemUserPermissionByUserName(id);
|
return systemUserService.getSystemUserPermissionByUserName(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@LoginRequired
|
@LoginRequired(role = RoleEnum.ADMIN)
|
||||||
@DeleteMapping("/user/{id}")
|
@DeleteMapping("/user/{id}")
|
||||||
public boolean delUser(@PathVariable("id") Long id) {
|
public boolean delUser(@PathVariable("id") Long id) {
|
||||||
if (id == SUPER_ADMIN_ID) {
|
if (SUPER_ADMIN_ID.equals(id)) {
|
||||||
throw new SnailJobServerException("不允许删除超级管理员");
|
throw new SnailJobServerException("不允许删除超级管理员");
|
||||||
}
|
}
|
||||||
return systemUserService.delUser(id);
|
return systemUserService.delUser(id);
|
||||||
|
Loading…
Reference in New Issue
Block a user