Skip to content

Commit 49d82e4

Browse files
committed
fix: update_exercise_assignments's handling of Closed/Open status
Now, removing an exercise/student/future_students from an assignment does not yield an exo with some GloballyInconsistent status anymore. Close ocaml-sf#558
1 parent c18da2a commit 49d82e4

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/state/learnocaml_data.ml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -633,24 +633,31 @@ module Exercise = struct
633633
SSet.fold (fun ex_id acc ->
634634
let st = get_status_t ex_id in
635635
let assg = st.assignments in
636+
let global_status = is_open_or_assigned_globally assg in
636637
let old_default = assg.default in
637638
let new_default =
638639
if default then status
639-
else if default0 then Closed
640+
else if default0 (* the future_students flag was removed *)
641+
then match global_status with
642+
| GloballyOpenOrAssigned | GloballyOpen -> Open
643+
| _ -> Closed
640644
else old_default
641645
in
642646
let add tk st tmap =
643-
if st = new_default then tmap
647+
if st = new_default then tmap (* normalize the token map *)
644648
else Token.Map.add tk st tmap
645649
in
646650
let token_map =
647651
Token.Map.fold (fun tk _ acc ->
648652
if Token.Set.mem tk students then
649653
if default then acc
650654
else Token.Map.add tk status acc
651-
else if Token.Set.mem tk students0 then
652-
if default then Token.Map.add tk Closed acc
653-
else Token.Map.remove tk acc
655+
else if Token.Set.mem tk students0 then (* the student was unassigned *)
656+
if default
657+
then match global_status with
658+
| GloballyOpenOrAssigned | GloballyOpen -> Token.Map.add tk Open acc
659+
| _ -> Token.Map.add tk Closed acc
660+
else (* Token.Map.remove tk (unneeded call) *) acc
654661
else add tk (get_status tk assg) acc)
655662
students_map Token.Map.empty
656663
in
@@ -668,7 +675,11 @@ module Exercise = struct
668675
let st = get_status_t ex_id in
669676
let assg = st.assignments in
670677
let dft_status =
671-
if default0 then Closed else default_assignment assg
678+
if default0 (* the old default was Assigned(_, _) *)
679+
then match is_open_or_assigned_globally assg with
680+
| GloballyOpenOrAssigned | GloballyOpen -> Open
681+
| _ -> Closed
682+
else default_assignment assg
672683
in
673684
let token_map =
674685
Token.Set.fold Token.Map.remove students0 assg.token_map

0 commit comments

Comments
 (0)