Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 082ca49

Browse files
committed
webui: Refactor data passed to web page templates
This refactors the page data structures passed to the HTML templates. The idea here is to have one data structure for meta information on the web page, including authentication and server information, and one separate data structure on the database. By improving the helper functions for handling these structures this also simplifies the code a bit.
1 parent 9a0a105 commit 082ca49

27 files changed

+300
-373
lines changed

common/types.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,6 @@ type APIKey struct {
132132
DateCreated time.Time `json:"date_created"`
133133
}
134134

135-
type Auth0Set struct {
136-
CallbackURL string
137-
ClientID string
138-
Domain string
139-
}
140-
141135
type BranchEntry struct {
142136
Commit string `json:"commit"`
143137
CommitCount int `json:"commit_count"`
@@ -349,21 +343,13 @@ type MergeRequestEntry struct {
349343
}
350344

351345
type MetaInfo struct {
352-
AvatarURL string
353346
Database string
354-
Environment string
355347
Folder string
356348
ForkDatabase string
357349
ForkDeleted bool
358350
ForkFolder string
359351
ForkOwner string
360-
LoggedInUser string
361-
NumStatusUpdates int
362352
Owner string
363-
PageSection string
364-
Protocol string
365-
Server string
366-
Title string
367353
}
368354

369355
type ReleaseEntry struct {

webui/main.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,24 +379,27 @@ func checkLogin(r *http.Request) (loggedInUser string, validSession bool, err er
379379
return
380380
}
381381

382-
func collectPageAuth0Info() (auth0 com.Auth0Set) {
382+
func collectPageAuth0Info() (auth0 Auth0Set) {
383383
auth0.CallbackURL = "https://" + com.Conf.Web.ServerName + "/x/callback"
384384
auth0.ClientID = com.Conf.Auth0.ClientID
385385
auth0.Domain = com.Conf.Auth0.Domain
386386
return
387387
}
388388

389-
func collectPageMetaInfo(r *http.Request, meta *com.MetaInfo, requireLogin bool, getOwnerAndDatabaseFromUrl bool, getOwnerAndDatabaseFromData bool) (errCode int, err error) {
389+
func collectPageMetaInfo(r *http.Request, pageMeta *PageMetaInfo, meta *com.MetaInfo, requireLogin bool, getOwnerAndDatabaseFromUrl bool, getOwnerAndDatabaseFromData bool) (errCode int, err error) {
390+
// Auth0 info
391+
pageMeta.Auth0 = collectPageAuth0Info()
392+
390393
// Server name
391-
meta.Server = com.Conf.Web.ServerName
394+
pageMeta.Server = com.Conf.Web.ServerName
392395

393396
// Retrieve session data (if any)
394397
loggedInUser, validSession, err := checkLogin(r)
395398
if err != nil {
396399
return http.StatusBadRequest, err
397400
}
398401
if validSession {
399-
meta.LoggedInUser = loggedInUser
402+
pageMeta.LoggedInUser = loggedInUser
400403
}
401404

402405
// Ensure we have a valid logged in user
@@ -411,9 +414,9 @@ func collectPageMetaInfo(r *http.Request, meta *com.MetaInfo, requireLogin bool,
411414
return http.StatusBadRequest, err
412415
}
413416
if ur.AvatarURL != "" {
414-
meta.AvatarURL = ur.AvatarURL + "&s=48"
417+
pageMeta.AvatarURL = ur.AvatarURL + "&s=48"
415418
}
416-
meta.NumStatusUpdates, err = com.UserStatusUpdates(loggedInUser)
419+
pageMeta.NumStatusUpdates, err = com.UserStatusUpdates(loggedInUser)
417420
if err != nil {
418421
return http.StatusBadRequest, err
419422
}
@@ -473,7 +476,7 @@ func collectPageMetaInfo(r *http.Request, meta *com.MetaInfo, requireLogin bool,
473476
}
474477

475478
// Pass along the environment setting
476-
meta.Environment = com.Conf.Environment.Environment
479+
pageMeta.Environment = com.Conf.Environment.Environment
477480

478481
return
479482
}

0 commit comments

Comments
 (0)