admin: add a button to edit the raw flag value instead of the checksum
This commit is contained in:
parent
b205409679
commit
eee2cd6a2f
4 changed files with 46 additions and 18 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue