Add attachments to assessment and course applications

This commit is contained in:
biss committed 2026-11-14 15:37:11 +08:00
1 parent bdfbf49f40
commit d36c0ff7b8
17 files changed
+12906 -39

No files matched your search

+2 -2
View File
@@ -1,6 +1,6 @@
# 审批附件(开发中)
# 审批附件
目前只有学生请假申请支持附件。申请与附件元数据一同写入数据库,审核人员只能按请假业务的数据范围读取附件。其他审批类型的规则可以配置,但尚未接入上传,因此暂不生效。
学生请假、免修、缓考和综合测评材料支持附件。申请与附件元数据一同写入数据库,读取权限沿用相应业务的数据范围。综合测评材料可以在新建或修改草稿、修改已驳回材料时新增附件;当前不支持单独删除附件,可以删除草稿后重新创建。其他审批类型未接入附件。
超级管理员可在审批中心的“附件规则”中选择新附件使用本地存储或 S3 兼容存储,并按审批类型配置扩展名、单文件大小和数量。请假附件单次请求的文件总大小上限为 100 MiB,反向代理也必须允许足够大的请求体。扩展名是文件名规则,并不验证文件实际内容;附件始终作为下载提供。
@@ -16,11 +16,7 @@ public sealed class ApprovalAttachmentPoliciesController(AppDbContext db) : Cont
{
public static readonly string[] Types =
[
"CourseExemption", "DeferredExam", "CourseSubstitution", "GradeModification",
"StudentStatusChange", "StudentLeave", "TeacherCourseApplication", "ClassroomReservation",
"CourseAdjustment", "DormitoryApplication", "GradeSheet", "GradeSubmissionBatch",
"ExperimentGradeSheet", "AssessmentDeclaration", "AssessmentAppeal",
"CampusRegistration", "AttendanceAppeal"
"CourseExemption", "DeferredExam", "StudentLeave", "AssessmentDeclaration"
];
[HttpGet]
@@ -0,0 +1,58 @@
using System.Net.Mime;
using Jiaowu.Api.Infrastructure.Attachments;
using Jiaowu.Api.Infrastructure.Auth;
using Jiaowu.Api.Infrastructure.Persistence;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Net.Http.Headers;
namespace Jiaowu.Api.Controllers;
[ApiController]
[Authorize]
[Route("api/approval-attachments")]
public sealed class ApprovalAttachmentsController(AppDbContext db, ICurrentUserDataScope scope,
IConfiguration configuration, IWebHostEnvironment environment) : ControllerBase
{
private static readonly string[] Types = ["CourseExemption", "DeferredExam", "AssessmentDeclaration"];
[HttpGet("policy/{type}")]
public async Task<IActionResult> Policy(string type, CancellationToken ct)
{
if (!Types.Contains(type, StringComparer.Ordinal)) return NotFound();
var policy = await db.ApprovalAttachmentPolicies.AsNoTracking().SingleOrDefaultAsync(x => x.ApprovalType == type, ct)
?? ApprovalAttachmentPoliciesController.Default(type);
return Ok(new { policy.AllowedExtensions, policy.MaxFileBytes, policy.MaxFileCount });
}
[HttpGet("{type}/{id:guid}")]
public async Task<IActionResult> List(string type, Guid id, CancellationToken ct)
{
if (!await CanRead(type, id, ct)) return NotFound();
return Ok(await db.ApprovalAttachments.AsNoTracking().Where(x => x.ApprovalType == type && x.ApprovalId == id)
.OrderBy(x => x.CreatedAt).Select(x => new { x.Id, x.FileName, x.Length }).ToListAsync(ct));
}
[HttpGet("{type}/{id:guid}/{attachmentId:guid}")]
public async Task<IActionResult> Download(string type, Guid id, Guid attachmentId, CancellationToken ct)
{
if (!await CanRead(type, id, ct)) return NotFound();
var file = await db.ApprovalAttachments.AsNoTracking().SingleOrDefaultAsync(x => x.ApprovalType == type && x.ApprovalId == id && x.Id == attachmentId, ct);
if (file is null) return NotFound();
Response.ContentType = MediaTypeNames.Application.Octet;
Response.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileNameStar = file.FileName }.ToString();
Response.Headers.XContentTypeOptions = "nosniff";
Response.ContentLength = file.Length;
await new ApprovalAttachmentStorage(configuration, environment).CopyToAsync(file.StorageProvider, file.StorageKey, Response.Body, ct);
return new EmptyResult();
}
private async Task<bool> CanRead(string type, Guid id, CancellationToken ct)
{
if (!Types.Contains(type, StringComparer.Ordinal)) return false;
// Reuse the approval progress endpoint's business-specific access checks.
var result = await new ApprovalsController(db, scope).GetProgress(type, id, ct);
return result.Result is OkObjectResult;
}
}
Loaded 3 of 17 files, more files were not shown because too many files have changed in this diff. Show more