fix: restrict primary detail editing to assigned member

This commit is contained in:
Your Name 2026-03-31 13:35:23 +08:00
parent 0edd74dc0d
commit aea4388cb5
2 changed files with 4 additions and 49 deletions

View File

@ -963,25 +963,8 @@ public class TaskService {
// 非管理员只能看到分配给自己的待审核任务
if (!isAdmin) {
boolean isDemandDeptMember = userService.getUserDepartments(userId).stream()
.filter(java.util.Objects::nonNull)
.anyMatch(dept -> "demand".equals(dept.getDeptType())
&& dept.getStatus() != null && dept.getStatus() == 1
&& (dept.getDeleted() == null || dept.getDeleted() == 0));
if (isDemandDeptMember) {
wrapper.and(w -> w
.eq(Task::getCurrentApproverId, userId)
.or(ow -> ow
.eq(Task::getApprovalStatus, "pending_detail_completion")
.eq(Task::getIsPrimaryTask, 1)
)
);
log.info("需求部门成员 {} 查询待审核任务,包含一级需求任务待完善明细列表", userId);
} else {
wrapper.eq(Task::getCurrentApproverId, userId);
}
}
// 根据任务类型筛选
if (taskTypeId != null) {
@ -1898,23 +1881,8 @@ public class TaskService {
&& existTask.getDetailCompleterId() != null
&& userId.equals(existTask.getDetailCompleterId());
// 对于一级需求任务在待完善明细状态,需求部门的成员都可以编辑
boolean isDemandDeptMemberForPrimaryTask = false;
if (existTask.getIsPrimaryTask() != null && existTask.getIsPrimaryTask() == 1
&& "pending_detail_completion".equals(existTask.getApprovalStatus())) {
List<Department> userDepartments = userService.getUserDepartments(userId);
isDemandDeptMemberForPrimaryTask = userDepartments.stream()
.filter(java.util.Objects::nonNull)
.anyMatch(dept -> "demand".equals(dept.getDeptType())
&& dept.getStatus() != null && dept.getStatus() == 1
&& (dept.getDeleted() == null || dept.getDeleted() == 0));
if (isDemandDeptMemberForPrimaryTask) {
log.info("需求部门成员 {} 编辑一级需求任务 {}", userId, id);
}
}
if (!isAdmin && !userId.equals(existTask.getPublisherId()) && !isPrimaryTaskDetailCompleter
&& !isDemandDeptMemberForPrimaryTask && !leaderCanEditPending) {
&& !leaderCanEditPending) {
throw new BusinessException(ResultCode.FORBIDDEN, "只有任务发布人、指定的明细完善人或接单部门负责人(待接单任务)可以更新任务");
}

View File

@ -5641,27 +5641,14 @@ const canRejectTask = (task: Task) => {
return canApproveTask(task)
}
const isDemandDepartmentMember = () => {
const userInfo = currentUserInfo.value || JSON.parse(localStorage.getItem('userInfo') || '{}')
const departments = Array.isArray(userInfo.departments) ? userInfo.departments : []
if (departments.some((dept: any) => dept?.deptType === 'demand')) {
return true
}
return userInfo.deptType === 'demand'
}
// 判断是否可以编辑完善任务明细(一级需求部门任务)
const canEditDetailTask = (task: Task) => {
const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}')
const currentUserId = userInfo.id
// 一级需求任务在待完善明细状态下,需求部门成员也允许补充任务明细
// 只有待完善明细状态的任务,且当前用户是指定的完善人
if (task.approvalStatus === 'pending_detail_completion') {
return task.currentApproverId === currentUserId
|| task.detailCompleterId === currentUserId
|| isDemandDepartmentMember()
return task.currentApproverId === currentUserId || task.detailCompleterId === currentUserId
}
return false