Display exercices when theme is not locked, but not flags
This commit is contained in:
parent
d8462cf58e
commit
375f1da071
1 changed files with 154 additions and 141 deletions
|
@ -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,173 +220,175 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
||||||
|
|
||||||
// Expose exercice flags
|
// Expose exercice flags
|
||||||
|
|
||||||
justifiedMCQ := map[int]myTeamFlag{}
|
if !e.Disabled {
|
||||||
|
justifiedMCQ := map[int]myTeamFlag{}
|
||||||
|
|
||||||
if labels, err := e.GetFlagLabels(); err != nil {
|
if labels, err := e.GetFlagLabels(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
for _, l := range labels {
|
for _, l := range labels {
|
||||||
if !DisplayAllFlags && t != nil && !t.CanSeeFlag(l) {
|
if !DisplayAllFlags && t != nil && !t.CanSeeFlag(l) {
|
||||||
// Dependancy missing, skip the flag for now
|
// Dependancy missing, skip the flag for now
|
||||||
continue
|
continue
|
||||||
}
|
|
||||||
|
|
||||||
exercice.Flags = append(exercice.Flags, myTeamFlag{
|
|
||||||
order: l.Order,
|
|
||||||
Label: l.Label,
|
|
||||||
Variant: l.Variant,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if flags, err := e.GetFlagKeys(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
for _, k := range flags {
|
|
||||||
if !strings.HasPrefix(k.Type, "label") {
|
|
||||||
exercice.NbFlags += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if !DisplayAllFlags && t != nil && !t.CanSeeFlag(k) {
|
|
||||||
// Dependancy missing, skip the flag for now
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
flag := myTeamFlag{
|
|
||||||
Id: k.Id,
|
|
||||||
Type: k.Type,
|
|
||||||
order: k.Order,
|
|
||||||
Help: k.Help,
|
|
||||||
Unit: k.Unit,
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasPrefix(flag.Type, "number") {
|
|
||||||
flag.Min, flag.Max, flag.Step, err = AnalyzeNumberFlag(flag.Type)
|
|
||||||
flag.Type = "number"
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exercice.Flags = append(exercice.Flags, myTeamFlag{
|
||||||
|
order: l.Order,
|
||||||
|
Label: l.Label,
|
||||||
|
Variant: l.Variant,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieve solved state or solution for public iface
|
if flags, err := e.GetFlagKeys(); err != nil {
|
||||||
if t == nil {
|
return nil, err
|
||||||
flag.IgnoreCase = k.IgnoreCase
|
} else {
|
||||||
flag.ValidatorRe = k.ValidatorRegexp
|
for _, k := range flags {
|
||||||
flag.Soluce = hex.EncodeToString(k.Checksum)
|
if !strings.HasPrefix(k.Type, "label") {
|
||||||
} else if PartialValidation {
|
exercice.NbFlags += 1
|
||||||
flag.Solved = t.HasPartiallySolved(k)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
flag.Multiline = k.Multiline
|
if !DisplayAllFlags && t != nil && !t.CanSeeFlag(k) {
|
||||||
flag.BonusGain = int64(float64(k.BonusGain) * GlobalScoreCoefficient)
|
// Dependancy missing, skip the flag for now
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
var fl FlagMCQLabel
|
flag := myTeamFlag{
|
||||||
if fl, err = k.GetMCQJustification(); err == nil {
|
Id: k.Id,
|
||||||
k.Label = fl.Label
|
Type: k.Type,
|
||||||
}
|
order: k.Order,
|
||||||
|
Help: k.Help,
|
||||||
|
Unit: k.Unit,
|
||||||
|
}
|
||||||
|
|
||||||
// Treat array flags
|
if strings.HasPrefix(flag.Type, "number") {
|
||||||
flag.Label, flag.Separator, flag.IgnoreOrder, flag.NbLines = k.AnalyzeFlagLabel()
|
flag.Min, flag.Max, flag.Step, err = AnalyzeNumberFlag(flag.Type)
|
||||||
|
flag.Type = "number"
|
||||||
// Fill more information if the flag is displaied
|
if err != nil {
|
||||||
if flag.Solved == nil {
|
return nil, err
|
||||||
flag.Placeholder = k.Placeholder
|
|
||||||
if choices, err := k.GetChoices(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else if t == nil || WChoiceCoefficient < 0 || k.ChoicesCost == 0 || t.SeeChoices(k) {
|
|
||||||
flag.Choices = map[string]interface{}{}
|
|
||||||
for _, c := range choices {
|
|
||||||
flag.Choices[c.Value] = c.Label
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
flag.ChoicesCost = int64(float64(k.ChoicesCost) * GlobalScoreCoefficient)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Append to corresponding flags' map
|
// Retrieve solved state or solution for public iface
|
||||||
if fl.IdChoice != 0 {
|
if t == nil {
|
||||||
justifiedMCQ[fl.IdChoice] = flag
|
flag.IgnoreCase = k.IgnoreCase
|
||||||
} else {
|
flag.ValidatorRe = k.ValidatorRegexp
|
||||||
exercice.Flags = append(exercice.Flags, flag)
|
flag.Soluce = hex.EncodeToString(k.Checksum)
|
||||||
|
} else if PartialValidation {
|
||||||
|
flag.Solved = t.HasPartiallySolved(k)
|
||||||
|
}
|
||||||
|
|
||||||
|
flag.Multiline = k.Multiline
|
||||||
|
flag.BonusGain = int64(float64(k.BonusGain) * GlobalScoreCoefficient)
|
||||||
|
|
||||||
|
var fl FlagMCQLabel
|
||||||
|
if fl, err = k.GetMCQJustification(); err == nil {
|
||||||
|
k.Label = fl.Label
|
||||||
|
}
|
||||||
|
|
||||||
|
// Treat array flags
|
||||||
|
flag.Label, flag.Separator, flag.IgnoreOrder, flag.NbLines = k.AnalyzeFlagLabel()
|
||||||
|
|
||||||
|
// Fill more information if the flag is displaied
|
||||||
|
if flag.Solved == nil {
|
||||||
|
flag.Placeholder = k.Placeholder
|
||||||
|
if choices, err := k.GetChoices(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if t == nil || WChoiceCoefficient < 0 || k.ChoicesCost == 0 || t.SeeChoices(k) {
|
||||||
|
flag.Choices = map[string]interface{}{}
|
||||||
|
for _, c := range choices {
|
||||||
|
flag.Choices[c.Value] = c.Label
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
flag.ChoicesCost = int64(float64(k.ChoicesCost) * GlobalScoreCoefficient)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append to corresponding flags' map
|
||||||
|
if fl.IdChoice != 0 {
|
||||||
|
justifiedMCQ[fl.IdChoice] = flag
|
||||||
|
} else {
|
||||||
|
exercice.Flags = append(exercice.Flags, flag)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if mcqs, err := e.GetMCQ(); err != nil {
|
if mcqs, err := e.GetMCQ(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
for _, mcq := range mcqs {
|
for _, mcq := range mcqs {
|
||||||
exercice.NbFlags += 1
|
exercice.NbFlags += 1
|
||||||
|
|
||||||
if !DisplayAllFlags && t != nil && !t.CanSeeFlag(mcq) {
|
if !DisplayAllFlags && t != nil && !t.CanSeeFlag(mcq) {
|
||||||
// Dependancy missing, skip the flag for now
|
// Dependancy missing, skip the flag for now
|
||||||
continue
|
continue
|
||||||
}
|
|
||||||
|
|
||||||
m := myTeamFlag{
|
|
||||||
Id: mcq.Id,
|
|
||||||
Type: "mcq",
|
|
||||||
order: mcq.Order,
|
|
||||||
Label: mcq.Title,
|
|
||||||
Choices: map[string]interface{}{},
|
|
||||||
}
|
|
||||||
|
|
||||||
soluce := ""
|
|
||||||
fullySolved := true
|
|
||||||
if t != nil {
|
|
||||||
m.PSolved = t.HasPartiallySolved(mcq)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, e := range mcq.Entries {
|
|
||||||
if e.Response {
|
|
||||||
soluce += "t"
|
|
||||||
} else {
|
|
||||||
soluce += "f"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := justifiedMCQ[e.Id]; ok {
|
m := myTeamFlag{
|
||||||
m.Justify = true
|
Id: mcq.Id,
|
||||||
|
Type: "mcq",
|
||||||
|
order: mcq.Order,
|
||||||
|
Label: mcq.Title,
|
||||||
|
Choices: map[string]interface{}{},
|
||||||
|
}
|
||||||
|
|
||||||
if m.PSolved != nil || v.Solved != nil {
|
soluce := ""
|
||||||
jc := myTeamMCQJustifiedChoice{
|
fullySolved := true
|
||||||
Label: e.Label,
|
if t != nil {
|
||||||
Value: v.Solved != nil,
|
m.PSolved = t.HasPartiallySolved(mcq)
|
||||||
Justification: v,
|
}
|
||||||
|
|
||||||
|
for _, e := range mcq.Entries {
|
||||||
|
if e.Response {
|
||||||
|
soluce += "t"
|
||||||
|
} else {
|
||||||
|
soluce += "f"
|
||||||
|
}
|
||||||
|
|
||||||
|
if v, ok := justifiedMCQ[e.Id]; ok {
|
||||||
|
m.Justify = true
|
||||||
|
|
||||||
|
if m.PSolved != nil || v.Solved != nil {
|
||||||
|
jc := myTeamMCQJustifiedChoice{
|
||||||
|
Label: e.Label,
|
||||||
|
Value: v.Solved != nil,
|
||||||
|
Justification: v,
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.Solved == nil {
|
||||||
|
fullySolved = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if PartialValidation && m.PSolved != nil {
|
||||||
|
jc.Value = e.Response
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Choices[strconv.Itoa(e.Id)] = jc
|
||||||
|
} else {
|
||||||
|
m.Choices[strconv.Itoa(e.Id)] = e.Label
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.Solved == nil {
|
|
||||||
fullySolved = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if PartialValidation && m.PSolved != nil {
|
|
||||||
jc.Value = e.Response
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Choices[strconv.Itoa(e.Id)] = jc
|
|
||||||
} else {
|
} else {
|
||||||
m.Choices[strconv.Itoa(e.Id)] = e.Label
|
m.Choices[strconv.Itoa(e.Id)] = e.Label
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
m.Choices[strconv.Itoa(e.Id)] = e.Label
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if t == nil {
|
if t == nil {
|
||||||
h, _ := ComputeHashedFlag([]byte(soluce), false, false, nil, false)
|
h, _ := ComputeHashedFlag([]byte(soluce), false, false, nil, false)
|
||||||
m.Soluce = hex.EncodeToString(h[:])
|
m.Soluce = hex.EncodeToString(h[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
if fullySolved {
|
if fullySolved {
|
||||||
m.Solved = m.PSolved
|
m.Solved = m.PSolved
|
||||||
m.PSolved = nil
|
m.PSolved = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
exercice.Flags = append(exercice.Flags, m)
|
exercice.Flags = append(exercice.Flags, m)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
||||||
|
|
Reference in a new issue