#2121 removed the pages behind sixteen sections and both capability handlers still named them, so GET /api/capabilities advertised sections nothing can render and the old service probed for pages that are gone. The single binary now reports an organisation as unavailable (its page exists, its writes do not) and lists nothing else it has no page for; the old service reports only the sections and probes its pages still make.
49 lines
1.8 KiB
Go
49 lines
1.8 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,
|
|
"captures": s.Captures != nil,
|
|
"mappings": s.Mappings != 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_policies", http.MethodPut, "/api/access/policies"},
|
|
}
|
|
}
|