Add publishing of awards to TBA.

This commit is contained in:
Patrick Fairbank
2019-09-15 02:09:23 -07:00
parent 26611367ce
commit 92a52ddd88
8 changed files with 139 additions and 25 deletions

View File

@@ -73,3 +73,17 @@ func (web *Web) awardsPostHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/setup/awards", 303)
}
// Publishes the awards to the web.
func (web *Web) awardsPublishHandler(w http.ResponseWriter, r *http.Request) {
if !web.userIsAdmin(w, r) {
return
}
err := web.arena.TbaClient.PublishAwards(web.arena.Database)
if err != nil {
http.Error(w, "Failed to publish awards: "+err.Error(), 500)
return
}
http.Redirect(w, r, "/setup/awards", 303)
}

View File

@@ -33,3 +33,14 @@ func TestSetupAwards(t *testing.T) {
assert.Equal(t, 200, recorder.Code)
assert.Contains(t, recorder.Body.String(), "Englebert")
}
func TestSetupAwardsPublish(t *testing.T) {
web := setupTestWeb(t)
web.arena.TbaClient.BaseUrl = "fakeurl"
web.arena.EventSettings.TbaPublishingEnabled = true
recorder := web.postHttpResponse("/setup/awards/publish", "")
assert.Equal(t, 500, recorder.Code)
assert.Contains(t, recorder.Body.String(), "Failed to publish awards")
}

View File

@@ -145,6 +145,7 @@ func (web *Web) newHandler() http.Handler {
router.HandleFunc("/reports/csv/wpa_keys", web.wpaKeysCsvReportHandler).Methods("GET")
router.HandleFunc("/setup/awards", web.awardsGetHandler).Methods("GET")
router.HandleFunc("/setup/awards", web.awardsPostHandler).Methods("POST")
router.HandleFunc("/setup/awards/publish", web.awardsPublishHandler).Methods("POST")
router.HandleFunc("/setup/db/clear", web.clearDbHandler).Methods("POST")
router.HandleFunc("/setup/db/restore", web.restoreDbHandler).Methods("POST")
router.HandleFunc("/setup/db/save", web.saveDbHandler).Methods("GET")