Phase 11, part 3: approvals for what agents send out
Agents can now ask to publish or schedule a post, send an email, add someone to a mailing list, or apply an SEO change. Each waits on the Approvals page (with a count in the sidebar) for an admin or a member with edit on its module, who can edit it first, approve or refuse it, and let the agent take that class of action on its own with a cap per day. A rotation after a leak revokes the old keys and withdraws everything allowed. All of it is in the audit log. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+21
-1
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/approvals"
|
||||
"supermarket/internal/audit"
|
||||
"supermarket/internal/fileutil"
|
||||
"supermarket/internal/mcpserver"
|
||||
@@ -273,6 +274,8 @@ func (s *Server) showKey(w http.ResponseWriter, r *http.Request, u *users.User,
|
||||
type agentData struct {
|
||||
Row agentRow
|
||||
Grants []grant
|
||||
Allowed []approvals.Grant // what it may do on its own
|
||||
Asked []approvals.Request
|
||||
Problem string
|
||||
Now time.Time
|
||||
}
|
||||
@@ -314,7 +317,10 @@ func (s *Server) renderAgent(w http.ResponseWriter, r *http.Request, u *users.Us
|
||||
if code != http.StatusOK {
|
||||
w.WriteHeader(code)
|
||||
}
|
||||
s.render(w, r, "agent", page{Title: u.Name, Nav: "settings/agents", Data: agentData{Row: row, Grants: agentGrants(), Problem: problem, Now: now}})
|
||||
d := agentData{Row: row, Grants: agentGrants(), Problem: problem, Now: now}
|
||||
d.Allowed, _ = approvals.Grants(s.DB, u.ID)
|
||||
d.Asked, _ = approvals.List(s.DB, "", u.ID, 20)
|
||||
s.render(w, r, "agent", page{Title: u.Name, Nav: "settings/agents", Data: d})
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -348,7 +354,21 @@ func (s *Server) agentAction(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
case "rotate":
|
||||
var key string
|
||||
leaked := r.PostFormValue("leaked") == "on"
|
||||
if leaked {
|
||||
// A leaked key: its replacement starts with nothing allowed on
|
||||
// its own, and the old key stops now.
|
||||
if err = approvals.WithdrawAll(s.DB, u.ID); err == nil {
|
||||
err = users.RevokeAll(s.DB, u.ID, now)
|
||||
}
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
if key, _, err = users.Rotate(s.DB, u.ID, now); err == nil {
|
||||
if leaked {
|
||||
s.audit(r, "key-revoked", u.Name, "it leaked: every key revoked, and what it may do on its own withdrawn")
|
||||
}
|
||||
if s.isHermes(u.ID) {
|
||||
err = s.newHermesToken(key)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user