Enable direct review and filter approval queues
This commit is contained in:
1 parent
2d1a43fd39
commit
88ef93022d
6 files changed
+169
-26
No files matched your search
@@ -61,7 +61,8 @@ public sealed class ApprovalsController(
|
||||
int page = 1,
|
||||
int pageSize = 20,
|
||||
CancellationToken ct = default,
|
||||
bool oldestFirst = false)
|
||||
bool oldestFirst = false,
|
||||
string? type = null)
|
||||
{
|
||||
if (page < 1 || pageSize is < 1 or > 100 || (long)page * pageSize > 100000)
|
||||
return ValidationProblem("page 必须大于 0,pageSize 必须在 1 到 100 之间,且分页窗口不能超过 100000 条。");
|
||||
@@ -114,7 +115,7 @@ public sealed class ApprovalsController(
|
||||
var canCollegeReview = scope.Current.IsInRole(SystemRoles.CollegeAdmin);
|
||||
items.AddRange(await Scoped<StudentStatusChange>(x => (canCollegeReview && x.State == StudentStatusChangeState.CounselorApproved) || (canFinalReview && x.State == StudentStatusChangeState.CollegeApproved))
|
||||
.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "StudentStatusChange", "学籍异动", $"{x.Student!.Name} — {SSCLabel(x.Type)}", x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name))
|
||||
.Select(x => new ApprovalItem(x.Id, "StudentStatusChange", "学籍异动", $"{x.Student!.Name} — {SSCLabel(x.Type)}", x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name, x.State == StudentStatusChangeState.CounselorApproved ? "college" : "final"))
|
||||
.ToListAsync(ct));
|
||||
AddCount("StudentStatusChange", await Scoped<StudentStatusChange>(x => (canCollegeReview && x.State == StudentStatusChangeState.CounselorApproved) || (canFinalReview && x.State == StudentStatusChangeState.CollegeApproved)).CountAsync(ct));
|
||||
|
||||
@@ -189,7 +190,7 @@ public sealed class ApprovalsController(
|
||||
items.AddRange(await dormApplications.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "DormitoryApplication", "住宿申请",
|
||||
x.Student!.Name, x.Reason, x.SubmittedAt,
|
||||
x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
x.Student.AdministrativeClass!.Major!.College!.Name, x.Status == DormitoryApplicationStatus.Submitted ? "counselor" : "dormitory")).ToListAsync(ct));
|
||||
AddCount("DormitoryApplication", await dormApplications.CountAsync(ct));
|
||||
}
|
||||
|
||||
@@ -197,7 +198,7 @@ public sealed class ApprovalsController(
|
||||
items.AddRange(await declarations.OrderByApprovalTime(x => x.SubmittedAt ?? x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "AssessmentDeclaration", "综合测评材料复核",
|
||||
$"{x.Student!.Name} — {x.Title}", x.Category, x.SubmittedAt ?? x.CreatedAt,
|
||||
x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
x.Student.AdministrativeClass!.Major!.College!.Name, "college")).ToListAsync(ct));
|
||||
AddCount("AssessmentDeclaration", await declarations.CountAsync(ct));
|
||||
|
||||
var assessmentAppeals = Scoped<ComprehensiveAssessmentAppeal>(x => x.Status == ComprehensiveAssessmentAppealStatus.Submitted);
|
||||
@@ -213,17 +214,17 @@ public sealed class ApprovalsController(
|
||||
var userId = current.UserId;
|
||||
var changes = db.StudentStatusChanges.AsNoTracking().Where(x => x.State == StudentStatusChangeState.Submitted && x.Student!.AdministrativeClass!.CounselorUserId == userId);
|
||||
items.AddRange(await changes.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "StudentStatusChange", "学籍异动", x.Student!.Name, x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
.Select(x => new ApprovalItem(x.Id, "StudentStatusChange", "学籍异动", $"{x.Student!.Name} — {SSCLabel(x.Type)}", x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name, "counselor")).ToListAsync(ct));
|
||||
AddCount("StudentStatusChange", await changes.CountAsync(ct));
|
||||
var declarations = db.ComprehensiveAssessmentDeclarations.AsNoTracking().Where(x => x.Status == ComprehensiveAssessmentDeclarationStatus.Submitted && x.Student!.AdministrativeClass!.CounselorUserId == userId);
|
||||
items.AddRange(await declarations.OrderByApprovalTime(x => x.SubmittedAt ?? x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "AssessmentDeclaration", "综合测评材料初审", $"{x.Student!.Name} — {x.Title}", x.Category, x.SubmittedAt ?? x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
.Select(x => new ApprovalItem(x.Id, "AssessmentDeclaration", "综合测评材料初审", $"{x.Student!.Name} — {x.Title}", x.Category, x.SubmittedAt ?? x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name, "counselor")).ToListAsync(ct));
|
||||
AddCount("AssessmentDeclaration", await declarations.CountAsync(ct));
|
||||
if (!isManager)
|
||||
{
|
||||
var dorm = db.DormitoryApplications.AsNoTracking().Where(x => x.Status == DormitoryApplicationStatus.Submitted && x.Student!.AdministrativeClass!.CounselorUserId == userId);
|
||||
items.AddRange(await dorm.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "DormitoryApplication", "住宿申请", x.Student!.Name, x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
.Select(x => new ApprovalItem(x.Id, "DormitoryApplication", "住宿申请", x.Student!.Name, x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name, "counselor")).ToListAsync(ct));
|
||||
AddCount("DormitoryApplication", await dorm.CountAsync(ct));
|
||||
}
|
||||
}
|
||||
@@ -253,14 +254,14 @@ public sealed class ApprovalsController(
|
||||
{
|
||||
var dorm = Scoped<DormitoryApplication>(x => x.Status == DormitoryApplicationStatus.CounselorApproved);
|
||||
items.AddRange(await dorm.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "DormitoryApplication", "住宿申请", x.Student!.Name, x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
.Select(x => new ApprovalItem(x.Id, "DormitoryApplication", "住宿申请", x.Student!.Name, x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name, "dormitory")).ToListAsync(ct));
|
||||
AddCount("DormitoryApplication", await dorm.CountAsync(ct));
|
||||
}
|
||||
if (current.IsInRole(SystemRoles.StudentAffairsAdmin) && !isManager)
|
||||
{
|
||||
var declarations = Scoped<ComprehensiveAssessmentDeclaration>(x => x.Status == ComprehensiveAssessmentDeclarationStatus.CounselorApproved);
|
||||
items.AddRange(await declarations.OrderByApprovalTime(x => x.SubmittedAt ?? x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "AssessmentDeclaration", "综合测评材料复核", $"{x.Student!.Name} — {x.Title}", x.Category, x.SubmittedAt ?? x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
.Select(x => new ApprovalItem(x.Id, "AssessmentDeclaration", "综合测评材料复核", $"{x.Student!.Name} — {x.Title}", x.Category, x.SubmittedAt ?? x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name, "college")).ToListAsync(ct));
|
||||
AddCount("AssessmentDeclaration", await declarations.CountAsync(ct));
|
||||
var appeals = Scoped<ComprehensiveAssessmentAppeal>(x => x.Status == ComprehensiveAssessmentAppealStatus.Submitted);
|
||||
items.AddRange(await appeals.OrderByApprovalTime(x => x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
@@ -296,7 +297,9 @@ public sealed class ApprovalsController(
|
||||
AddCount("GraduationClearance", await clearances.CountAsync(ct));
|
||||
}
|
||||
|
||||
var ordered = oldestFirst ? items.OrderBy(x => x.Time) : items.OrderByDescending(x => x.Time);
|
||||
var filtered = string.IsNullOrWhiteSpace(type) ? items : items.Where(x => x.Type == type);
|
||||
if (!string.IsNullOrWhiteSpace(type)) total = counts.GetValueOrDefault(type);
|
||||
var ordered = oldestFirst ? filtered.OrderBy(x => x.Time) : filtered.OrderByDescending(x => x.Time);
|
||||
var pageItems = ordered
|
||||
.ThenBy(x => x.Type)
|
||||
.ThenBy(x => x.Id)
|
||||
|
||||
@@ -13,6 +13,28 @@ namespace Jiaowu.Api.Tests;
|
||||
|
||||
public sealed class ApprovalsControllerTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Counselor_queue_shows_the_status_change_stage_and_type()
|
||||
{
|
||||
await using var fixture = await ApprovalFixture.CreateAsync();
|
||||
var counselorId = Guid.NewGuid();
|
||||
fixture.Db.Users.Add(new ApplicationUser { Id = counselorId, UserName = "counselor-test", DisplayName = "辅导员" });
|
||||
var administrativeClass = await fixture.Db.AdministrativeClasses.FindAsync(fixture.Student.AdministrativeClassId);
|
||||
administrativeClass!.CounselorUserId = counselorId;
|
||||
fixture.Db.StudentStatusChanges.Add(new StudentStatusChange
|
||||
{
|
||||
StudentId = fixture.Student.Id, Type = StudentStatusChangeType.Suspension,
|
||||
Reason = "需要休学", State = StudentStatusChangeState.Submitted
|
||||
});
|
||||
await fixture.Db.SaveChangesAsync();
|
||||
var response = await new ApprovalsController(fixture.Db, new CounselorDataScope(counselorId))
|
||||
.GetPending(1, 20, CancellationToken.None);
|
||||
var result = Assert.IsType<ApprovalPendingResult>(Assert.IsType<OkObjectResult>(response.Result).Value);
|
||||
var item = Assert.Single(result.Items);
|
||||
Assert.Equal("counselor", item.Stage);
|
||||
Assert.Contains("休学", item.Title);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Clearance_pending_only_includes_the_responsible_role()
|
||||
{
|
||||
@@ -164,6 +186,12 @@ public sealed class ApprovalsControllerTests
|
||||
var oldestPage = Assert.IsType<ApprovalPendingResult>(Assert.IsType<OkObjectResult>(oldest.Result).Value);
|
||||
Assert.Equal("较早提交", Assert.Single(oldestPage.Items).Desc);
|
||||
Assert.Equal(2, oldestPage.Total);
|
||||
|
||||
var filtered = await controller.GetPending(1, 1, CancellationToken.None, type: "CourseExemption");
|
||||
var filteredPage = Assert.IsType<ApprovalPendingResult>(Assert.IsType<OkObjectResult>(filtered.Result).Value);
|
||||
Assert.Equal(1, filteredPage.Total);
|
||||
Assert.Equal("CourseExemption", Assert.Single(filteredPage.Items).Type);
|
||||
Assert.Equal(1, filteredPage.Counts["DeferredExam"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -477,4 +505,11 @@ public sealed class ApprovalsControllerTests
|
||||
Guid.NewGuid(), "学院管理员", collegeId, DataScope.College,
|
||||
new HashSet<string>([SystemRoles.CollegeAdmin]));
|
||||
}
|
||||
|
||||
private sealed class CounselorDataScope(Guid userId) : ICurrentUserDataScope
|
||||
{
|
||||
public CurrentUserScope Current { get; } = new(
|
||||
userId, "辅导员", null, DataScope.Class,
|
||||
new HashSet<string>([SystemRoles.Counselor]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { expect, test } from '@playwright/test'
|
||||
|
||||
const cases: { type: string; stage: string | null; secondaryId?: string; endpoint: string; body: Record<string, unknown>; reject?: 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 } },
|
||||
{ type: 'ClassroomReservation', stage: null, endpoint: '/api/classroom-reservations/item-1/approve', body: { comment: null } },
|
||||
{ type: 'CampusRegistration', stage: null, endpoint: '/api/campus-registrations/applications/item-1/review', body: { approved: true, comment: null } },
|
||||
{ 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 },
|
||||
]
|
||||
|
||||
for (const scenario of cases) test(`${scenario.type} can be ${scenario.reject ? 'rejected' : 'approved'} from the approval center`, async ({ page }) => {
|
||||
const pageErrors: string[] = []
|
||||
page.on('pageerror', error => pageErrors.push(error.message))
|
||||
const user = { id: 'reviewer', userName: 'reviewer', displayName: '审核员', roles: ['AcademicAdmin'], permissions: [], effectiveDataScope: 'All' }
|
||||
await page.addInitScript((savedUser) => {
|
||||
localStorage.setItem('jiaowu_token', 'test-token')
|
||||
localStorage.setItem('jiaowu_user', JSON.stringify(savedUser))
|
||||
localStorage.setItem('jiaowu_access_expires_at', '2099-01-01T00:00:00Z')
|
||||
localStorage.setItem('jiaowu_session_expires_at', '2099-01-01T00:00:00Z')
|
||||
}, user)
|
||||
let reviewed = false
|
||||
await page.route(url => url.pathname.startsWith('/api/'), async route => {
|
||||
const url = new URL(route.request().url())
|
||||
if (url.pathname === '/api/approvals/pending') {
|
||||
const items = reviewed ? [] : [{ id: 'item-1', secondaryId: scenario.secondaryId, type: scenario.type, stage: scenario.stage, label: '申请', title: '学生 — 《课程》', desc: '申请事由', time: '2026-11-01T00:00:00Z', college: '学院' }]
|
||||
return route.fulfill({ json: { items, total: items.length, page: 1, pageSize: 20, counts: reviewed ? {} : { [scenario.type]: 1 } } })
|
||||
}
|
||||
if (url.pathname === scenario.endpoint) {
|
||||
expect(route.request().method()).toBe('POST')
|
||||
expect(route.request().postDataJSON()).toEqual(scenario.body)
|
||||
reviewed = true
|
||||
return route.fulfill({ status: 204 })
|
||||
}
|
||||
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: {} })
|
||||
})
|
||||
await page.goto('/approvals')
|
||||
const card = page.locator('.appr-card').filter({ hasText: '申请事由' })
|
||||
await expect(card).toBeVisible()
|
||||
if (scenario.reject) {
|
||||
await card.getByRole('button', { name: '驳回' }).click()
|
||||
const dialog = page.getByRole('dialog')
|
||||
await dialog.locator('textarea').fill('理由不充分')
|
||||
await dialog.getByRole('button', { name: '确认驳回' }).click()
|
||||
} else await card.getByRole('button', { name: '通过' }).click()
|
||||
await expect(card).toHaveCount(0)
|
||||
expect(reviewed).toBe(true)
|
||||
expect(pageErrors).toEqual([])
|
||||
})
|
||||
Loaded 3 of 6 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user