Add a disabled state to exercices

This commit is contained in:
nemunaire 2023-03-20 11:23:03 +01:00
parent 0f41e44e13
commit eb85b28f5b
10 changed files with 33 additions and 17 deletions

View file

@ -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() {

View file

@ -74,9 +74,10 @@
<form ng-submit="updateExercices()">
<fieldset>
<legend class="text-dark">Édition de masse <button type="submit" class="float-right btn btn-sm btn-success"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></button></legend>
<div class="form-group row" ng-repeat="field in ['gain','coefficient','issue','issuekind']">
<label for="{{ field }}" class="col-sm-1 col-form-label-sm">{{ field | capitalize }}</label>
<div class="col-sm-11">
<div class="form-group row" ng-class="{'row': field != 'disabled'}" ng-repeat="field in ['disabled','gain','coefficient','issue','issuekind']">
<input type="checkbox" class="form-check-input" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'disabled'">
<label for="{{ field }}" class="col-form-label-sm" ng-class="{'col-sm-1': field != 'disabled'}">{{ field | capitalize }}</label>
<div class="col-sm-11" ng-if="field != 'disabled'">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field != 'statement' && field != 'issue' && field != 'issuekind' && field != 'overview' && field != 'depend' && field != 'gain' && field != 'coefficient'">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'gain'" integer>
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'coefficient'" float>

View file

@ -21,8 +21,8 @@
<div class="form-group row" ng-repeat="field in fields">
<label for="{{ field }}" class="col-sm-1 col-form-label-sm">{{ field | capitalize }}</label>
<div class="col-sm-11">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field != 'statement' && field != 'issue' && field != 'issuekind' && field != 'overview' && field != 'resolution' && field != 'finished' && field != 'depend' && field != 'gain' && field != 'coefficient' && field != 'wip'">
<input class="form-check-input" type="checkbox" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'wip'">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field != 'statement' && field != 'issue' && field != 'issuekind' && field != 'overview' && field != 'resolution' && field != 'finished' && field != 'depend' && field != 'gain' && field != 'coefficient' && field != 'wip' && field != 'disabled'">
<input type="checkbox" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'wip' || field == 'disabled'">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'gain'" integer>
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'coefficient'" float>
<textarea class="form-control form-control-sm" id="{{field}}" ng-model="exercice[field]" ng-if="field == 'statement' || field == 'overview' || field == 'finished' || field == 'resolution' || field == 'issue'"></textarea>

View file

@ -9,9 +9,10 @@
<div class="row">
<form ng-submit="saveTheme()" class="col-4">
<div class="form-group" ng-repeat="field in fields">
<div ng-class="{'form-group': field != 'disabled', 'form-check': field == 'disabled'}" ng-repeat="field in fields">
<input type="checkbox" class="form-check-input" id="{{ field }}" ng-model="theme[field]" ng-if="field == 'disabled'">
<label for="{{ field }}">{{ field | capitalize }}</label>
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="theme[field]" ng-if="field != 'intro'">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="theme[field]" ng-if="field != 'intro' && field != 'disabled'">
<textarea class="form-control form-control-sm" id="{{ field }}" ng-model="theme[field]" ng-if="field == 'intro'"></textarea>
</div>
<div class="text-right" ng-show="theme.id">

View file

@ -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 {

View file

@ -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) {

View file

@ -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")

View file

@ -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,

View file

@ -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

View file

@ -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