Expand approval center access and history

This commit is contained in:
biss committed 2026-12-01 10:35:32 +08:00
1 parent 3ce77d9cd9
commit 8b9f156dd4
4 files changed
+98 -5

No files matched your search

@@ -858,6 +858,15 @@ public sealed class ApprovalsController(
.Select(x => new ApprovalReviewedItem { Id = x.Id, Type = "GraduationClearance", Title = x.Student!.Name + " — " + x.GraduationClearanceItem!.Name, Time = x.CompletedAt!.Value, Comment = x.Notes }));
await Add(db.StudentStatusChangeEvents.AsNoTracking().Where(x => x.ActorUserId == userId && (x.ToState == StudentStatusChangeState.CounselorApproved || x.ToState == StudentStatusChangeState.CollegeApproved || x.ToState == StudentStatusChangeState.Approved || x.ToState == StudentStatusChangeState.Rejected))
.Select(x => new ApprovalReviewedItem { Id = x.StudentStatusChangeId, Type = "StudentStatusChange", Title = x.StudentStatusChange!.Student!.Name, Time = x.OccurredAt, Comment = x.Comment }));
// An approval by the receiving college does not change the status and
// is stored on the request. Rejections already have an event above.
await Add(db.StudentStatusChanges.AsNoTracking().Where(x => x.ReceivingCollegeReviewerId == userId && x.ReceivingCollegeReviewedAt != null &&
!db.StudentStatusChangeEvents.Any(e => e.StudentStatusChangeId == x.Id && e.ActorUserId == userId && e.OccurredAt == x.ReceivingCollegeReviewedAt && e.ToState == StudentStatusChangeState.Rejected))
.Select(x => new ApprovalReviewedItem { Id = x.Id, Type = "StudentStatusChange", Title = x.Student!.Name, Time = x.ReceivingCollegeReviewedAt!.Value, Comment = x.ReceivingCollegeReviewComment, Approved = true }));
await Add(db.StudentDisciplineEvents.AsNoTracking().Where(x => x.ActorUserId == userId &&
((x.FromState == StudentDisciplineState.Submitted && (x.ToState == StudentDisciplineState.CollegeApproved || x.ToState == StudentDisciplineState.Rejected)) ||
(x.FromState == StudentDisciplineState.CollegeApproved && (x.ToState == StudentDisciplineState.Effective || x.ToState == StudentDisciplineState.Rejected))))
.Select(x => new ApprovalReviewedItem { Id = x.StudentDisciplineId, Type = "StudentDiscipline", Title = x.StudentDiscipline!.Student!.Name + " — " + x.StudentDiscipline.DisciplineType, Time = x.OccurredAt, Comment = x.Comment, Approved = x.ToState != StudentDisciplineState.Rejected }));
return Ok(new ApprovalReviewedResult(items.OrderByDescending(x => x.Time).ThenBy(x => x.Type).ThenBy(x => x.Id).Skip((page - 1) * pageSize).Take(pageSize).ToList(), total));
}
@@ -1106,8 +1115,10 @@ public sealed class ApprovalsController(
var gradeAppeals = db.GradeAppeals.AsNoTracking().Where(x => x.Status == GradeAppealStatus.Submitted && x.GradeRecord!.GradeSheet!.TeachingTask!.Status != TeachingTaskStatus.Closed);
if (!isManager)
gradeAppeals = gradeAppeals.Where(x => x.GradeRecord!.GradeSheet!.TeachingTask!.Teachers.Any(t => t.Teacher!.UserId == current.UserId));
else if (current.RestrictedCollegeId is { } gradeCollegeId)
else if (current.Scope == DataScope.College && current.RestrictedCollegeId is { } gradeCollegeId)
gradeAppeals = gradeAppeals.Where(x => x.GradeRecord!.GradeSheet!.TeachingTask!.Course!.CollegeId == gradeCollegeId);
else if (current.Scope != DataScope.All)
gradeAppeals = gradeAppeals.Where(x => false);
items.AddRange(await gradeAppeals.WhereApprovalBefore(x => x.SubmittedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
.Select(x => new ApprovalItem(x.Id, "GradeAppeal", "成绩异议", $"{x.Student!.Name} — 《{x.GradeRecord!.GradeSheet!.TeachingTask!.Course!.Name}》", x.Reason, x.SubmittedAt, x.GradeRecord.GradeSheet.TeachingTask.Course.College!.Name)).ToListAsync(ct));
AddCount("GradeAppeal", await gradeAppeals.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
@@ -19,6 +19,43 @@ namespace Jiaowu.Api.Tests;
public sealed class ApprovalsControllerTests
{
[Fact]
public async Task Pending_grade_appeals_do_not_escape_a_missing_college_scope()
{
await using var fixture = await ApprovalFixture.CreateAsync();
var record = new GradeRecord { StudentId = fixture.Student.Id };
fixture.Db.GradeSheets.Add(new GradeSheet { TeachingTaskId = fixture.CurrentTask.Id, Records = [record] });
fixture.Db.GradeAppeals.Add(new GradeAppeal { StudentId = fixture.Student.Id, GradeRecordId = record.Id, Reason = "成绩有误" });
await fixture.Db.SaveChangesAsync();
var result = await new ApprovalsController(fixture.Db, new MissingCollegeDataScope()).GetPending(1, 20, CancellationToken.None, type: "GradeAppeal");
var page = Assert.IsType<ApprovalPendingResult>(Assert.IsType<OkObjectResult>(result.Result).Value);
Assert.Empty(page.Items);
}
[Fact]
public async Task Reviewed_includes_discipline_reviews_and_receiving_decisions_once()
{
await using var fixture = await ApprovalFixture.CreateAsync();
var scope = new ManagerDataScope();
var userId = scope.Current.UserId;
var now = DateTime.UtcNow;
var discipline = new StudentDiscipline { StudentId = fixture.Student.Id, DisciplineType = "警告", Facts = "事实", Basis = "依据", DecisionNumber = "1", DecisionAuthority = "学院", DecisionDate = DateOnly.FromDateTime(DateTime.Today), EffectiveDate = DateOnly.FromDateTime(DateTime.Today), CreatedByUserId = userId };
var accepted = new StudentStatusChange { StudentId = fixture.Student.Id, Reason = "转专业", ReceivingCollegeReviewerId = userId, ReceivingCollegeReviewedAt = now, ReceivingCollegeReviewComment = "同意接收" };
var rejected = new StudentStatusChange { StudentId = fixture.Student.Id, Reason = "转专业", ReceivingCollegeReviewerId = userId, ReceivingCollegeReviewedAt = now.AddMinutes(-1), ReceivingCollegeReviewComment = "不同意" };
fixture.Db.AddRange(discipline, accepted, rejected);
fixture.Db.StudentDisciplineEvents.AddRange(
new StudentDisciplineEvent { StudentDisciplineId = discipline.Id, ActorUserId = userId, OccurredAt = now.AddMinutes(-2), FromState = StudentDisciplineState.Submitted, ToState = StudentDisciplineState.CollegeApproved },
new StudentDisciplineEvent { StudentDisciplineId = discipline.Id, ActorUserId = userId, OccurredAt = now.AddMinutes(-3), FromState = StudentDisciplineState.Draft, ToState = StudentDisciplineState.Submitted });
fixture.Db.StudentStatusChangeEvents.Add(new StudentStatusChangeEvent { StudentStatusChangeId = rejected.Id, ActorUserId = userId, OccurredAt = now.AddMinutes(-1), FromState = StudentStatusChangeState.CollegeApproved, ToState = StudentStatusChangeState.Rejected });
await fixture.Db.SaveChangesAsync();
var result = await new ApprovalsController(fixture.Db, scope).GetReviewed();
var page = Assert.IsType<ApprovalReviewedResult>(Assert.IsType<OkObjectResult>(result.Result).Value);
Assert.Equal(3, page.Total);
Assert.True(Assert.Single(page.Items, x => x.Id == accepted.Id).Approved);
Assert.Single(page.Items, x => x.Id == rejected.Id);
Assert.True(Assert.Single(page.Items, x => x.Id == discipline.Id).Approved);
}
[Fact]
public async Task Reviewed_list_returns_only_current_reviewers_records_in_review_time_order()
{
@@ -2035,6 +2072,11 @@ public sealed class ApprovalsControllerTests
new HashSet<string>([SystemRoles.SuperAdmin]));
}
private sealed class MissingCollegeDataScope : ICurrentUserDataScope
{
public CurrentUserScope Current { get; } = new(Guid.NewGuid(), "学院管理员", null, DataScope.College, new HashSet<string>([SystemRoles.CollegeAdmin]));
}
private sealed class CollegeDataScope(Guid collegeId) : ICurrentUserDataScope
{
public CurrentUserScope Current { get; } = new(
+8 -2
View File
@@ -1,8 +1,12 @@
import { expect, test } from '@playwright/test'
test.use({ serviceWorkers: 'block' })
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 }, progress: true },
{ type: 'StudentStatusChange', stage: 'receivingCollege', endpoint: '/api/student-status-changes/item-1/receiving-college-review', body: { approved: true, comment: null }, progress: true },
{ type: 'AssessmentDeclaration', stage: 'counselor', endpoint: '/api/comprehensive-assessments/declarations/item-1/review', body: { approved: true, comment: null }, progress: true },
{ type: 'TeacherCourseApplication', stage: null, endpoint: '/api/teacher-course-applications/item-1/review', body: { status: 'Approved', reviewComment: null }, progress: true },
{ type: 'ClassroomReservation', stage: null, endpoint: '/api/classroom-reservations/item-1/approve', body: { comment: null }, progress: true },
{ type: 'CampusRegistration', stage: null, endpoint: '/api/campus-registrations/applications/item-1/review', body: { approved: true, comment: null } },
@@ -13,11 +17,12 @@ const cases: { type: string; stage: string | null; secondaryId?: string; endpoin
{ type: 'CourseAdjustment', stage: null, endpoint: '/api/course-adjustments/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 }) => {
for (const scenario of cases) test(`${scenario.type} ${scenario.stage ?? 'review'} can be ${scenario.reject ? 'rejected' : 'approved'} from the approval center`, async ({ page }) => {
if (scenario.type === 'StudentStatusChange') await page.setViewportSize({ width: 360, height: 800 })
const pageErrors: string[] = []
page.on('pageerror', error => pageErrors.push(error.message))
const user = { id: 'reviewer', userName: 'reviewer', displayName: '审核员', roles: ['AcademicAdmin'], permissions: [], effectiveDataScope: 'All' }
const roles = scenario.type === 'AssessmentDeclaration' ? ['Counselor'] : scenario.stage === 'receivingCollege' ? ['CollegeAdmin'] : ['AcademicAdmin']
const user = { id: 'reviewer', userName: 'reviewer', displayName: '审核员', roles, permissions: [], effectiveDataScope: 'All' }
await page.addInitScript((savedUser) => {
localStorage.setItem('jiaowu_token', 'test-token')
localStorage.setItem('jiaowu_user', JSON.stringify(savedUser))
@@ -73,6 +78,7 @@ for (const scenario of cases) test(`${scenario.type} can be ${scenario.reject ?
await expect(dialog.getByText(scenario.type === 'TeacherCourseApplication' ? '本次申报开始' : '已提交')).toBeVisible()
if (scenario.type === 'StudentStatusChange') await expect(dialog.getByText('该申请部分办理详情未留存。')).toBeVisible()
await dialog.locator('.el-dialog__headerbtn').click()
await expect(dialog).toBeHidden()
}
if (scenario.reject) {
await card.getByRole('button', { name: '驳回' }).click()
Loaded 3 of 4 files, more files were not shown because too many files have changed in this diff. Show more