fix: 修复视觉调研草稿上传权限

This commit is contained in:
江林铖 2026-07-30 14:54:11 +08:00
parent 3618d61a97
commit 3329cc8948
2 changed files with 45 additions and 8 deletions

View File

@ -687,6 +687,42 @@ describe('performance survey service policies', () => {
expect(transactionClient.performanceSurvey.update).toHaveBeenCalled()
})
test('发起人可为非旧代码的视觉模板草稿继续上传作品', async () => {
;(prisma.performanceSurvey.findUnique as jest.Mock).mockResolvedValue(buildSurvey({
templateCode: 'ai_work_review',
templateSnapshot: {
code: 'ai_work_review',
name: 'AI作品评审',
shortName: 'AI作品评审',
surveyType: 'visual_case',
requiredWorkItemCount: 3,
questions: [],
},
targets: [{
id: 'target-ai-designer',
employeeProfileId: 'employee-ai-designer',
targetType: 'employee',
targetName: 'AI设计师',
targetSnapshot: {},
responses: [],
assignments: [],
workItems: [],
}],
}))
const detail = await getPerformanceSurveyDetail(session, 'survey-1')
expect(detail.targets).toEqual([
expect.objectContaining({
id: 'target-ai-designer',
canUploadWorkItems: false,
canCreateWorkItem: true,
requiredWorkItemCount: 3,
workItemUploadRemaining: 3,
}),
])
})
test('素材库管理员身份不会扩大个人调研详情到其他被考核人', async () => {
;(prisma.user.findUnique as jest.Mock).mockResolvedValue({
...baseUser,

View File

@ -703,7 +703,7 @@ async function assertAssignmentStageOpen(survey: any, assignment: any) {
}
return
}
if (!isVisualCaseTemplate(survey.templateCode)) return
if (!isVisualCaseTemplate(survey.templateSnapshot || survey.templateCode)) return
if (isSelfWorkflowRole(readWorkflowRole(assignment.evaluatorSnapshot))) return
if (!(await hasCompletedVisualSelfAssessment(survey.id, assignment.targetId))) {
throw new PerformanceSurveyApiError('被考核人完成自评后才会开放主管与元泽评分', 409)
@ -715,7 +715,7 @@ async function canSubmitCurrentVisualStage(survey: any, assignments: any[]) {
if (configuredAssignments.length > 0) {
return configuredAssignments.some((assignment) => assignment.releasedAt && assignment.status !== 'submitted')
}
if (!isVisualCaseTemplate(survey.templateCode)) return true
if (!isVisualCaseTemplate(survey.templateSnapshot || survey.templateCode)) return true
if (assignments.some((assignment) => isSelfWorkflowRole(readWorkflowRole(assignment.evaluatorSnapshot)))) return true
const targetIds = Array.from(new Set(assignments.map((assignment) => clean(assignment.targetId)).filter(Boolean))) as string[]
if (targetIds.length === 0) return false
@ -968,9 +968,6 @@ function getPersonalSurveyTargets<T extends {
targets: T[],
) {
const assignedTargetIds = new Set((survey.assignments || []).map((assignment) => assignment.targetId))
const isCreator = survey.creatorUserId === ctx.user.id
if (isCreator) return targets
return targets.filter((target) => (
assignedTargetIds.has(target.id)
@ -3067,12 +3064,14 @@ export async function getPerformanceSurveyDetail(session: Session | null, survey
throw new PerformanceSurveyApiError('调研不存在或无权限', 404)
}
const visibleTargets = getPersonalSurveyTargets(ctx, survey, survey.targets)
const isCreator = survey.creatorUserId === ctx.user.id
const visibleTargets = isCreator
? survey.targets
: getPersonalSurveyTargets(ctx, survey, survey.targets)
const isAssigned = survey.assignments.length > 0
const isTarget = Boolean(
ctx.employee && visibleTargets.some((target) => target.employeeProfileId === ctx.employee?.id),
)
const isCreator = survey.creatorUserId === ctx.user.id
const canManage = isCreator
if (visibleTargets.length === 0 || (!isCreator && !isAssigned && !isTarget)) {
@ -3126,7 +3125,9 @@ export async function getPerformanceSurveyDetail(session: Session | null, survey
targets: visibleTargets.map((target) => {
const currentAssignment = currentAssignments.get(target.id)
const response = currentAssignment?.response
const isVisualTemplate = isVisualCaseTemplate(survey.templateCode)
const isVisualTemplate = isVisualCaseTemplate(
(survey.templateSnapshot as PerformanceSurveyTemplateShape) || survey.templateCode,
)
const requiredWorkItemCount = isVisualTemplate
? Math.max(1, Number((survey.templateSnapshot as PerformanceSurveyTemplateShape).requiredWorkItemCount || 3))
: 0