feat: 管理员享受所有角色权限
- 管理员可以代审核所有任务(主任务和子任务组) - 管理员可以发起任务(不受部门类型限制) - isAdminUser同时检查isAdmin字段和角色
This commit is contained in:
parent
79c0d92410
commit
07ce2e5613
@ -608,8 +608,16 @@ public class TaskApprovalService {
|
||||
|
||||
/**
|
||||
* 验证审核人权限
|
||||
* 管理员可以代审核所有任务
|
||||
*/
|
||||
private void validateApprover(Task task, Long approverId, String expectedRole) {
|
||||
// 检查是否是管理员,管理员可以代审核所有任务
|
||||
User approver = userMapper.selectById(approverId);
|
||||
if (approver != null && Integer.valueOf(1).equals(approver.getIsAdmin())) {
|
||||
log.info("管理员 {} 代审核任务 {}", approver.getRealName(), task.getId());
|
||||
return; // 管理员绕过权限验证
|
||||
}
|
||||
|
||||
if (!approverId.equals(task.getCurrentApproverId())) {
|
||||
throw new BusinessException(ResultCode.FORBIDDEN, "您无权审核此任务");
|
||||
}
|
||||
|
||||
@ -454,13 +454,20 @@ public class TaskItemService {
|
||||
throw new BusinessException(ResultCode.NOT_FOUND, "主任务不存在");
|
||||
}
|
||||
|
||||
// 2. 验证审核人权限(必须是接单部门负责人)
|
||||
if (mainTask.getReceiverDeptId() == null) {
|
||||
throw new BusinessException(ResultCode.FORBIDDEN, "任务未指定接单部门");
|
||||
}
|
||||
com.designhub.entity.Department receiverDept = departmentMapper.selectById(mainTask.getReceiverDeptId());
|
||||
if (receiverDept == null || !approverId.equals(receiverDept.getLeaderId())) {
|
||||
throw new BusinessException(ResultCode.FORBIDDEN, "只有接单部门负责人可以审核子任务组");
|
||||
// 2. 验证审核人权限(必须是接单部门负责人或管理员)
|
||||
com.designhub.entity.User approver = userService.getUserById(approverId);
|
||||
boolean isAdmin = approver != null && Integer.valueOf(1).equals(approver.getIsAdmin());
|
||||
|
||||
if (!isAdmin) {
|
||||
if (mainTask.getReceiverDeptId() == null) {
|
||||
throw new BusinessException(ResultCode.FORBIDDEN, "任务未指定接单部门");
|
||||
}
|
||||
com.designhub.entity.Department receiverDept = departmentMapper.selectById(mainTask.getReceiverDeptId());
|
||||
if (receiverDept == null || !approverId.equals(receiverDept.getLeaderId())) {
|
||||
throw new BusinessException(ResultCode.FORBIDDEN, "只有接单部门负责人可以审核子任务组");
|
||||
}
|
||||
} else {
|
||||
log.info("管理员 {} 代审核子任务组", approver.getRealName());
|
||||
}
|
||||
|
||||
// 3. 获取该组的所有待审核子任务
|
||||
@ -649,13 +656,20 @@ public class TaskItemService {
|
||||
throw new BusinessException(ResultCode.NOT_FOUND, "主任务不存在");
|
||||
}
|
||||
|
||||
// 2. 验证审核人权限(必须是接单部门负责人)
|
||||
if (mainTask.getReceiverDeptId() == null) {
|
||||
throw new BusinessException(ResultCode.FORBIDDEN, "任务未指定接单部门");
|
||||
}
|
||||
com.designhub.entity.Department receiverDept = departmentMapper.selectById(mainTask.getReceiverDeptId());
|
||||
if (receiverDept == null || !rejectorId.equals(receiverDept.getLeaderId())) {
|
||||
throw new BusinessException(ResultCode.FORBIDDEN, "只有接单部门负责人可以驳回子任务组");
|
||||
// 2. 验证审核人权限(必须是接单部门负责人或管理员)
|
||||
com.designhub.entity.User rejector = userService.getUserById(rejectorId);
|
||||
boolean isAdmin = rejector != null && Integer.valueOf(1).equals(rejector.getIsAdmin());
|
||||
|
||||
if (!isAdmin) {
|
||||
if (mainTask.getReceiverDeptId() == null) {
|
||||
throw new BusinessException(ResultCode.FORBIDDEN, "任务未指定接单部门");
|
||||
}
|
||||
com.designhub.entity.Department receiverDept = departmentMapper.selectById(mainTask.getReceiverDeptId());
|
||||
if (receiverDept == null || !rejectorId.equals(receiverDept.getLeaderId())) {
|
||||
throw new BusinessException(ResultCode.FORBIDDEN, "只有接单部门负责人可以驳回子任务组");
|
||||
}
|
||||
} else {
|
||||
log.info("管理员 {} 代驳回子任务组", rejector.getRealName());
|
||||
}
|
||||
|
||||
// 3. 更新主任务状态为 rejected
|
||||
|
||||
@ -976,6 +976,13 @@ public class TaskService {
|
||||
*/
|
||||
private boolean isAdminUser(Long userId) {
|
||||
try {
|
||||
// 首先检查用户的 isAdmin 字段
|
||||
User user = userService.getUserById(userId);
|
||||
if (user != null && Integer.valueOf(1).equals(user.getIsAdmin())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 其次检查角色
|
||||
var roles = roleService.getRolesByUserId(userId);
|
||||
return roles.stream().anyMatch(role ->
|
||||
"ADMIN".equals(role.getRoleCode()) ||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user