From 5d834c1cd2138d6bd0d4daf415bdb5221c38bb1c Mon Sep 17 00:00:00 2001 From: Nick Gerakines Date: Wed, 15 Jan 2020 13:37:57 -0500 Subject: [PATCH] Minor code cleanup on settings page to improve oauth account management UI. T713 --- account.go | 19 +++++++++++++-- templates.go | 1 + templates/user/settings.tmpl | 45 +++++++++++++++++++++--------------- 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/account.go b/account.go index 3544813..ae3ef87 100644 --- a/account.go +++ b/account.go @@ -1038,11 +1038,24 @@ func viewSettings(app *App, u *User, w http.ResponseWriter, r *http.Request) err flashes, _ := getSessionFlashes(app, w, r, nil) + enableOauthSlack := app.Config().SlackOauth.ClientID != "" + enableOauthWriteAs := app.Config().WriteAsOauth.ClientID != "" + oauthAccounts, err := app.db.GetOauthAccounts(r.Context(), u.ID) if err != nil { log.Error("Unable to get oauth accounts for settings: %s", err) return impart.HTTPError{http.StatusInternalServerError, "Unable to retrieve user data. The humans have been alerted."} } + for _, oauthAccount := range oauthAccounts { + switch oauthAccount.Provider { + case "slack": + enableOauthSlack = false + case "write.as": + enableOauthWriteAs = false + } + } + + displayOauthSection := enableOauthSlack || enableOauthWriteAs || len(oauthAccounts) > 0 obj := struct { *UserPage @@ -1050,6 +1063,7 @@ func viewSettings(app *App, u *User, w http.ResponseWriter, r *http.Request) err HasPass bool IsLogOut bool Suspended bool + OauthSection bool OauthAccounts []oauthAccountInfo OauthSlack bool OauthWriteAs bool @@ -1059,9 +1073,10 @@ func viewSettings(app *App, u *User, w http.ResponseWriter, r *http.Request) err HasPass: passIsSet, IsLogOut: r.FormValue("logout") == "1", Suspended: fullUser.IsSilenced(), + OauthSection: displayOauthSection, OauthAccounts: oauthAccounts, - OauthSlack: app.Config().SlackOauth.ClientID != "", - OauthWriteAs: app.Config().WriteAsOauth.ClientID != "", + OauthSlack: enableOauthSlack, + OauthWriteAs: enableOauthWriteAs, } showUserPage(w, "settings", obj) diff --git a/templates.go b/templates.go index 968845d..c1a6da8 100644 --- a/templates.go +++ b/templates.go @@ -37,6 +37,7 @@ var ( "localstr": localStr, "localhtml": localHTML, "tolower": strings.ToLower, + "title": strings.Title, } ) diff --git a/templates/user/settings.tmpl b/templates/user/settings.tmpl index 2cda7dd..fc76f48 100644 --- a/templates/user/settings.tmpl +++ b/templates/user/settings.tmpl @@ -67,26 +67,33 @@ h3 { font-weight: normal; } - {{ if .OauthAccounts }} - {{ range $oauth_account := .OauthAccounts }} -
- - - -
-

{{ $oauth_account.Provider }}

-
- -
-
-
+ {{ if .OauthSection }} +

OAuth Management

+ {{ if .OauthAccounts }} +

Existing OAuth accounts can be removed from your account.

+ {{ range $oauth_account := .OauthAccounts }} +
+ + + +
+
+ +
+
+
+ {{ end }} + {{ end }} + {{ if or .OauthSlack .OauthWriteAs }} +

+ {{ if .OauthSlack }} + Sign in with Slack + {{ end }} + {{ if .OauthWriteAs }} + Link your Write.as account. + {{ end }} +

{{ end }} - {{ end }} - {{ if .OauthSlack }} - Sign in with Slack - {{ end }} - {{ if .OauthWriteAs }} - Link your Write.as account. {{ end }}