1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-22 08:35:57 +01:00

Split out userHandler.

This commit is contained in:
Juliusz Chroboczek 2024-05-03 20:36:51 +02:00
parent dc0610dc59
commit 46ed942300

View file

@ -277,24 +277,27 @@ func usersHandler(w http.ResponseWriter, r *http.Request, g, pth string) {
} }
first2, kind2, rest2 := splitPath(pth) first2, kind2, rest2 := splitPath(pth)
if first2 != "" && kind2 == ".password" && rest2 == "" { if first2 != "" && kind2 == "" {
userHandler(w, r, g, first2[1:])
return
} else if first2 != "" && kind2 == ".password" && rest2 == "" {
passwordHandler(w, r, g, first2[1:]) passwordHandler(w, r, g, first2[1:])
return return
} else if kind2 != "" || first2 == "" { }
if !checkAdmin(w, r) { if !checkAdmin(w, r) {
return return
} }
notFound(w) notFound(w)
return return
} }
func userHandler(w http.ResponseWriter, r *http.Request, g, user string) {
if !checkAdmin(w, r) { if !checkAdmin(w, r) {
return return
} }
username := first2[1:]
if r.Method == "HEAD" || r.Method == "GET" { if r.Method == "HEAD" || r.Method == "GET" {
user, etag, err := group.GetSanitisedUser(g, username) user, etag, err := group.GetSanitisedUser(g, user)
if err != nil { if err != nil {
httpError(w, err) httpError(w, err)
return return
@ -307,7 +310,7 @@ func usersHandler(w http.ResponseWriter, r *http.Request, g, pth string) {
sendJSON(w, r, user) sendJSON(w, r, user)
return return
} else if r.Method == "PUT" { } else if r.Method == "PUT" {
etag, err := group.GetUserTag(g, username) etag, err := group.GetUserTag(g, user)
if errors.Is(err, os.ErrNotExist) { if errors.Is(err, os.ErrNotExist) {
etag = "" etag = ""
err = nil err = nil
@ -326,7 +329,7 @@ func usersHandler(w http.ResponseWriter, r *http.Request, g, pth string) {
if done { if done {
return return
} }
err = group.UpdateUser(g, username, etag, &newdesc) err = group.UpdateUser(g, user, etag, &newdesc)
if err != nil { if err != nil {
httpError(w, err) httpError(w, err)
return return
@ -338,7 +341,7 @@ func usersHandler(w http.ResponseWriter, r *http.Request, g, pth string) {
} }
return return
} else if r.Method == "DELETE" { } else if r.Method == "DELETE" {
etag, err := group.GetUserTag(g, username) etag, err := group.GetUserTag(g, user)
if err != nil { if err != nil {
httpError(w, err) httpError(w, err)
return return
@ -349,7 +352,7 @@ func usersHandler(w http.ResponseWriter, r *http.Request, g, pth string) {
return return
} }
err = group.DeleteUser(g, username, etag) err = group.DeleteUser(g, user, etag)
if err != nil { if err != nil {
httpError(w, err) httpError(w, err)
return return