Fix assessment workflow and physical admin data scope
This commit is contained in:
1 parent
304b8abeb8
commit
faa2743b84
11 files changed
+135
-21
No files matched your search
@@ -1253,12 +1253,7 @@ public sealed class ComprehensiveAssessmentsController(
|
||||
{
|
||||
page = Math.Max(page, 1);
|
||||
pageSize = Math.Clamp(pageSize, 10, 100);
|
||||
var query = ApplyDeclarationScope(db.ComprehensiveAssessmentDeclarations.AsNoTracking())
|
||||
.Where(x => x.Status == ComprehensiveAssessmentDeclarationStatus.Submitted || x.Status == ComprehensiveAssessmentDeclarationStatus.CounselorApproved);
|
||||
var current = currentUserDataScope.Current;
|
||||
query = current.Scope == DataScope.Class && current.IsInRole(SystemRoles.Counselor)
|
||||
? query.Where(x => x.Status == ComprehensiveAssessmentDeclarationStatus.Submitted)
|
||||
: query.Where(x => x.Status == ComprehensiveAssessmentDeclarationStatus.CounselorApproved);
|
||||
var query = PendingDeclarationScope(db.ComprehensiveAssessmentDeclarations.AsNoTracking());
|
||||
if (batchId.HasValue) query = query.Where(x => x.ComprehensiveAssessmentBatchId == batchId);
|
||||
if (!string.IsNullOrWhiteSpace(keyword))
|
||||
{
|
||||
@@ -1278,10 +1273,10 @@ public sealed class ComprehensiveAssessmentsController(
|
||||
[Authorize(Roles = Reviewers)]
|
||||
public async Task<ActionResult> ReviewDeclaration(Guid id, ReviewAssessmentDeclarationRequest request, CancellationToken token)
|
||||
{
|
||||
var item = await ApplyDeclarationScope(db.ComprehensiveAssessmentDeclarations).Include(x => x.Dimension).FirstOrDefaultAsync(x => x.Id == id, token);
|
||||
var item = await PendingDeclarationScope(db.ComprehensiveAssessmentDeclarations).Include(x => x.Dimension).FirstOrDefaultAsync(x => x.Id == id, token);
|
||||
if (item is null) return NotFound();
|
||||
var current = currentUserDataScope.Current;
|
||||
var counselorStage = current.Scope == DataScope.Class && current.IsInRole(SystemRoles.Counselor);
|
||||
var counselorStage = item.Status == ComprehensiveAssessmentDeclarationStatus.Submitted;
|
||||
if (counselorStage)
|
||||
{
|
||||
if (item.Status != ComprehensiveAssessmentDeclarationStatus.Submitted) return ConflictProblem("材料不在辅导员初审阶段。");
|
||||
@@ -1471,6 +1466,20 @@ public sealed class ComprehensiveAssessmentsController(
|
||||
return query;
|
||||
}
|
||||
|
||||
private IQueryable<ComprehensiveAssessmentDeclaration> PendingDeclarationScope(IQueryable<ComprehensiveAssessmentDeclaration> query)
|
||||
{
|
||||
var current = currentUserDataScope.Current;
|
||||
var counselor = current.IsInRole(SystemRoles.Counselor);
|
||||
var schoolReviewer = current.IsInRole(SystemRoles.SuperAdmin) ||
|
||||
current.IsInRole(SystemRoles.AcademicAdmin) || current.IsInRole(SystemRoles.StudentAffairsAdmin);
|
||||
var collegeReviewer = current.IsInRole(SystemRoles.CollegeAdmin) && current.CollegeId.HasValue;
|
||||
return query.Where(x =>
|
||||
(counselor && x.Status == ComprehensiveAssessmentDeclarationStatus.Submitted &&
|
||||
x.Student!.AdministrativeClass!.CounselorUserId == current.UserId) ||
|
||||
((schoolReviewer || (collegeReviewer && x.Student!.AdministrativeClass!.Major!.CollegeId == current.CollegeId)) &&
|
||||
x.Status == ComprehensiveAssessmentDeclarationStatus.CounselorApproved));
|
||||
}
|
||||
|
||||
private IQueryable<ComprehensiveAssessmentAppeal> ApplyAppealScope(IQueryable<ComprehensiveAssessmentAppeal> query)
|
||||
{
|
||||
var current = currentUserDataScope.Current;
|
||||
|
||||
@@ -516,7 +516,7 @@ public sealed class PhysicalFitnessController(AppDbContext db, ICurrentUserDataS
|
||||
private IQueryable<Student> ApplyStudentScope(IQueryable<Student> source)
|
||||
{
|
||||
var current = scope.Current;
|
||||
if (current.Scope == DataScope.All) return source;
|
||||
if (current.IsInRole(SystemRoles.PhysicalEducationAdmin) || current.Scope == DataScope.All) return source;
|
||||
if (current.Scope == DataScope.College)
|
||||
return source.Where(x => x.AdministrativeClass!.Major!.CollegeId == current.RestrictedCollegeId);
|
||||
if (current.Scope == DataScope.Class)
|
||||
|
||||
@@ -60,6 +60,9 @@ public sealed class CurrentUserDataScope(IHttpContextAccessor httpContextAccesso
|
||||
|
||||
public static class EffectiveDataScopeResolver
|
||||
{
|
||||
// Physical education administrators have school-wide scope only in the
|
||||
// physical-fitness domain, not in unrelated academic or student data.
|
||||
public static DataScope Resolve(IEnumerable<string> roles) =>
|
||||
RolePermissionCatalog.ResolveDataScope(roles);
|
||||
RolePermissionCatalog.ResolveDataScope(roles.Where(role =>
|
||||
!string.Equals(role, SystemRoles.PhysicalEducationAdmin, StringComparison.OrdinalIgnoreCase)));
|
||||
}
|
||||
Loaded 3 of 11 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user