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
|
||||
ret.Exercices = map[string]myTeamExercice{}
|
||||
if exos, err := GetDiscountedExercices(); err != nil {
|
||||
return ret, err
|
||||
} else if started {
|
||||
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.Disabled = e.Disabled
|
||||
exercice.WIP = e.WIP
|
||||
|
@ -209,173 +220,175 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
|
||||
// Expose exercice flags
|
||||
|
||||
justifiedMCQ := map[int]myTeamFlag{}
|
||||
if !e.Disabled {
|
||||
justifiedMCQ := map[int]myTeamFlag{}
|
||||
|
||||
if labels, err := e.GetFlagLabels(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
for _, l := range labels {
|
||||
if !DisplayAllFlags && t != nil && !t.CanSeeFlag(l) {
|
||||
// Dependancy missing, skip the flag for now
|
||||
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
|
||||
if labels, err := e.GetFlagLabels(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
for _, l := range labels {
|
||||
if !DisplayAllFlags && t != nil && !t.CanSeeFlag(l) {
|
||||
// Dependancy missing, skip the flag for now
|
||||
continue
|
||||
}
|
||||
|
||||
exercice.Flags = append(exercice.Flags, myTeamFlag{
|
||||
order: l.Order,
|
||||
Label: l.Label,
|
||||
Variant: l.Variant,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve solved state or solution for public iface
|
||||
if t == nil {
|
||||
flag.IgnoreCase = k.IgnoreCase
|
||||
flag.ValidatorRe = k.ValidatorRegexp
|
||||
flag.Soluce = hex.EncodeToString(k.Checksum)
|
||||
} else if PartialValidation {
|
||||
flag.Solved = t.HasPartiallySolved(k)
|
||||
}
|
||||
if flags, err := e.GetFlagKeys(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
for _, k := range flags {
|
||||
if !strings.HasPrefix(k.Type, "label") {
|
||||
exercice.NbFlags += 1
|
||||
}
|
||||
|
||||
flag.Multiline = k.Multiline
|
||||
flag.BonusGain = int64(float64(k.BonusGain) * GlobalScoreCoefficient)
|
||||
if !DisplayAllFlags && t != nil && !t.CanSeeFlag(k) {
|
||||
// Dependancy missing, skip the flag for now
|
||||
continue
|
||||
}
|
||||
|
||||
var fl FlagMCQLabel
|
||||
if fl, err = k.GetMCQJustification(); err == nil {
|
||||
k.Label = fl.Label
|
||||
}
|
||||
flag := myTeamFlag{
|
||||
Id: k.Id,
|
||||
Type: k.Type,
|
||||
order: k.Order,
|
||||
Help: k.Help,
|
||||
Unit: k.Unit,
|
||||
}
|
||||
|
||||
// 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
|
||||
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
|
||||
}
|
||||
} 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)
|
||||
// Retrieve solved state or solution for public iface
|
||||
if t == nil {
|
||||
flag.IgnoreCase = k.IgnoreCase
|
||||
flag.ValidatorRe = k.ValidatorRegexp
|
||||
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 {
|
||||
return nil, err
|
||||
} else {
|
||||
for _, mcq := range mcqs {
|
||||
exercice.NbFlags += 1
|
||||
if mcqs, err := e.GetMCQ(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
for _, mcq := range mcqs {
|
||||
exercice.NbFlags += 1
|
||||
|
||||
if !DisplayAllFlags && t != nil && !t.CanSeeFlag(mcq) {
|
||||
// Dependancy missing, skip the flag for now
|
||||
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 !DisplayAllFlags && t != nil && !t.CanSeeFlag(mcq) {
|
||||
// Dependancy missing, skip the flag for now
|
||||
continue
|
||||
}
|
||||
|
||||
if v, ok := justifiedMCQ[e.Id]; ok {
|
||||
m.Justify = true
|
||||
m := myTeamFlag{
|
||||
Id: mcq.Id,
|
||||
Type: "mcq",
|
||||
order: mcq.Order,
|
||||
Label: mcq.Title,
|
||||
Choices: map[string]interface{}{},
|
||||
}
|
||||
|
||||
if m.PSolved != nil || v.Solved != nil {
|
||||
jc := myTeamMCQJustifiedChoice{
|
||||
Label: e.Label,
|
||||
Value: v.Solved != nil,
|
||||
Justification: v,
|
||||
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.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 {
|
||||
m.Choices[strconv.Itoa(e.Id)] = e.Label
|
||||
}
|
||||
} else {
|
||||
m.Choices[strconv.Itoa(e.Id)] = e.Label
|
||||
}
|
||||
}
|
||||
|
||||
if t == nil {
|
||||
h, _ := ComputeHashedFlag([]byte(soluce), false, false, nil, false)
|
||||
m.Soluce = hex.EncodeToString(h[:])
|
||||
}
|
||||
if t == nil {
|
||||
h, _ := ComputeHashedFlag([]byte(soluce), false, false, nil, false)
|
||||
m.Soluce = hex.EncodeToString(h[:])
|
||||
}
|
||||
|
||||
if fullySolved {
|
||||
m.Solved = m.PSolved
|
||||
m.PSolved = nil
|
||||
}
|
||||
if fullySolved {
|
||||
m.Solved = m.PSolved
|
||||
m.PSolved = nil
|
||||
}
|
||||
|
||||
exercice.Flags = append(exercice.Flags, m)
|
||||
exercice.Flags = append(exercice.Flags, m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort flags by order
|
||||
sort.Sort(ByOrder(exercice.Flags))
|
||||
// Sort flags by order
|
||||
sort.Sort(ByOrder(exercice.Flags))
|
||||
}
|
||||
|
||||
// Hash table ordered by exercice Id
|
||||
ret.Exercices[fmt.Sprintf("%d", e.Id)] = exercice
|
||||
|
|
Reference in a new issue