61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
package webui
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/identity"
|
|
"github.com/samcharles93/archie-core/internal/domain/org"
|
|
)
|
|
|
|
// SetupStep is one item in the dashboard's getting-started checklist. Path is
|
|
// the page that owns the configuration the step is about, so an operator can
|
|
// follow the step to where it is fixed rather than guess a settings page.
|
|
type SetupStep struct {
|
|
Title string `json:"title"`
|
|
Detail string `json:"detail,omitempty"`
|
|
Done bool `json:"done"`
|
|
Path string `json:"path,omitempty"`
|
|
}
|
|
|
|
// handleSetup reports which setup steps are still missing in the caller's
|
|
// organisation, from live state. Optional capabilities (a chat channel, a
|
|
// repository) are set up where they are used, not listed here.
|
|
func (s *Server) handleSetup(w http.ResponseWriter, r *http.Request) {
|
|
steps := []SetupStep{}
|
|
if s.Store == nil {
|
|
writeJSON(w, map[string]any{"steps": steps})
|
|
return
|
|
}
|
|
if done, ok := s.hasActiveAgent(r); ok {
|
|
steps = append(steps, SetupStep{Title: "Agent identity", Done: done, Path: "/org/agents"})
|
|
}
|
|
if count, err := s.Store.StatusCounts(r.Context()); err == nil {
|
|
total := 0
|
|
for _, n := range count {
|
|
total += n
|
|
}
|
|
steps = append(steps, SetupStep{Title: "First task", Done: total > 0, Path: "/tasks"})
|
|
}
|
|
writeJSON(w, map[string]any{"steps": steps})
|
|
}
|
|
|
|
// hasActiveAgent reports whether the caller's org has an active bot or
|
|
// service account assigned; ok is false when that cannot be read.
|
|
func (s *Server) hasActiveAgent(r *http.Request) (done, ok bool) {
|
|
reader, isReader := s.Orgs.(org.AgentAssignments)
|
|
if !isReader || s.Identities == nil {
|
|
return false, false
|
|
}
|
|
assignments, err := reader.ListOrgAgents(r.Context(), policyOrg(r))
|
|
if err != nil {
|
|
return false, false
|
|
}
|
|
for _, assignment := range assignments {
|
|
value, err := s.Identities.Get(r.Context(), assignment.IdentityID)
|
|
if err == nil && value.Kind.Agent() && value.Lifecycle == identity.LifecycleActive {
|
|
return true, true
|
|
}
|
|
}
|
|
return false, true
|
|
}
|