From 47ba134b55d019599c8078eb4006479d1008f690 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Thu, 16 Jan 2020 15:33:28 +0100 Subject: [PATCH] Implement flag type 'text': this is like keys, but on multiple lines --- admin/api/exercice.go | 3 ++- admin/static/views/exercice.html | 4 ++++ admin/sync/exercice_keys.go | 9 ++++++--- frontend/static/js/challenge.js | 3 ++- frontend/submissions.go | 2 +- libfic/db.go | 1 + libfic/file.go | 2 +- libfic/flag_key.go | 17 ++++++++++------- libfic/team_my.go | 3 +++ 9 files changed, 30 insertions(+), 14 deletions(-) diff --git a/admin/api/exercice.go b/admin/api/exercice.go index a1a24b03..0e85a77e 100644 --- a/admin/api/exercice.go +++ b/admin/api/exercice.go @@ -325,6 +325,7 @@ type uploadedFlag struct { Label string Help string IgnoreCase bool + Multiline bool ValidatorRe *string `json:"validator_regexp"` Flag string Value []byte @@ -346,7 +347,7 @@ func createExerciceFlag(exercice fic.Exercice, body []byte) (interface{}, error) vre = uk.ValidatorRe } - return exercice.AddRawFlagKey(uk.Label, uk.Help, uk.IgnoreCase, vre, []byte(uk.Flag), uk.ChoicesCost) + return exercice.AddRawFlagKey(uk.Label, uk.Help, uk.IgnoreCase, uk.Multiline, vre, []byte(uk.Flag), uk.ChoicesCost) } func showExerciceFlag(flag fic.FlagKey, _ fic.Exercice, body []byte) (interface{}, error) { diff --git a/admin/static/views/exercice.html b/admin/static/views/exercice.html index 52cef198..d369d615 100644 --- a/admin/static/views/exercice.html +++ b/admin/static/views/exercice.html @@ -146,6 +146,10 @@ +
+ + +
diff --git a/admin/sync/exercice_keys.go b/admin/sync/exercice_keys.go index c2f2c4b3..2090b2d9 100644 --- a/admin/sync/exercice_keys.go +++ b/admin/sync/exercice_keys.go @@ -116,7 +116,7 @@ func buildKeyFlag(exercice fic.Exercice, flag ExerciceFlag, flagline int, defaul } flag.Label = prep + flag.Label - if !isFullGraphic(raw) { + if (flag.Type == "text" && !isFullGraphic(strings.Replace(raw, "\n", "", -1))) || (flag.Type != "text" && !isFullGraphic(raw)) { errs = append(errs, fmt.Sprintf("%q: WARNING flag #%d: non-printable characters in flag, is this really expected?", path.Base(exercice.Path), flagline)) } @@ -130,6 +130,7 @@ func buildKeyFlag(exercice fic.Exercice, flag ExerciceFlag, flagline int, defaul Label: flag.Label, Help: flag.Help, IgnoreCase: !flag.CaseSensitive, + Multiline: flag.Type == "text", ValidatorRegexp: validatorRegexp(flag.ValidatorRe), Checksum: hashedFlag[:], ChoicesCost: flag.ChoicesCost, @@ -191,6 +192,8 @@ func buildExerciceFlag(i Importer, exercice fic.Exercice, flag ExerciceFlag, nli flag.Type = "key" case "key": flag.Type = "key" + case "text": + flag.Type = "text" case "vector": flag.Type = "vector" case "ucq": @@ -198,11 +201,11 @@ func buildExerciceFlag(i Importer, exercice fic.Exercice, flag ExerciceFlag, nli case "mcq": flag.Type = "mcq" default: - errs = append(errs, fmt.Sprintf("%q: flag #%d: invalid type of flag: should be 'key', 'mcq', 'ucq' or 'vector'.", path.Base(exercice.Path), nline+1)) + errs = append(errs, fmt.Sprintf("%q: flag #%d: invalid type of flag: should be 'key', 'text', 'mcq', 'ucq' or 'vector'.", path.Base(exercice.Path), nline+1)) return } - if flag.Type == "key" || flag.Type == "ucq" || flag.Type == "vector" { + if flag.Type == "key" || flag.Type == "text" || flag.Type == "ucq" || flag.Type == "vector" { addedFlag, choices, berrs := buildKeyFlag(exercice, flag, nline+1, "Flag") if len(berrs) > 0 { errs = append(errs, berrs...) diff --git a/frontend/static/js/challenge.js b/frontend/static/js/challenge.js index b0ccbed5..614cde60 100644 --- a/frontend/static/js/challenge.js +++ b/frontend/static/js/challenge.js @@ -125,7 +125,8 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
- + +