diff --git a/frontend/static/js/challenge.js b/frontend/static/js/challenge.js index 7e671d2c..c7e20c30 100644 --- a/frontend/static/js/challenge.js +++ b/frontend/static/js/challenge.js @@ -256,8 +256,12 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) angular.forEach(mcq["choices"], function(choice,cid) { this[cid] = { label: choice, - value: false + value: mcq["checks_solved"] !== undefined && mcq["checks_solved"][cid] !== undefined && mcq["checks_solved"][cid] > 0 }; + if (mcq["checks_solved"] !== undefined) { + this[cid].disabled = true; + this[cid].solved = mcq["checks_solved"][cid] !== undefined && mcq["checks_solved"][cid] >= 2; + } }, mcq["choices"]); }, $scope.mcqs); } @@ -265,12 +269,11 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) waitMy(); $scope.ssubmit = function() { - var resp = {} + var resp = {"flags":{}} var check = undefined if ($scope.my.exercices[$rootScope.current_exercice].flags && Object.keys($scope.my.exercices[$rootScope.current_exercice].flags).length) { - resp["flags"] = {}; angular.forEach($scope.my.exercices[$rootScope.current_exercice].flags, function(flag,kid) { if (flag.found == null) { if (flag.soluce !== undefined) { @@ -291,6 +294,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) var soluce = ""; resp["mcqs"] = {}; angular.forEach($scope.my.exercices[$rootScope.current_exercice].mcqs, function(mcq) { + var nid = 0; if (mcq.solved == null) { angular.forEach(mcq.choices, function(choice, cid) { if (mcq.soluce !== undefined) { @@ -298,7 +302,15 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) soluce += choice.value ? "t" : "f"; } else { - if (choice.value) resp["mcqs"][cid] = choice.value; + if (choice.value) { + resp["mcqs"][cid] = choice.value; + if (mcq.justify !== undefined) { + if (choice.justify) + resp["flags"][mcq.justify[nid++]] = choice.justify; + else if (!choice.solved) + nid++; + } + } } }); if (mcq.soluce !== undefined) { diff --git a/frontend/static/views/defi.html b/frontend/static/views/defi.html index 2d0d6f47..c893db2e 100644 --- a/frontend/static/views/defi.html +++ b/frontend/static/views/defi.html @@ -92,8 +92,10 @@

{{ mcq.title }}

- + + +

diff --git a/libfic/exercice.go b/libfic/exercice.go index bb05c879..7019a121 100644 --- a/libfic/exercice.go +++ b/libfic/exercice.go @@ -298,7 +298,7 @@ func (e Exercice) CheckResponse(cksum []byte, respflags map[int64]string, respmc // Check flags for _, flag := range flags { - if res, ok := respflags[flag.Id]; !ok { + if res, ok := respflags[flag.Id]; !ok && (!PartialValidation || t.HasPartiallySolved(flag) == nil) { valid = false } else if !flag.Check([]byte(res)) { if !PartialValidation || t.HasPartiallySolved(flag) == nil { diff --git a/libfic/team_my.go b/libfic/team_my.go index 3d4fa78c..18dcb315 100644 --- a/libfic/team_my.go +++ b/libfic/team_my.go @@ -23,9 +23,10 @@ type myTeamHint struct { } type myTeamMCQ struct { Title string `json:"title"` - Justify bool `json:"justify,omitempty"` + Justify []int64 `json:"justify,omitempty"` Choices map[int64]string `json:"choices,omitempty"` Solved *time.Time `json:"solved,omitempty"` + PSolved map[int64]int `json:"checks_solved,omitempty"` Soluce string `json:"soluce,omitempty"` } type myTeamFlag struct { @@ -155,7 +156,8 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) { // Expose exercice flags - var justifiedMCQ map[string][]byte + justifiedMCQ := map[string][]byte{} + justifiedMCQ_ids := map[string]int64{} exercice.Flags = map[int64]myTeamFlag{} if flags, err := e.GetFlags(); err != nil { @@ -166,6 +168,9 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) { if k.Label[0] == '%' { justifiedMCQ[k.Label[1:]] = k.Checksum + if t == nil || t.HasPartiallySolved(k) == nil { + justifiedMCQ_ids[k.Label[1:]] = k.Id + } continue } else if t == nil { flag.Soluce = hex.EncodeToString(k.Checksum) @@ -205,6 +210,9 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) { } soluce := "" + solved_justify := true + var nb_gen_justify_id int64 + var max_justify_id int64 for _, e := range mcq.Entries { m.Choices[e.Id] = e.Label @@ -214,15 +222,46 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) { soluce += "f" } if v, ok := justifiedMCQ[m.Title + "%" + e.Label]; ok { - m.Justify = true + if m.Justify == nil { + m.Justify = []int64{} + } + if t == nil { soluce += hex.EncodeToString(v) } + + if v, ok := justifiedMCQ_ids[m.Title + "%" + e.Label]; ok { + solved_justify = false + m.Justify = append(m.Justify, v) + if v > max_justify_id { + max_justify_id = v + } + } + } else { + nb_gen_justify_id += 1 } } + // Fill the rest of the array with factice values in order to hide number of valid choices + for i := int64(0); i < nb_gen_justify_id; i++ { + m.Justify = append(m.Justify, max_justify_id + 1 + i) + } + if t != nil { - m.Solved = t.HasPartiallyRespond(mcq) + if solved_justify { + m.Solved = t.HasPartiallyRespond(mcq) + } else if PartialValidation && t.HasPartiallyRespond(mcq) != nil { + m.PSolved = map[int64]int{} + for _, e := range mcq.Entries { + if _, ok := justifiedMCQ[m.Title + "%" + e.Label]; ok { + if _, ok := justifiedMCQ_ids[m.Title + "%" + e.Label]; !ok { + m.PSolved[e.Id] = 2 + } else if e.Response { + m.PSolved[e.Id] = 1 + } + } + } + } } else { h := getHashedFlag([]byte(soluce)) m.Soluce = hex.EncodeToString(h[:])