From 8623773edc6d296170e1ed1e3c8bb0a29bab72ed Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Wed, 14 Jan 2026 20:15:48 +0000 Subject: [PATCH] Make oauth prompt use its own context type And use the common utility to populate the user information --- sync/dash.go | 18 ++++++++++++++++-- sync/oauth.go | 22 +++++++++++++--------- sync/types.go | 23 +++++------------------ 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/sync/dash.go b/sync/dash.go index 7add4752..477704aa 100644 --- a/sync/dash.go +++ b/sync/dash.go @@ -3,6 +3,7 @@ package sync import ( "context" "errors" + "html/template" "net/http" "time" @@ -28,6 +29,19 @@ var ( sourceT = buildTemplate("source", "authenticated") ) +type ContextDashboard struct { + CountInspections int + CountMosquitoSources int + CountServiceRequests int + Geo template.JS + IsSyncOngoing bool + LastSync *time.Time + MapData ComponentMap + Org string + RecentRequests []ServiceRequestSummary + User User +} + type ContextDistrict struct { MapboxToken string } @@ -85,7 +99,7 @@ func getRoot(w http.ResponseWriter, r *http.Request) { dashboard(r.Context(), w, user) return } else { - oauthPrompt(w, user) + oauthPrompt(w, r, user) return } } @@ -224,7 +238,7 @@ func dashboard(ctx context.Context, w http.ResponseWriter, user *models.User) { respondError(w, "Failed to get user context", err, http.StatusInternalServerError) return } - data := ContentDashboard{ + data := ContextDashboard{ CountInspections: int(inspectionCount), CountMosquitoSources: int(sourceCount), CountServiceRequests: int(serviceCount), diff --git a/sync/oauth.go b/sync/oauth.go index d581b9e1..cac03063 100644 --- a/sync/oauth.go +++ b/sync/oauth.go @@ -15,6 +15,10 @@ var ( oauthPromptT = buildTemplate("oauth-prompt", "authenticated") ) +type ContextOauthPrompt struct { + User User +} + func getArcgisOauthBegin(w http.ResponseWriter, r *http.Request) { authURL := config.BuildArcGISAuthURL(config.ClientID) http.Redirect(w, r, authURL, http.StatusFound) @@ -46,17 +50,17 @@ func getOAuthRefresh(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/?next=/oauth/refresh", http.StatusFound) return } - oauthPrompt(w, user) + oauthPrompt(w, r, user) } -func oauthPrompt(w http.ResponseWriter, user *models.User) { - dp := user.DisplayName - data := ContentDashboard{ - User: User{ - DisplayName: dp, - Initials: extractInitials(dp), - Username: user.Username, - }, +func oauthPrompt(w http.ResponseWriter, r *http.Request, user *models.User) { + userContent, err := contentForUser(r.Context(), user) + if err != nil { + respondError(w, "Failed to get user content", err, http.StatusInternalServerError) + return + } + data := ContextOauthPrompt{ + User: userContent, } htmlpage.RenderOrError(w, oauthPromptT, data) } diff --git a/sync/types.go b/sync/types.go index de475d2c..8bcd0300 100644 --- a/sync/types.go +++ b/sync/types.go @@ -1,7 +1,6 @@ package sync import ( - "html/template" "time" "github.com/Gleipnir-Technology/nidus-sync/notification" @@ -64,19 +63,6 @@ type ContentReportDetail struct { } type ContentReportDiagnostic struct { } -type ContentDashboard struct { - CountInspections int - CountMosquitoSources int - CountServiceRequests int - Geo template.JS - IsSyncOngoing bool - LastSync *time.Time - MapData ComponentMap - Org string - RecentRequests []ServiceRequestSummary - User User -} - type ContentDashboardLoading struct { User User } @@ -114,8 +100,9 @@ type ServiceRequestSummary struct { Status string } type User struct { - DisplayName string - Initials string - Notifications []notification.Notification - Username string + DisplayName string + Initials string + Notifications []notification.Notification + OrganizationID int + Username string }