admin: New button to delete tries for a flag
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b409fa6806
commit
08a31898df
7 changed files with 99 additions and 4 deletions
|
|
@ -16,6 +16,7 @@ type Flag interface {
|
|||
FoundBy(t *Team) error
|
||||
NbTries() (int64, error)
|
||||
TeamsOnIt() ([]int64, error)
|
||||
DeleteTries() error
|
||||
}
|
||||
|
||||
// GetFlag returns a list of flags comming with the challenge.
|
||||
|
|
|
|||
|
|
@ -255,6 +255,29 @@ func (k *FlagKey) TeamsOnIt() ([]int64, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (k *FlagKey) DeleteTries() error {
|
||||
if rows, err := DBQuery("SELECT id_try FROM exercice_tries_flags WHERE id_flag = ?", k.Id); err != nil {
|
||||
return err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var idtry int64
|
||||
err = rows.Scan(&idtry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = DBExec("DELETE FROM exercice_tries WHERE id_try = ?", idtry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// AddFlagKey creates and fills a new struct Flag, from a hashed flag, and registers it into the database.
|
||||
func (k *FlagKey) Create(e *Exercice) (Flag, error) {
|
||||
// Check the regexp compile
|
||||
|
|
|
|||
|
|
@ -79,6 +79,10 @@ func (k *FlagLabel) TeamsOnIt() ([]int64, error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func (k *FlagLabel) DeleteTries() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddFlagLabel creates and fills a new struct Flag and registers it into the database.
|
||||
func (k *FlagLabel) Create(e *Exercice) (Flag, error) {
|
||||
if res, err := DBExec("INSERT INTO exercice_flag_labels (id_exercice, ordre, label, variant) VALUES (?, ?, ?, ?)", e.Id, k.Order, k.Label, k.Variant); err != nil {
|
||||
|
|
|
|||
|
|
@ -161,6 +161,29 @@ func (m *MCQ) TeamsOnIt() ([]int64, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (m *MCQ) DeleteTries() error {
|
||||
if rows, err := DBQuery("SELECT id_try FROM exercice_tries_mcq WHERE id_mcq = ?", m.Id); err != nil {
|
||||
return err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var idtry int64
|
||||
err = rows.Scan(&idtry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = DBExec("DELETE FROM exercice_tries WHERE id_try = ?", idtry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Create registers a MCQ into the database and recursively add its entries.
|
||||
func (m *MCQ) Create(e *Exercice) (Flag, error) {
|
||||
if res, err := DBExec("INSERT INTO exercice_mcq (id_exercice, ordre, title) VALUES (?, ?, ?)", e.Id, m.Order, m.Title); err != nil {
|
||||
|
|
|
|||
Reference in a new issue