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

Commit 4c83f50

Browse files
committed
webui: Don't assume usernames are all lowercase
There are occasional errors showing up in our backend when a user has a username that's not all lower case. This commit should go a long way towards fixing that problem.
1 parent 39156f7 commit 4c83f50

File tree

1 file changed

+112
-14
lines changed

1 file changed

+112
-14
lines changed

webui/main.go

Lines changed: 112 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,14 @@ func branchNamesHandler(w http.ResponseWriter, r *http.Request) {
390390
w.WriteHeader(http.StatusBadRequest)
391391
return
392392
}
393-
dbOwner := strings.ToLower(usr)
393+
394+
// Use the established capitalisation of the username
395+
z, err := database.User(usr)
396+
if err != nil {
397+
w.WriteHeader(http.StatusInternalServerError)
398+
return
399+
}
400+
dbOwner := z.Username
394401

395402
// If any of the required values were empty, indicate failure
396403
if dbOwner == "" || dbName == "" {
@@ -1611,7 +1618,14 @@ func deleteBranchHandler(w http.ResponseWriter, r *http.Request) {
16111618
w.WriteHeader(http.StatusBadRequest)
16121619
return
16131620
}
1614-
dbOwner := strings.ToLower(usr)
1621+
1622+
// Use the established capitalisation of the username
1623+
z, err := database.User(usr)
1624+
if err != nil {
1625+
w.WriteHeader(http.StatusInternalServerError)
1626+
return
1627+
}
1628+
dbOwner := z.Username
16151629

16161630
// Check if a branch name was requested
16171631
branchName, err := com.GetFormBranch(r)
@@ -2102,7 +2116,14 @@ func deleteCommitHandler(w http.ResponseWriter, r *http.Request) {
21022116
w.WriteHeader(http.StatusBadRequest)
21032117
return
21042118
}
2105-
dbOwner := strings.ToLower(usr)
2119+
2120+
// Use the established capitalisation of the username
2121+
z, err := database.User(usr)
2122+
if err != nil {
2123+
w.WriteHeader(http.StatusInternalServerError)
2124+
return
2125+
}
2126+
dbOwner := z.Username
21062127

21072128
// Validate the supplied commit ID
21082129
commit, err := com.GetFormCommit(r)
@@ -2399,7 +2420,14 @@ func deleteDatabaseHandler(w http.ResponseWriter, r *http.Request) {
23992420
fmt.Fprint(w, "Validation failed for owner or database name")
24002421
return
24012422
}
2402-
dbOwner := strings.ToLower(usr)
2423+
2424+
// Use the established capitalisation of the username
2425+
z, err := database.User(usr)
2426+
if err != nil {
2427+
w.WriteHeader(http.StatusInternalServerError)
2428+
return
2429+
}
2430+
dbOwner := z.Username
24032431

24042432
// If any of the required values were empty, indicate failure
24052433
if dbName == "" || dbOwner == "" {
@@ -2517,7 +2545,14 @@ func deleteReleaseHandler(w http.ResponseWriter, r *http.Request) {
25172545
w.WriteHeader(http.StatusBadRequest)
25182546
return
25192547
}
2520-
dbOwner := strings.ToLower(usr)
2548+
2549+
// Use the established capitalisation of the username
2550+
z, err := database.User(usr)
2551+
if err != nil {
2552+
w.WriteHeader(http.StatusInternalServerError)
2553+
return
2554+
}
2555+
dbOwner := z.Username
25212556

25222557
// Ensure a release name was supplied in the tag parameter
25232558
relName, err := com.GetFormTag(r)
@@ -2598,7 +2633,14 @@ func deleteTagHandler(w http.ResponseWriter, r *http.Request) {
25982633
w.WriteHeader(http.StatusBadRequest)
25992634
return
26002635
}
2601-
dbOwner := strings.ToLower(usr)
2636+
2637+
// Use the established capitalisation of the username
2638+
z, err := database.User(usr)
2639+
if err != nil {
2640+
w.WriteHeader(http.StatusInternalServerError)
2641+
return
2642+
}
2643+
dbOwner := z.Username
26022644

26032645
// Ensure a tag name was supplied
26042646
tagName, err := com.GetFormTag(r)
@@ -4023,7 +4065,14 @@ func saveSettingsHandler(w http.ResponseWriter, r *http.Request) {
40234065
errorPage(w, r, http.StatusBadRequest, err.Error())
40244066
return
40254067
}
4026-
dbOwner := strings.ToLower(usr)
4068+
4069+
// Use the established capitalisation of the username
4070+
z, err := database.User(usr)
4071+
if err != nil {
4072+
w.WriteHeader(http.StatusInternalServerError)
4073+
return
4074+
}
4075+
dbOwner := z.Username
40274076

40284077
// Make sure a username was given
40294078
if len(dbOwner) == 0 || dbOwner == "" {
@@ -4436,7 +4485,14 @@ func setDefaultBranchHandler(w http.ResponseWriter, r *http.Request) {
44364485
w.WriteHeader(http.StatusBadRequest)
44374486
return
44384487
}
4439-
dbOwner := strings.ToLower(usr)
4488+
4489+
// Use the established capitalisation of the username
4490+
z, err := database.User(usr)
4491+
if err != nil {
4492+
w.WriteHeader(http.StatusInternalServerError)
4493+
return
4494+
}
4495+
dbOwner := z.Username
44404496

44414497
// Check if a branch name was requested
44424498
branchName, err := com.GetFormBranch(r)
@@ -4570,7 +4626,14 @@ func tableNamesHandler(w http.ResponseWriter, r *http.Request) {
45704626
w.WriteHeader(http.StatusBadRequest)
45714627
return
45724628
}
4573-
dbOwner := strings.ToLower(usr)
4629+
4630+
// Use the established capitalisation of the username
4631+
z, err := database.User(usr)
4632+
if err != nil {
4633+
w.WriteHeader(http.StatusInternalServerError)
4634+
return
4635+
}
4636+
dbOwner := z.Username
45744637

45754638
// Make sure a branch name was provided
45764639
branchName, err := com.GetFormBranch(r)
@@ -4994,7 +5057,14 @@ func updateBranchHandler(w http.ResponseWriter, r *http.Request) {
49945057
w.WriteHeader(http.StatusBadRequest)
49955058
return
49965059
}
4997-
dbOwner := strings.ToLower(usr)
5060+
5061+
// Use the established capitalisation of the username
5062+
z, err := database.User(usr)
5063+
if err != nil {
5064+
w.WriteHeader(http.StatusInternalServerError)
5065+
return
5066+
}
5067+
dbOwner := z.Username
49985068

49995069
// Unescape, then validate the new branch name
50005070
a := r.PostFormValue("newbranch")
@@ -5137,7 +5207,14 @@ func updateCommentHandler(w http.ResponseWriter, r *http.Request) {
51375207
w.WriteHeader(http.StatusBadRequest)
51385208
return
51395209
}
5140-
dbOwner := strings.ToLower(usr)
5210+
5211+
// Use the established capitalisation of the username
5212+
z, err := database.User(usr)
5213+
if err != nil {
5214+
w.WriteHeader(http.StatusInternalServerError)
5215+
return
5216+
}
5217+
dbOwner := z.Username
51415218

51425219
// Ensure a discussion ID was given
51435220
a := r.PostFormValue("discid")
@@ -5346,7 +5423,14 @@ func updateDiscussHandler(w http.ResponseWriter, r *http.Request) {
53465423
fmt.Fprint(w, "Bad request")
53475424
return
53485425
}
5349-
dbOwner := strings.ToLower(usr)
5426+
5427+
// Use the established capitalisation of the username
5428+
z, err := database.User(usr)
5429+
if err != nil {
5430+
w.WriteHeader(http.StatusInternalServerError)
5431+
return
5432+
}
5433+
dbOwner := z.Username
53505434

53515435
// Ensure a discussion ID was given
53525436
a := r.PostFormValue("discid")
@@ -5456,7 +5540,14 @@ func updateReleaseHandler(w http.ResponseWriter, r *http.Request) {
54565540
w.WriteHeader(http.StatusBadRequest)
54575541
return
54585542
}
5459-
dbOwner := strings.ToLower(usr)
5543+
5544+
// Use the established capitalisation of the username
5545+
z, err := database.User(usr)
5546+
if err != nil {
5547+
w.WriteHeader(http.StatusInternalServerError)
5548+
return
5549+
}
5550+
dbOwner := z.Username
54605551

54615552
// Validate new release name
54625553
a := r.PostFormValue("newtag")
@@ -5570,7 +5661,14 @@ func updateTagHandler(w http.ResponseWriter, r *http.Request) {
55705661
w.WriteHeader(http.StatusBadRequest)
55715662
return
55725663
}
5573-
dbOwner := strings.ToLower(usr)
5664+
5665+
// Use the established capitalisation of the username
5666+
z, err := database.User(usr)
5667+
if err != nil {
5668+
w.WriteHeader(http.StatusInternalServerError)
5669+
return
5670+
}
5671+
dbOwner := z.Username
55745672

55755673
// Validate new tag name
55765674
a := r.PostFormValue("newtag")

0 commit comments

Comments
 (0)