Fix approval notification deep links

This commit is contained in:
biss committed 2026-12-01 10:55:26 +08:00
1 parent 2b595e57c0
commit 92ac805664
6 files changed
+139 -14

No files matched your search

@@ -1187,12 +1187,32 @@ public sealed class ApprovalsController(
}
[HttpGet("pending/{type}/{id:guid}")]
[Authorize(Roles = Managers)]
[Authorize(Roles = Managers + "," + SystemRoles.Teacher + "," + SystemRoles.Counselor + "," + SystemRoles.DormitoryAdmin + "," + SystemRoles.StudentAffairsAdmin + "," + SystemRoles.Leader)]
public async Task<ActionResult<ApprovalItem>> GetPendingItem(
string type,
Guid id,
CancellationToken ct)
CancellationToken ct,
Guid? secondaryId = null)
{
var current = scope.Current;
var isManager = current.IsInRole(SystemRoles.SuperAdmin) || current.IsInRole(SystemRoles.AcademicAdmin) || current.IsInRole(SystemRoles.CollegeAdmin);
if (type == "ClassroomReservation")
{
if (!current.IsInRole(SystemRoles.CollegeAdmin) || current.CollegeId is not { } collegeId) return NotFound();
var reservation = await db.ClassroomReservations.AsNoTracking().Where(x => x.Id == id && x.Status == ClassroomReservationStatus.Submitted && x.ApplicantCollegeId == collegeId)
.Select(x => new ApprovalItem(x.Id, "ClassroomReservation", "教室借用", x.ApplicantName + " — " + x.Classroom!.Name, x.Purpose, x.CreatedAt, x.ApplicantCollege!.Name)).FirstOrDefaultAsync(ct);
return reservation is null ? NotFound() : Ok(reservation);
}
if (type == "AttendanceAppeal")
{
if (!secondaryId.HasValue || !(isManager || current.IsInRole(SystemRoles.Teacher) || current.IsInRole(SystemRoles.Counselor))) return NotFound();
var attendance = db.AttendanceRecords.AsNoTracking().Where(x => x.StudentId == id && x.AttendanceSheetId == secondaryId.Value && x.AppealStatus == AttendanceAppealStatus.Pending && x.AttendanceSheet!.TeachingTask!.Status == TeachingTaskStatus.Published);
if (!(current.IsInRole(SystemRoles.SuperAdmin) || current.IsInRole(SystemRoles.AcademicAdmin)))
attendance = attendance.Where(x => x.AttendanceSheet!.TeachingTask!.Teachers.Any(t => t.Teacher!.UserId == current.UserId));
var appeal = await attendance.Select(x => new ApprovalItem(x.StudentId, "AttendanceAppeal", "考勤申诉", x.Student!.Name + " — 《" + x.AttendanceSheet!.TeachingTask!.Course!.Name + "》", x.AppealReason ?? "", x.AppealSubmittedAt ?? x.AttendanceSheet.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name, null, x.AttendanceSheetId)).FirstOrDefaultAsync(ct);
return appeal is null ? NotFound() : Ok(appeal);
}
if (!isManager) return NotFound();
var canFinalReview = scope.Current.IsInRole(SystemRoles.SuperAdmin) || scope.Current.IsInRole(SystemRoles.AcademicAdmin);
var super = scope.Current.IsInRole(SystemRoles.SuperAdmin);
var college = scope.Current.IsInRole(SystemRoles.CollegeAdmin);
@@ -1134,7 +1134,7 @@ public sealed class AttendanceController(
await NotificationService.SendToUserIdsAsync(db, teacherUserIds,
"考勤申诉待处理",
$"学生 {studentName} 对《{courseName}》考勤记录提出申诉。",
"/teacher-attendance", cancellationToken,
$"/approvals?tab=pending&type=AttendanceAppeal&id={record.StudentId}&secondaryId={record.AttendanceSheetId}", cancellationToken,
NotificationCategory.Attendance);
}
@@ -319,7 +319,7 @@ public sealed class ClassroomReservationsController(
$"{reservation.ApplicantName} 申请于 {reservation.ReservationDate:yyyy-MM-dd} " +
$"借用 {classroom.BuildingName} {classroom.Name}。",
reservation.ApplicantCollegeId,
"/classroom-reservations",
$"/approvals?tab=pending&type=ClassroomReservation&id={reservation.Id}",
cancellationToken,
NotificationCategory.Approval);
return Created("", new { reservation.Id });
Loaded 3 of 6 files, more files were not shown because too many files have changed in this diff. Show more