diff --git a/admin/api/exercice.go b/admin/api/exercice.go index 2a1fb275..a1ab5153 100644 --- a/admin/api/exercice.go +++ b/admin/api/exercice.go @@ -332,7 +332,15 @@ func updateExerciceFlag(flag fic.FlagKey, exercice fic.Exercice, body []byte) (i flag.Help = uk.Help flag.IgnoreCase = uk.IgnoreCase - flag.Checksum = uk.Value + if len(uk.Flag) > 0 { + var err error + flag.Checksum, err = flag.ComputeChecksum([]byte(uk.Flag)) + if err != nil { + return nil, err + } + } else { + flag.Checksum = uk.Value + } flag.ChoicesCost = uk.ChoicesCost if uk.ValidatorRe != nil && len(*uk.ValidatorRe) > 0 { diff --git a/admin/static/js/app.js b/admin/static/js/app.js index f9d06cc5..61967cae 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -1341,6 +1341,10 @@ angular.module("FICApp") .controller("ExerciceFlagsController", function($scope, ExerciceFlag, $routeParams, $rootScope, $http) { $scope.flags = ExerciceFlag.query({ exerciceId: $routeParams.exerciceId }); + $scope.changeValue = function(flag) { + flag.value = undefined; + flag.show_raw = true; + } $scope.addFlag = function() { $scope.flags.push(new ExerciceFlag()); } diff --git a/admin/static/views/exercice.html b/admin/static/views/exercice.html index e9438d29..ae4fd3c8 100644 --- a/admin/static/views/exercice.html +++ b/admin/static/views/exercice.html @@ -126,8 +126,13 @@
- - +
+ +
+ +
+
+
@@ -138,8 +143,8 @@
-
- +
+
diff --git a/libfic/flag_key.go b/libfic/flag_key.go index 08e22737..c31c8ac7 100644 --- a/libfic/flag_key.go +++ b/libfic/flag_key.go @@ -119,6 +119,28 @@ func (e Exercice) AddFlagKey(name string, help string, ignorecase bool, validato } } +// SetChecksumFromValue . +func (k FlagKey) ComputeChecksum(val []byte) (cksum []byte, err error) { + if k.IgnoreCase { + val = bytes.ToLower(val) + } + + // Check that raw value passes through the regexp + if k.ValidatorRegexp != nil { + if val, err = ExecValidatorRegexp(*k.ValidatorRegexp, val); err != nil { + return + } + } + + // Check that the value is not empty + if len(val) == 0 { + err = errors.New("Empty flag after applying filters") + } + + hash := getHashedFlag(val) + return hash[:], err +} + // Update applies modifications back to the database. func (k FlagKey) Update() (int64, error) { if k.ValidatorRegexp != nil { @@ -220,21 +242,10 @@ func (k FlagKey) Check(v interface{}) int { val = va } - if k.IgnoreCase { - val = bytes.ToLower(val) - } - - // Check that raw value passes through the regexp - if k.ValidatorRegexp != nil { - val, _ = ExecValidatorRegexp(*k.ValidatorRegexp, val) - } - - // Check that the value is not empty - if len(val) == 0 { + hash, err := k.ComputeChecksum(val) + if err != nil { return 1 } - - hash := getHashedFlag(val) if len(k.Checksum) != len(hash) { return 1 }