internal/httpd/admin.go

251a71053c93d2621ad97fa7d1ce8efacb119406
gitbay/internal/httpd/admin.go history · blame · raw

34 lines · 870 bytes

 1package httpd
 2
 3import (
 4	"net/http"
 5
 6	"gitbay.org/gitbay/internal/store"
 7)
 8
 9// adminPage is the operator's view: the running build and every worker
10// queue, read through the dashboard command's admin-only block. A
11// non-admin gets the same 404 a missing page would, so the URL confirms
12// nothing.
13func (s *Server) adminPage(w http.ResponseWriter, r *http.Request, viewer store.User) {
14	if !viewer.IsAdmin {
15		s.notFound(w, r)
16		return
17	}
18	var d struct {
19		Server struct {
20			Commit string `json:"commit"`
21		} `json:"server"`
22		Queues store.Queues `json:"queues"`
23	}
24	if msg, ok := s.runControlInto(viewer, []string{"dashboard"}, &d); !ok {
25		http.Error(w, msg, http.StatusInternalServerError)
26		return
27	}
28	s.render(w, "admin.html", struct {
29		basePage
30		Tab    string
31		Commit string
32		Queues store.Queues
33	}{s.baseFor(viewer), "admin", d.Server.Commit, d.Queues})
34}