Files
Agent-System-Backend/internal/store/knowledge_owned_account_write.go
T
weichen adcd8fefd2 Fence U3 account writes and stabilize directory cursors
Why: Account disable could be followed by late Backend business writes, API key creation could implicitly create users, account bootstrap locks could invert, and directory cursors were process-local or leaked out-of-scope changes.

Evidence: Local go test ./... and isolated PostgreSQL package suites passed on the staged candidate; exact committed-head SELF replay and stage 6 human review remain pending.

Impact: Adds final account transactions and external-effect checks across HTTP, Host, Bus and run manager; tightens API key issuance and persists versioned cursor signing. Delegated RDM rename still needs the separately proposed real-operator contract, so A1 and stage 6 are not complete.

Refs: Documents U3 r1, approved A1-A4 amendment fb3a821, pending delegated-projection amendment 5783940, Dev feature/iam-u3-account-directory-recovery.
2026-10-14 07:33:54 +00:00

36 lines
1.0 KiB
Go

package store
import (
"database/sql"
"errors"
core "agent-system-core"
)
// AddKnowledgeForOwnedProjectAccountChecked is the HTTP owner's project path.
// Domain/plugin publication has a separate authorization callback and uses the
// broader account-checked method; this entry rechecks physical ownership in
// the final Backend transaction.
func (s *Store) AddKnowledgeForOwnedProjectAccountChecked(actor, projectID string, allowImplicitDefault bool, docs ...core.KnowledgeDoc) error {
if len(docs) == 0 {
return nil
}
for _, doc := range docs {
if doc.Owner != core.ID(actor) || doc.ProjectID != core.ID(projectID) {
return ErrNotFound
}
}
return s.withEffectiveAccountWrite(actor, allowImplicitDefault, func(tx *sql.Tx, _ Account) error {
var owner string
if err := tx.QueryRow(s.q(`SELECT owner FROM projects WHERE id=?`), projectID).Scan(&owner); errors.Is(err, sql.ErrNoRows) {
return ErrNotFound
} else if err != nil {
return err
}
if owner != actor {
return ErrNotFound
}
return s.addKnowledgeTx(tx, docs)
})
}