Show recorded approval progress

This commit is contained in:
biss committed 2026-11-07 20:27:41 +08:00
1 parent 88ef93022d
commit 75f1751629
6 files changed
+165 -1

No files matched your search

@@ -54,6 +54,68 @@ public sealed class ApprovalsController(
return NoContent();
}
[HttpGet("progress/{type}/{id:guid}")]
public async Task<ActionResult<ApprovalProgressResponse>> GetProgress(string type, Guid id, CancellationToken ct)
{
var current = scope.Current;
var manager = current.IsInRole(SystemRoles.SuperAdmin) || current.IsInRole(SystemRoles.AcademicAdmin) || current.IsInRole(SystemRoles.CollegeAdmin);
var userId = current.UserId;
var steps = new List<ApprovalProgressStep>();
switch (type)
{
case "CourseExemption":
{
var query = manager ? Scoped<CourseExemption>(x => x.Id == id) : db.CourseExemptions.AsNoTracking().Where(x => x.Id == id && x.Student!.UserId == userId);
var item = await query.FirstOrDefaultAsync(ct);
if (item is null) return NotFound();
AddSingleApprovalSteps(steps, item.SubmittedAt, item.ReviewedAt, item.Status, item.ReviewComment);
break;
}
case "DeferredExam":
{
var query = manager ? Scoped<DeferredExam>(x => x.Id == id) : db.DeferredExams.AsNoTracking().Where(x => x.Id == id && x.Student!.UserId == userId);
var item = await query.FirstOrDefaultAsync(ct);
if (item is null) return NotFound();
AddSingleApprovalSteps(steps, item.SubmittedAt, item.ReviewedAt, item.Status, item.ReviewComment);
break;
}
case "CourseSubstitution":
{
var query = manager ? Scoped<CourseSubstitution>(x => x.Id == id) : db.CourseSubstitutions.AsNoTracking().Where(x => x.Id == id && x.Student!.UserId == userId);
var item = await query.FirstOrDefaultAsync(ct);
if (item is null) return NotFound();
AddSingleApprovalSteps(steps, item.SubmittedAt, item.ReviewedAt, item.Status, item.ReviewComment);
break;
}
case "GradeModification":
{
var query = manager ? Scoped<GradeModification>(x => x.Id == id) : db.GradeModifications.AsNoTracking().Where(x => x.Id == id && x.ApplicantUserId == userId);
var item = await query.FirstOrDefaultAsync(ct);
if (item is null) return NotFound();
steps.Add(new("submitted", item.SubmittedAt, item.Reason));
if (item.CollegeReviewedAt is { } collegeTime)
{
var rejected = item.Status == GradeModificationStatus.Rejected && item.FinalReviewedAt is null;
steps.Add(new(rejected ? "collegeRejected" : "collegeApproved", collegeTime, rejected ? item.ReviewComment : null));
}
if (item.FinalReviewedAt is { } finalTime)
steps.Add(new(item.Status == GradeModificationStatus.Rejected ? "finalRejected" : "finalApproved", finalTime, item.ReviewComment));
break;
}
default:
return NotFound();
}
return Ok(new ApprovalProgressResponse(type, id, steps));
}
private static void AddSingleApprovalSteps(List<ApprovalProgressStep> steps, DateTime submittedAt, DateTime? reviewedAt, ApprovalStatus status, string? comment)
{
steps.Add(new("submitted", submittedAt, null));
if (reviewedAt is { } time && status is ApprovalStatus.Approved or ApprovalStatus.Rejected)
steps.Add(new(status == ApprovalStatus.Approved ? "approved" : "rejected", time, comment));
}
// ═══════════════ Aggregated pending ═══════════════
[HttpGet("pending")]
[Authorize(Roles = Managers + "," + SystemRoles.Teacher + "," + SystemRoles.Counselor + "," + SystemRoles.DormitoryAdmin + "," + SystemRoles.StudentAffairsAdmin + "," + SystemRoles.Leader)]
@@ -1023,6 +1085,8 @@ public sealed class ApprovalsController(
public sealed record ApprovalItem(Guid Id, string Type, string Label, string Title, string Desc, DateTime Time, string College, string? Stage = null, Guid? SecondaryId = null);
public sealed record ApprovalPendingResult(IReadOnlyCollection<ApprovalItem> Items, int Total, int Page, int PageSize, IReadOnlyDictionary<string, int> Counts);
public sealed record ApprovalRouteSettingRequest([Required] string ReviewerRole);
public sealed record ApprovalProgressStep(string Kind, DateTime Time, string? Comment);
public sealed record ApprovalProgressResponse(string Type, Guid Id, IReadOnlyList<ApprovalProgressStep> Steps);
internal static class ApprovalOrderingExtensions
{
@@ -13,6 +13,55 @@ namespace Jiaowu.Api.Tests;
public sealed class ApprovalsControllerTests
{
[Fact]
public async Task Grade_change_progress_keeps_college_and_final_decisions_distinct()
{
await using var fixture = await ApprovalFixture.CreateAsync();
var sheet = new GradeSheet { TeachingTaskId = fixture.CurrentTask.Id };
var record = new GradeRecord { GradeSheetId = sheet.Id, StudentId = fixture.Student.Id };
var submitted = DateTime.UtcNow.AddDays(-1);
var change = new GradeModification
{
GradeRecordId = record.Id, ApplicantUserId = Guid.NewGuid(), Reason = "更正依据",
Status = GradeModificationStatus.Rejected, SubmittedAt = submitted,
CollegeReviewedAt = submitted.AddHours(1), FinalReviewedAt = submitted.AddHours(2),
ReviewComment = "校级未通过"
};
fixture.Db.AddRange(sheet, record, change);
await fixture.Db.SaveChangesAsync();
var controller = new ApprovalsController(fixture.Db, new ManagerDataScope());
var response = await controller.GetProgress("GradeModification", change.Id, CancellationToken.None);
var result = Assert.IsType<ApprovalProgressResponse>(Assert.IsType<OkObjectResult>(response.Result).Value);
Assert.Equal(new[] { "submitted", "collegeApproved", "finalRejected" }, result.Steps.Select(x => x.Kind));
Assert.Null(result.Steps[1].Comment);
Assert.Equal("校级未通过", result.Steps[2].Comment);
}
[Fact]
public async Task Progress_uses_recorded_events_and_enforces_access()
{
await using var fixture = await ApprovalFixture.CreateAsync();
var submitted = DateTime.UtcNow.AddHours(-2);
var reviewed = submitted.AddHours(1);
var exemption = new CourseExemption
{
StudentId = fixture.Student.Id, TeachingTaskId = fixture.CurrentTask.Id,
Reason = "申请免修", SubmittedAt = submitted, ReviewedAt = reviewed,
Status = ApprovalStatus.Rejected, ReviewComment = "材料不足"
};
fixture.Db.CourseExemptions.Add(exemption);
await fixture.Db.SaveChangesAsync();
var response = await fixture.Controller.GetProgress("CourseExemption", exemption.Id, CancellationToken.None);
var progress = Assert.IsType<ApprovalProgressResponse>(Assert.IsType<OkObjectResult>(response.Result).Value);
Assert.Equal(new[] { "submitted", "rejected" }, progress.Steps.Select(x => x.Kind));
Assert.Equal("材料不足", progress.Steps[1].Comment);
var outsider = new ApprovalsController(fixture.Db, new StudentDataScope(Guid.NewGuid()));
Assert.IsType<NotFoundResult>((await outsider.GetProgress("CourseExemption", exemption.Id, CancellationToken.None)).Result);
var otherCollege = new ApprovalsController(fixture.Db, new CollegeDataScope(Guid.NewGuid()));
Assert.IsType<NotFoundResult>((await otherCollege.GetProgress("CourseExemption", exemption.Id, CancellationToken.None)).Result);
}
[Fact]
public async Task Counselor_queue_shows_the_status_change_stage_and_type()
{
+10 -1
View File
@@ -1,6 +1,6 @@
import { expect, test } from '@playwright/test'
const cases: { type: string; stage: string | null; secondaryId?: string; endpoint: string; body: Record<string, unknown>; reject?: boolean }[] = [
const cases: { type: string; stage: string | null; secondaryId?: string; endpoint: string; body: Record<string, unknown> | null; reject?: boolean; progress?: boolean }[] = [
{ type: 'AttendanceAppeal', stage: null, secondaryId: 'sheet-1', endpoint: '/api/attendance/appeals/sheet-1/item-1/review', body: { approve: true, comment: null } },
{ type: 'StudentStatusChange', stage: 'final', endpoint: '/api/student-status-changes/item-1/review', body: { approved: true, comment: null } },
{ type: 'TeacherCourseApplication', stage: null, endpoint: '/api/teacher-course-applications/item-1/review', body: { status: 'Approved', reviewComment: null } },
@@ -9,6 +9,7 @@ const cases: { type: string; stage: string | null; secondaryId?: string; endpoin
{ type: 'DormitoryApplication', stage: 'counselor', endpoint: '/api/dormitory-services/applications/item-1/counselor-review', body: { approved: true, comment: null } },
{ type: 'AttendanceAppeal', stage: null, secondaryId: 'sheet-1', endpoint: '/api/attendance/appeals/sheet-1/item-1/review', body: { approve: false, comment: '理由不充分' }, reject: true },
{ type: 'TeacherCourseApplication', stage: null, endpoint: '/api/teacher-course-applications/item-1/review', body: { status: 'Rejected', reviewComment: '理由不充分' }, reject: true },
{ type: 'CourseExemption', stage: null, endpoint: '/api/approvals/exemptions/item-1/approve', body: null, progress: true },
]
for (const scenario of cases) test(`${scenario.type} can be ${scenario.reject ? 'rejected' : 'approved'} from the approval center`, async ({ page }) => {
@@ -34,6 +35,8 @@ for (const scenario of cases) test(`${scenario.type} can be ${scenario.reject ?
reviewed = true
return route.fulfill({ status: 204 })
}
if (url.pathname === '/api/approvals/progress/CourseExemption/item-1')
return route.fulfill({ json: { type: scenario.type, id: 'item-1', steps: [{ kind: 'submitted', time: '2026-11-01T00:00:00Z', comment: null }] } })
if (url.pathname === '/api/auth/me') return route.fulfill({ json: user })
if (url.pathname === '/api/plugins/runtime') return route.fulfill({ json: [] })
return route.fulfill({ json: {} })
@@ -41,6 +44,12 @@ for (const scenario of cases) test(`${scenario.type} can be ${scenario.reject ?
await page.goto('/approvals')
const card = page.locator('.appr-card').filter({ hasText: '申请事由' })
await expect(card).toBeVisible()
if (scenario.progress) {
await card.getByRole('button', { name: '办理进度' }).click()
const dialog = page.getByRole('dialog')
await expect(dialog.getByText('已提交')).toBeVisible()
await dialog.locator('.el-dialog__headerbtn').click()
}
if (scenario.reject) {
await card.getByRole('button', { name: '驳回' }).click()
const dialog = page.getByRole('dialog')
Loaded 3 of 6 files, more files were not shown because too many files have changed in this diff. Show more