feat(manage): 实现部门负责人视角,支持只读查看部门成员项目与任务

部门负责人/部门管理员可通过系统配置开启,选择管理部门后只读查看
本部门及下级部门成员的全部项目和任务。前端自动根据 department_readonly
标记禁用编辑操作,后端统一注入负责人视角上下文控制数据访问边界。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
kuaifan
2026-05-21 00:14:36 +00:00
parent e0ad8ce6c1
commit 0863e5529a
27 changed files with 1359 additions and 94 deletions

View File

@@ -2258,6 +2258,39 @@ class ProjectTask extends AbstractModel
return $task;
}
/**
* 获取任务(含部门负责人只读视角兜底)
* @param int $task_id
* @param null|bool $archived true:仅限未归档, false:仅限已归档, null:不限制
* @param null|bool $trashed true:仅限未删除, false:仅限已删除, null:不限制
* @param array $with
* @return self
*/
public static function findForDepartmentView($task_id, $archived = true, $trashed = true, $with = [])
{
$user = User::auth();
$departmentView = UserDepartment::ownerViewContext($user, true);
if ($departmentView['enabled']) {
$builder = self::with($with)->allData()->where('project_tasks.id', intval($task_id));
if ($trashed === false) {
$builder->onlyTrashed();
} elseif ($trashed === null) {
$builder->withTrashed();
}
$task = $builder->first();
if (!empty($task) && UserDepartment::isDepartmentReadonlyProject($departmentView, intval($task->project_id))) {
if ($archived === true && $task->archived_at != null) {
throw new ApiException('任务已归档', ['task_id' => $task_id]);
}
if ($archived === false && $task->archived_at == null) {
throw new ApiException('任务未归档', ['task_id' => $task_id]);
}
return $task;
}
}
return self::userTask($task_id, $archived, $trashed, $with);
}
/**
* 构建指定周期内的未完成任务查询(用于周报/日报等)
* @param int $userid