Files
archie/internal/webui/api_capabilities.go
T
sam da01f2cbe1 feat(access): denial retention knob, State Store sweep and dashboard denials page (#1842)
Add [access].denial_retention (default 90 days, matching the audit-retention
seed) wired through config defaults and validation; the State Store sweeps
denial records older than the configured age hourly via the new
access.DenialPruner / PruneDenials store query. The dashboard gains
GET /api/access/denials (read_audit-gated, so org admins/owners see their
org's records; the store scopes by the credential's org) and an
/org/denials page backed by a Pinia store.
2026-10-31 14:23:31 +11:00

53 lines
2.0 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,
// 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_config", http.MethodPost, "/api/control-plane/resources/_/commands/replace"},
}
}