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

Commit eef1fb7

Browse files
committed
webui: Get database owner and name from DB details data structure
The database owner and name were taken from their own data structure even though most pages are providing a data structure with database details including the database name. This commit adds the database owner to that structure and removes the extra data structure for the name.
1 parent f36c016 commit eef1fb7

30 files changed

+450
-457
lines changed

common/postgresql.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,16 @@ func DBDetails(DB *SQLiteDBinfo, loggedInUser, dbOwner, dbFolder, dbName, commit
652652
DB.Info.Licence = "Not specified"
653653
}
654654

655+
// Retrieve correctly capitalised username for the database owner
656+
usrOwner, err := User(dbOwner)
657+
if err != nil {
658+
return err
659+
}
660+
655661
// Fill out the fields we already have data for
656662
DB.Info.Database = dbName
657663
DB.Info.Folder = dbFolder
664+
DB.Info.Owner = usrOwner.Username
658665

659666
// The social stats are always updated because they could change without the cache being updated
660667
DB.Info.Watchers, DB.Info.Stars, DB.Info.Forks, err = SocialStats(dbOwner, dbFolder, dbName)

common/types.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ type CommitEntry struct {
163163
Tree DBTree `json:"tree"`
164164
}
165165

166+
type DatabaseName struct {
167+
Database string
168+
Folder string
169+
Owner string
170+
}
171+
166172
type DataValue struct {
167173
Name string
168174
Type ValType
@@ -226,6 +232,7 @@ type DBInfo struct {
226232
LicenceURL string
227233
MRs int
228234
OneLineDesc string
235+
Owner string
229236
Public bool
230237
RepoModified time.Time
231238
Releases int
@@ -346,12 +353,6 @@ type MergeRequestEntry struct {
346353
State MergeRequestState `json:"state"`
347354
}
348355

349-
type MetaInfo struct {
350-
Database string
351-
Folder string
352-
Owner string
353-
}
354-
355356
type ReleaseEntry struct {
356357
Commit string `json:"commit"`
357358
Date time.Time `json:"date"`

webui/main.go

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

382-
func collectDatabaseInfo(r *http.Request, meta *com.MetaInfo) (errCode int, err error) {
383-
// TODO: Add folder and branch name support
384-
dbOwner, dbName, err := com.GetOD(1, r) // 1 = Ignore "/xxx/" at the start of the URL
385-
if err != nil {
386-
return http.StatusBadRequest, err
387-
}
388-
389-
// Validate the supplied information
390-
if dbOwner == "" || dbName == "" {
391-
return http.StatusBadRequest, fmt.Errorf("Missing database owner or database name")
392-
}
393-
394-
// Retrieve correctly capitalised username for the database owner
395-
usr, err := com.User(dbOwner)
396-
if err != nil {
397-
return http.StatusBadRequest, err
398-
}
399-
400-
// Store information
401-
meta.Database = dbName
402-
meta.Owner = usr.Username
403-
meta.Folder = "/"
404-
405-
return
406-
}
407-
408382
func collectPageMetaInfo(r *http.Request, pageMeta *PageMetaInfo) (errCode int, err error) {
409383
// Auth0 info
410384
pageMeta.Auth0.CallbackURL = "https://" + com.Conf.Web.ServerName + "/x/callback"
@@ -2977,6 +2951,31 @@ func generateCertHandler(w http.ResponseWriter, r *http.Request) {
29772951
return
29782952
}
29792953

2954+
func getDatabaseName(r *http.Request) (db com.DatabaseName, err error) {
2955+
// TODO: Add folder and branch name support
2956+
db.Owner, db.Database, err = com.GetOD(1, r) // 1 = Ignore "/xxx/" at the start of the URL
2957+
if err != nil {
2958+
return
2959+
}
2960+
2961+
// Validate the supplied information
2962+
if db.Owner == "" || db.Database == "" {
2963+
return db, fmt.Errorf("Missing database owner or database name")
2964+
}
2965+
2966+
// Retrieve correctly capitalised username for the database owner
2967+
usr, err := com.User(db.Owner)
2968+
if err != nil {
2969+
return db, err
2970+
}
2971+
2972+
// Store information
2973+
db.Owner = usr.Username
2974+
db.Folder = "/"
2975+
2976+
return
2977+
}
2978+
29802979
// Removes the logged in users session information.
29812980
func logoutHandler(w http.ResponseWriter, r *http.Request) {
29822981
// Remove session info

0 commit comments

Comments
 (0)