Quality / check (pull_request) Successful in 3m7s
The dashboard is served by both binaries, and internal/webui serves no /api/memory route. Reporting the memory sections as unavailable drops both pages from the navigation there instead of offering pages whose every read and write answers not found.
59 lines
2.3 KiB
Go
59 lines
2.3 KiB
Go
package webui
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/access"
|
|
)
|
|
|
|
// handleCapabilities reports which dashboard sections this process can serve
|
|
// and which the caller may use, so the browser hides the rest.
|
|
func (s *Server) handleCapabilities(w http.ResponseWriter, r *http.Request) {
|
|
sections := map[string]bool{
|
|
"chat": s.Chat != nil && s.Chat.Contract != nil,
|
|
"logs": s.LogFeed != nil,
|
|
"skills": s.Skills != nil,
|
|
"curators": s.Curators != nil,
|
|
"channels": s.Channels != nil,
|
|
"captures": s.Captures != nil,
|
|
"mappings": s.Mappings != nil,
|
|
"bindings": s.Bindings != nil,
|
|
// The workflows page draws its statistics from the task store
|
|
// and its definition list from the local registry, so it is
|
|
// worth showing with only the former.
|
|
"workflows": true,
|
|
// The memory pages and their admin settings call /api/memory, which
|
|
// this process does not serve: offering them would answer every read
|
|
// and write with a not-found.
|
|
"memory": false,
|
|
"memory_admin": false,
|
|
// Configuration renders from whichever source is wired, and only
|
|
// the system org operates the instance: every other org's
|
|
// settings pages would offer saves the control plane refuses.
|
|
"settings": instanceViewer(r),
|
|
}
|
|
// A page is offered only to a caller whose grants let it operate there.
|
|
// With no access chain the single operator may use everything.
|
|
_, hasPrincipal := access.PrincipalFromContext(r.Context())
|
|
for _, p := range pageProbes() {
|
|
sections[p.section] = !hasPrincipal || s.Access == nil || s.mayCall(r, p.method, p.path)
|
|
}
|
|
writeJSON(w, map[string]any{"sections": sections})
|
|
}
|
|
|
|
type pageProbe struct{ section, method, path string }
|
|
|
|
// pageProbes names, per page, the API call that page makes; the dashboard
|
|
// hides a page whose call the caller's grants refuse.
|
|
func pageProbes() []pageProbe {
|
|
return []pageProbe{
|
|
{"org_members", http.MethodPost, "/api/orgs/_/members"},
|
|
{"org_agents", http.MethodPut, "/api/orgs/_/agents/_"},
|
|
{"org_policies", http.MethodPut, "/api/access/policies"},
|
|
{"org_denials", http.MethodGet, "/api/access/denials"},
|
|
{"org_audit", http.MethodGet, "/api/audit"},
|
|
{"org_usage", http.MethodGet, "/api/usage"},
|
|
{"org_config", http.MethodPost, "/api/control-plane/resources/_/commands/replace"},
|
|
}
|
|
}
|