Do not accept “subdirectories” for public campsite types URL

For now, it ends with the UUID or 404.
This commit is contained in:
jordi fita mas 2023-10-18 20:58:52 +02:00
parent 852acaccc3
commit 6e7df4ca79
1 changed files with 23 additions and 15 deletions

View File

@ -28,16 +28,21 @@ type PublicHandler struct {
func (h *PublicHandler) Handler(user *auth.User, company *auth.Company, conn *database.Conn) http.Handler { func (h *PublicHandler) Handler(user *auth.User, company *auth.Company, conn *database.Conn) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var head string var typeUuid string
head, r.URL.Path = httplib.ShiftPath(r.URL.Path) typeUuid, r.URL.Path = httplib.ShiftPath(r.URL.Path)
switch r.Method { if !uuid.Valid(typeUuid) {
case http.MethodGet:
if !uuid.Valid(head) {
http.NotFound(w, r) http.NotFound(w, r)
return return
} }
page, err := newPublicPage(r.Context(), company, conn, user.Locale, head)
var head string
head, r.URL.Path = httplib.ShiftPath(r.URL.Path)
switch head {
case "":
switch r.Method {
case http.MethodGet:
page, err := newPublicPage(r.Context(), company, conn, user.Locale, typeUuid)
if database.ErrorIsNotFound(err) { if database.ErrorIsNotFound(err) {
http.NotFound(w, r) http.NotFound(w, r)
return return
@ -48,6 +53,9 @@ func (h *PublicHandler) Handler(user *auth.User, company *auth.Company, conn *da
default: default:
httplib.MethodNotAllowed(w, r, http.MethodGet) httplib.MethodNotAllowed(w, r, http.MethodGet)
} }
default:
http.NotFound(w, r)
}
}) })
} }