diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 56ce3872..39de6692 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -1539,7 +1539,7 @@ angular.module("FICApp") }) .controller("ThemeController", function($scope, Theme, $routeParams, $location, $rootScope, $http) { $scope.theme = Theme.get({ themeId: $routeParams.themeId }); - $scope.fields = ["name", "urlid", "authors", "headline", "intro", "image", "partner_txt", "partner_href", "partner_img"]; + $scope.fields = ["name", "urlid", "authors", "headline", "intro", "image", "partner_txt", "partner_href", "partner_img"]; $scope.saveTheme = function() { if (this.theme.id) { @@ -1712,7 +1712,7 @@ angular.module("FICApp") }); }); $scope.exercices = Exercice.query(); - $scope.fields = ["title", "urlid", "statement", "headline", "overview", "finished", "depend", "gain", "coefficient", "videoURI", "resolution", "issue", "issuekind", "wip"]; + $scope.fields = ["title", "urlid", "disabled", "statement", "headline", "overview", "finished", "depend", "gain", "coefficient", "videoURI", "resolution", "issue", "issuekind", "wip"]; $scope.inSync = false; $scope.syncExo = function() { diff --git a/admin/static/views/exercice-list.html b/admin/static/views/exercice-list.html index 050bf57c..780c0b14 100644 --- a/admin/static/views/exercice-list.html +++ b/admin/static/views/exercice-list.html @@ -74,9 +74,10 @@
Édition de masse -
- -
+
+ + +
diff --git a/admin/static/views/exercice.html b/admin/static/views/exercice.html index 7b80e71a..e7b1ea4e 100644 --- a/admin/static/views/exercice.html +++ b/admin/static/views/exercice.html @@ -21,8 +21,8 @@
- - + + diff --git a/admin/static/views/theme.html b/admin/static/views/theme.html index bc03a3cc..d5e9dfc8 100644 --- a/admin/static/views/theme.html +++ b/admin/static/views/theme.html @@ -9,9 +9,10 @@
-
+
+ - +
diff --git a/backend/choices.go b/backend/choices.go index 3d1deab0..18facfc6 100644 --- a/backend/choices.go +++ b/backend/choices.go @@ -40,6 +40,8 @@ func treatWantChoices(pathname string, team *fic.Team) { log.Printf("%s [ERR] Unable to retrieve the flag's underlying exercice: %s\n", id, err) } else if !team.HasAccess(exercice) { log.Printf("%s [!!!] The team asks to display choices whereas it doesn't have access to the exercice\n", id) + } else if exercice.Disabled { + log.Println("[!!!] The team submits something for a disabled exercice") } else if err = team.DisplayChoices(flag); err != nil { log.Printf("%s [ERR] %s\n", id, err) } else { diff --git a/backend/hint.go b/backend/hint.go index f69c1759..a9e2c2ff 100644 --- a/backend/hint.go +++ b/backend/hint.go @@ -38,6 +38,8 @@ func treatOpeningHint(pathname string, team *fic.Team) { log.Printf("%s [ERR] Unable to retrieve the given hint: %s\n", id, err) } else if exercice, err := hint.GetExercice(); err != nil { log.Printf("%s [ERR] Unable to retrieve the hint's underlying exercice: %s\n", id, err) + } else if exercice.Disabled { + log.Println("[!!!] The team submits something for a disabled exercice") } else if !team.HasAccess(exercice) { log.Printf("%s [!!!] The team asks to open an hint whereas it doesn't have access to the exercice\n", id) } else if !team.CanSeeHint(hint) { diff --git a/backend/submission.go b/backend/submission.go index b7268ca1..f4172d0b 100644 --- a/backend/submission.go +++ b/backend/submission.go @@ -44,6 +44,12 @@ func treatSubmission(pathname string, team *fic.Team, exercice_id string) { return } + // Check the exercice is not disabled + if exercice.Disabled { + log.Println("[!!!] The team submits something for a disabled exercice") + return + } + // Check the team can access this exercice if !team.HasAccess(exercice) { log.Println("[!!!] The team submits something for an exercice it doesn't have access yet") diff --git a/libfic/db.go b/libfic/db.go index dcab471c..69e013fe 100644 --- a/libfic/db.go +++ b/libfic/db.go @@ -140,6 +140,7 @@ CREATE TABLE IF NOT EXISTS exercices( id_exercice INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, id_theme INTEGER NOT NULL, title VARCHAR(255) NOT NULL, + disabled BOOLEAN NOT NULL DEFAULT 0, headline TEXT NOT NULL, url_id VARCHAR(255) NOT NULL, path VARCHAR(191) NOT NULL UNIQUE, diff --git a/libfic/exercice.go b/libfic/exercice.go index 47080986..96d94bc5 100644 --- a/libfic/exercice.go +++ b/libfic/exercice.go @@ -24,6 +24,8 @@ type Exercice struct { IdTheme int64 `json:"id_theme"` Language string `json:"lang,omitempty"` Title string `json:"title"` + // Disabled indicates if the exercice is available to players now or not + Disabled bool `json:"disabled"` // WIP indicates if the exercice is in development or not WIP bool `json:"wip"` // URLid is used to reference the challenge from the URL path @@ -69,7 +71,7 @@ func (e *Exercice) AnalyzeTitle() { func getExercice(condition string, args ...interface{}) (*Exercice, error) { var e Exercice - if err := DBQueryRow("SELECT id_exercice, id_theme, title, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM exercices "+condition, args...).Scan(&e.Id, &e.IdTheme, &e.Title, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil { + if err := DBQueryRow("SELECT id_exercice, id_theme, title, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM exercices "+condition, args...).Scan(&e.Id, &e.IdTheme, &e.Title, &e.Disabled, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil { return nil, err } e.AnalyzeTitle() @@ -99,7 +101,7 @@ func (t *Theme) GetExerciceByPath(epath string) (*Exercice, error) { // GetExercices returns the list of all challenges present in the database. func GetExercices() ([]*Exercice, error) { - if rows, err := DBQuery("SELECT id_exercice, id_theme, title, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM exercices ORDER BY path ASC"); err != nil { + if rows, err := DBQuery("SELECT id_exercice, id_theme, title, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM exercices ORDER BY path ASC"); err != nil { return nil, err } else { defer rows.Close() @@ -107,7 +109,7 @@ func GetExercices() ([]*Exercice, error) { exos := []*Exercice{} for rows.Next() { e := &Exercice{} - if err := rows.Scan(&e.Id, &e.IdTheme, &e.Title, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil { + if err := rows.Scan(&e.Id, &e.IdTheme, &e.Title, &e.Disabled, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil { return nil, err } e.AnalyzeTitle() @@ -123,7 +125,7 @@ func GetExercices() ([]*Exercice, error) { // GetExercices returns the list of all challenges in the Theme. func (t *Theme) GetExercices() ([]*Exercice, error) { - if rows, err := DBQuery("SELECT id_exercice, id_theme, title, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM exercices WHERE id_theme = ? ORDER BY path ASC", t.Id); err != nil { + if rows, err := DBQuery("SELECT id_exercice, id_theme, title, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM exercices WHERE id_theme = ? ORDER BY path ASC", t.Id); err != nil { return nil, err } else { defer rows.Close() @@ -131,7 +133,7 @@ func (t *Theme) GetExercices() ([]*Exercice, error) { exos := []*Exercice{} for rows.Next() { e := &Exercice{} - if err := rows.Scan(&e.Id, &e.IdTheme, &e.Title, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil { + if err := rows.Scan(&e.Id, &e.IdTheme, &e.Title, &e.Disabled, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil { return nil, err } e.AnalyzeTitle() @@ -194,7 +196,7 @@ func (t *Theme) addExercice(e *Exercice) (err error) { if e.WIP { wip = "%" } - if res, err := DBExec("INSERT INTO exercices (id_theme, title, url_id, path, statement, overview, finished, headline, issue, depend, gain, video_uri, resolution, seealso, issue_kind, coefficient_cur) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "+ik+", "+cc+")", t.Id, wip+e.Title, e.URLId, e.Path, e.Statement, e.Overview, e.Finished, e.Headline, e.Issue, e.Depend, e.Gain, e.VideoURI, e.Resolution, e.SeeAlso); err != nil { + if res, err := DBExec("INSERT INTO exercices (id_theme, title, disabled, url_id, path, statement, overview, finished, headline, issue, depend, gain, video_uri, resolution, seealso, issue_kind, coefficient_cur) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "+ik+", "+cc+")", t.Id, wip+e.Title, e.Disabled, e.URLId, e.Path, e.Statement, e.Overview, e.Finished, e.Headline, e.Issue, e.Depend, e.Gain, e.VideoURI, e.Resolution, e.SeeAlso); err != nil { return err } else if eid, err := res.LastInsertId(); err != nil { return err @@ -214,6 +216,7 @@ func (t *Theme) AddExercice(title string, wip bool, urlId string, path string, s e = &Exercice{ Title: title, + Disabled: false, WIP: wip, URLId: urlId, Path: path, @@ -240,7 +243,7 @@ func (e *Exercice) Update() (int64, error) { wip = "%" } - if res, err := DBExec("UPDATE exercices SET title = ?, url_id = ?, path = ?, statement = ?, overview = ?, headline = ?, issue = ?, issue_kind = ?, depend = ?, gain = ?, coefficient_cur = ?, video_uri = ?, resolution = ?, seealso = ?, finished = ? WHERE id_exercice = ?", wip+e.Title, e.URLId, e.Path, e.Statement, e.Overview, e.Headline, e.Issue, e.IssueKind, e.Depend, e.Gain, e.Coefficient, e.VideoURI, e.Resolution, e.SeeAlso, e.Finished, e.Id); err != nil { + if res, err := DBExec("UPDATE exercices SET title = ?, disabled = ?, url_id = ?, path = ?, statement = ?, overview = ?, headline = ?, issue = ?, issue_kind = ?, depend = ?, gain = ?, coefficient_cur = ?, video_uri = ?, resolution = ?, seealso = ?, finished = ? WHERE id_exercice = ?", wip+e.Title, e.Disabled, e.URLId, e.Path, e.Statement, e.Overview, e.Headline, e.Issue, e.IssueKind, e.Depend, e.Gain, e.Coefficient, e.VideoURI, e.Resolution, e.SeeAlso, e.Finished, e.Id); err != nil { return 0, err } else if nb, err := res.RowsAffected(); err != nil { return 0, err diff --git a/libfic/team_my.go b/libfic/team_my.go index 46e3d125..6387ce82 100644 --- a/libfic/team_my.go +++ b/libfic/team_my.go @@ -120,7 +120,7 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) { return ret, err } else if started { for _, e := range exos { - if t == nil || t.HasAccess(e) { + if t == nil || (!e.Disabled && t.HasAccess(e)) { exercice := myTeamExercice{} exercice.WIP = e.WIP exercice.ThemeId = e.IdTheme