From 37b7755c08f80cddfa0487f2a72a6a3dd722dfaf Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sat, 15 Feb 2020 12:56:33 -0500 Subject: [PATCH] Tell admin that automated check failed when necessary This keeps track when automated update check fails, and displays a relevant message to the admin on /admin/updates Ref T572 --- admin.go | 2 ++ less/core.less | 5 +++++ templates/user/admin/app-updates.tmpl | 6 +++++- updates.go | 4 +++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/admin.go b/admin.go index c0ad436..b1f1533 100644 --- a/admin.go +++ b/admin.go @@ -612,6 +612,7 @@ func handleViewAdminUpdates(app *App, u *User, w http.ResponseWriter, r *http.Re LatestVersion string LatestReleaseURL string LatestReleaseNotesURL string + CheckFailed bool }{ UserPage: NewUserPage(app, r, u, "Updates", nil), AdminPage: NewAdminPage(app), @@ -624,6 +625,7 @@ func handleViewAdminUpdates(app *App, u *User, w http.ResponseWriter, r *http.Re p.LatestReleaseURL = app.updates.ReleaseURL() p.LatestReleaseNotesURL = app.updates.ReleaseNotesURL() p.UpdateAvailable = app.updates.AreAvailable() + p.CheckFailed = app.updates.checkError != nil } showUserPage(w, "app-updates", p) diff --git a/less/core.less b/less/core.less index 05a050c..afccc9c 100644 --- a/less/core.less +++ b/less/core.less @@ -1350,6 +1350,11 @@ div.row { color: #71D571; } +.ex.failure { + font-weight: bold; + color: @dangerCol; +} + @media all and (max-width: 450px) { body#post { header { diff --git a/templates/user/admin/app-updates.tmpl b/templates/user/admin/app-updates.tmpl index 36e7f23..62fd83d 100644 --- a/templates/user/admin/app-updates.tmpl +++ b/templates/user/admin/app-updates.tmpl @@ -15,7 +15,11 @@ {{template "admin-header" .}} {{ if .UpdateChecks }} - {{if not .UpdateAvailable}} + {{if .CheckFailed}} +

× Automated update check failed.

+

Installed version: {{.Version}} (release notes).

+

Learn about latest releases on the WriteFreely blog or forum.

+ {{else if not .UpdateAvailable}}

WriteFreely is up to date.

Installed version: {{.Version}} (release notes).

{{else}} diff --git a/updates.go b/updates.go index b1893fd..e41b00b 100644 --- a/updates.go +++ b/updates.go @@ -30,6 +30,7 @@ type updatesCache struct { lastCheck time.Time latestVersion string currentVersion string + checkError error } // CheckNow asks for the latest released version of writefreely and updates @@ -38,11 +39,12 @@ type updatesCache struct { func (uc *updatesCache) CheckNow() error { uc.mu.Lock() defer uc.mu.Unlock() + uc.lastCheck = time.Now() latestRemote, err := newVersionCheck() if err != nil { + uc.checkError = err return err } - uc.lastCheck = time.Now() if CompareSemver(latestRemote, uc.latestVersion) == 1 { uc.latestVersion = latestRemote }