admin: New route to reset settings to sane default values

This commit is contained in:
nemunaire 2020-11-13 11:25:29 +01:00
parent a8f25471f1
commit 1436d9ca81
4 changed files with 35 additions and 30 deletions

View file

@ -16,6 +16,9 @@ func init() {
router.GET("/api/settings-ro.json", apiHandler(getROSettings))
router.GET("/api/settings.json", apiHandler(getSettings))
router.PUT("/api/settings.json", apiHandler(saveSettings))
router.DELETE("/api/settings.json", apiHandler(func(_ httprouter.Params, _ []byte) (interface{}, error) {
return true, ResetSettings()
}))
router.POST("/api/reset", apiHandler(reset))
}
@ -61,6 +64,29 @@ func ApplySettings(config settings.FICSettings) {
fic.SubmissionUniqueness = config.SubmissionUniqueness
}
func ResetSettings() error {
return settings.SaveSettings(path.Join(settings.SettingsDir, settings.SettingsFile), settings.FICSettings{
Title: "Challenge FIC",
Authors: "Laboratoire SRS, ÉPITA",
FirstBlood: fic.FirstBlood,
SubmissionCostBase: fic.SubmissionCostBase,
ExerciceCurCoefficient: 1,
HintCurCoefficient: 1,
WChoiceCurCoefficient: 1,
AllowRegistration: false,
CanJoinTeam: false,
DenyTeamCreation: false,
DenyNameChange: false,
AcceptNewIssue: true,
EnableResolutionRoute: false,
PartialValidation: true,
UnlockedChallengeDepth: 0,
SubmissionUniqueness: false,
DisplayAllFlags: false,
EventKindness: false,
})
}
func reset(_ httprouter.Params, body []byte) (interface{}, error) {
var m map[string]string
if err := json.Unmarshal(body, &m); err != nil {
@ -75,6 +101,8 @@ func reset(_ httprouter.Params, body []byte) (interface{}, error) {
return true, fic.ResetExercices()
} else if t == "game" {
return true, fic.ResetGame()
} else if t == "settings" {
return true, ResetSettings()
} else {
return nil, errors.New("Unknown reset type")
}