Display exercices when theme is not locked, but not flags

This commit is contained in:
nemunaire 2023-04-06 15:41:14 +02:00
parent d8462cf58e
commit 375f1da071

View file

@ -116,13 +116,24 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
} }
} }
// Retrieve themes
themes, err := GetThemes()
if err != nil {
return ret, err
}
mapthemes := map[int64]*Theme{}
for _, theme := range themes {
mapthemes[theme.Id] = theme
}
// Fill exercices, only if the challenge is started // Fill exercices, only if the challenge is started
ret.Exercices = map[string]myTeamExercice{} ret.Exercices = map[string]myTeamExercice{}
if exos, err := GetDiscountedExercices(); err != nil { if exos, err := GetDiscountedExercices(); err != nil {
return ret, err return ret, err
} else if started { } else if started {
for _, e := range exos { for _, e := range exos {
if t == nil || (!e.Disabled && t.HasAccess(e)) { if t == nil || ((!e.Disabled || !mapthemes[e.IdTheme].Locked) && t.HasAccess(e)) {
exercice := myTeamExercice{} exercice := myTeamExercice{}
exercice.Disabled = e.Disabled exercice.Disabled = e.Disabled
exercice.WIP = e.WIP exercice.WIP = e.WIP
@ -209,6 +220,7 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
// Expose exercice flags // Expose exercice flags
if !e.Disabled {
justifiedMCQ := map[int]myTeamFlag{} justifiedMCQ := map[int]myTeamFlag{}
if labels, err := e.GetFlagLabels(); err != nil { if labels, err := e.GetFlagLabels(); err != nil {
@ -376,6 +388,7 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
// Sort flags by order // Sort flags by order
sort.Sort(ByOrder(exercice.Flags)) sort.Sort(ByOrder(exercice.Flags))
}
// Hash table ordered by exercice Id // Hash table ordered by exercice Id
ret.Exercices[fmt.Sprintf("%d", e.Id)] = exercice ret.Exercices[fmt.Sprintf("%d", e.Id)] = exercice