mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-11-10 08:57:25 +01:00
Add Header Requirements and BuildInfos to message
This commit is contained in:
parent
8eda4b306d
commit
9afb6dc933
@ -319,11 +319,11 @@ func main() {
|
|||||||
|
|
||||||
// Send a searchId and then reply with a redirect to a user, or directly send query to job table for jobid and project.
|
// Send a searchId and then reply with a redirect to a user, or directly send query to job table for jobid and project.
|
||||||
secured.HandleFunc("/search", func(rw http.ResponseWriter, r *http.Request) {
|
secured.HandleFunc("/search", func(rw http.ResponseWriter, r *http.Request) {
|
||||||
routerConfig.HandleSearchBar(rw, r)
|
routerConfig.HandleSearchBar(rw, r, buildInfo)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Mount all /monitoring/... and /api/... routes.
|
// Mount all /monitoring/... and /api/... routes.
|
||||||
routerConfig.SetupRoutes(secured, version, commit, date)
|
routerConfig.SetupRoutes(secured, buildInfo)
|
||||||
api.MountRoutes(secured)
|
api.MountRoutes(secured)
|
||||||
|
|
||||||
if config.Keys.EmbedStaticFiles {
|
if config.Keys.EmbedStaticFiles {
|
||||||
|
@ -229,7 +229,7 @@ func buildFilterPresets(query url.Values) map[string]interface{} {
|
|||||||
return filterPresets
|
return filterPresets
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupRoutes(router *mux.Router, version string, hash string, buildTime string) {
|
func SetupRoutes(router *mux.Router, buildInfo web.Build) {
|
||||||
userCfgRepo := repository.GetUserCfgRepo()
|
userCfgRepo := repository.GetUserCfgRepo()
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
route := route
|
route := route
|
||||||
@ -255,7 +255,7 @@ func SetupRoutes(router *mux.Router, version string, hash string, buildTime stri
|
|||||||
Title: title,
|
Title: title,
|
||||||
User: *user,
|
User: *user,
|
||||||
Roles: availableRoles,
|
Roles: availableRoles,
|
||||||
Build: web.Build{Version: version, Hash: hash, Buildtime: buildTime},
|
Build: buildInfo,
|
||||||
Config: conf,
|
Config: conf,
|
||||||
Infos: infos,
|
Infos: infos,
|
||||||
}
|
}
|
||||||
@ -269,10 +269,12 @@ func SetupRoutes(router *mux.Router, version string, hash string, buildTime stri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleSearchBar(rw http.ResponseWriter, r *http.Request) {
|
func HandleSearchBar(rw http.ResponseWriter, r *http.Request, buildInfo web.Build) {
|
||||||
|
user := auth.GetUser(r.Context())
|
||||||
|
availableRoles, _ := auth.GetValidRolesMap(user)
|
||||||
|
|
||||||
if search := r.URL.Query().Get("searchId"); search != "" {
|
if search := r.URL.Query().Get("searchId"); search != "" {
|
||||||
repo := repository.GetJobRepository()
|
repo := repository.GetJobRepository()
|
||||||
user := auth.GetUser(r.Context())
|
|
||||||
splitSearch := strings.Split(search, ":")
|
splitSearch := strings.Split(search, ":")
|
||||||
|
|
||||||
if len(splitSearch) == 2 {
|
if len(splitSearch) == 2 {
|
||||||
@ -287,7 +289,7 @@ func HandleSearchBar(rw http.ResponseWriter, r *http.Request) {
|
|||||||
if user.HasAnyRole([]auth.Role{auth.RoleAdmin, auth.RoleSupport, auth.RoleManager}) {
|
if user.HasAnyRole([]auth.Role{auth.RoleAdmin, auth.RoleSupport, auth.RoleManager}) {
|
||||||
http.Redirect(rw, r, "/monitoring/users/?user="+url.QueryEscape(strings.Trim(splitSearch[1], " ")), http.StatusFound)
|
http.Redirect(rw, r, "/monitoring/users/?user="+url.QueryEscape(strings.Trim(splitSearch[1], " ")), http.StatusFound)
|
||||||
} else {
|
} else {
|
||||||
web.RenderTemplate(rw, r, "message.tmpl", &web.Page{Title: "Error", MsgType: "alert-danger", Message: "Missing Access Rights"})
|
web.RenderTemplate(rw, r, "message.tmpl", &web.Page{Title: "Error", MsgType: "alert-danger", Message: "Missing Access Rights", User: *user, Roles: availableRoles, Build: buildInfo})
|
||||||
}
|
}
|
||||||
case "name":
|
case "name":
|
||||||
usernames, _ := repo.FindColumnValues(user, strings.Trim(splitSearch[1], " "), "user", "username", "name")
|
usernames, _ := repo.FindColumnValues(user, strings.Trim(splitSearch[1], " "), "user", "username", "name")
|
||||||
@ -298,17 +300,17 @@ func HandleSearchBar(rw http.ResponseWriter, r *http.Request) {
|
|||||||
if user.HasAnyRole([]auth.Role{auth.RoleAdmin, auth.RoleSupport, auth.RoleManager}) {
|
if user.HasAnyRole([]auth.Role{auth.RoleAdmin, auth.RoleSupport, auth.RoleManager}) {
|
||||||
http.Redirect(rw, r, "/monitoring/users/?user=NoUserNameFound", http.StatusPermanentRedirect)
|
http.Redirect(rw, r, "/monitoring/users/?user=NoUserNameFound", http.StatusPermanentRedirect)
|
||||||
} else {
|
} else {
|
||||||
web.RenderTemplate(rw, r, "message.tmpl", &web.Page{Title: "Error", MsgType: "alert-danger", Message: "Missing Access Rights"})
|
web.RenderTemplate(rw, r, "message.tmpl", &web.Page{Title: "Error", MsgType: "alert-danger", Message: "Missing Access Rights", User: *user, Roles: availableRoles, Build: buildInfo})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
web.RenderTemplate(rw, r, "message.tmpl", &web.Page{Title: "Warning", MsgType: "alert-warning", Message: fmt.Sprintf("Unknown search term %s", strings.Trim(splitSearch[0], " "))})
|
web.RenderTemplate(rw, r, "message.tmpl", &web.Page{Title: "Warning", MsgType: "alert-warning", Message: fmt.Sprintf("Unknown search term %s", strings.Trim(splitSearch[0], " ")), User: *user, Roles: availableRoles, Build: buildInfo})
|
||||||
}
|
}
|
||||||
} else if len(splitSearch) == 1 {
|
} else if len(splitSearch) == 1 {
|
||||||
|
|
||||||
username, project, jobname, err := repo.FindUserOrProjectOrJobname(user, strings.Trim(search, " "))
|
username, project, jobname, err := repo.FindUserOrProjectOrJobname(user, strings.Trim(search, " "))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
web.RenderTemplate(rw, r, "message.tmpl", &web.Page{Title: "Info", MsgType: "alert-info", Message: "Search without result"})
|
web.RenderTemplate(rw, r, "message.tmpl", &web.Page{Title: "Info", MsgType: "alert-info", Message: "Search without result", User: *user, Roles: availableRoles, Build: buildInfo})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,9 +324,9 @@ func HandleSearchBar(rw http.ResponseWriter, r *http.Request) {
|
|||||||
http.Redirect(rw, r, "/monitoring/jobs/?jobId="+url.QueryEscape(strings.Trim(search, " ")), http.StatusFound) // No Result: Probably jobId
|
http.Redirect(rw, r, "/monitoring/jobs/?jobId="+url.QueryEscape(strings.Trim(search, " ")), http.StatusFound) // No Result: Probably jobId
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
web.RenderTemplate(rw, r, "message.tmpl", &web.Page{Title: "Error", MsgType: "alert-danger", Message: "Searchbar query parameters malformed"})
|
web.RenderTemplate(rw, r, "message.tmpl", &web.Page{Title: "Error", MsgType: "alert-danger", Message: "Searchbar query parameters malformed", User: *user, Roles: availableRoles, Build: buildInfo})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
web.RenderTemplate(rw, r, "message.tmpl", &web.Page{Title: "Warning", MsgType: "alert-warning", Message: "Empty search"})
|
web.RenderTemplate(rw, r, "message.tmpl", &web.Page{Title: "Warning", MsgType: "alert-warning", Message: "Empty search", User: *user, Roles: availableRoles, Build: buildInfo})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user