internal/httpd/admin.go
40 lines · 1107 bytes
1 symbol in this file
1package httpd
2
3import (
4 "net/http"
5
6 "gitbay.org/gitbay/internal/control"
7 "gitbay.org/gitbay/internal/store"
8)
9
10// adminPage is the operator's view: the running build and every worker
11// queue, read through the dashboard command's admin-only block. A
12// non-admin gets the same 404 a missing page would, so the URL confirms
13// nothing.
14func (s *Server) adminPage(w http.ResponseWriter, r *http.Request, viewer store.User) {
15 if !viewer.IsAdmin {
16 s.notFound(w, r)
17 return
18 }
19 var d control.DashboardOut
20 if msg, ok := s.runControlInto(viewer, []string{"dashboard"}, &d); !ok {
21 http.Error(w, msg, http.StatusInternalServerError)
22 return
23 }
24 // Both blocks are admin-only and this handler is admin-gated, so they
25 // are present; the payload types them as optional because everyone
26 // else's dashboard omits them.
27 commit, queues := "", store.Queues{}
28 if d.Server != nil {
29 commit = d.Server.Commit
30 }
31 if d.Queues != nil {
32 queues = *d.Queues
33 }
34 s.render(w, "admin.html", struct {
35 basePage
36 Tab string
37 Commit string
38 Queues store.Queues
39 }{s.baseFor(viewer), "admin", commit, queues})
40}