carlos / platform Public

console: a linked account's own owners earn no plan notice

Spec §8: a customer account's notices go to whoever pays, its platform's
owners. The plan banner and CLI warnings still show the warning to the
customer's owner, but no longer record notice for afterGraceDue
(ownerNoticeCounts), so only a delivered email to the platform's owners
starts the clock. Astra Task 13 review, P2.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 4856dcf18132d80b72ac92fe4b9dbfe822b04f93 parent 5b143c4
3 files changed, +91 −2
  • internal/console/plangracepass.go +2 −2
  • internal/console/platformlinked.go +15 −0
  • internal/console/platformlinked_test.go +74 −0
diff --git a/internal/console/plangracepass.go b/internal/console/plangracepass.go
index 7f3a4a7ba..28bdd8422 100644
--- a/internal/console/plangracepass.go
+++ b/internal/console/plangracepass.go
@@ -380,7 +380,7 @@ func (s *Server) planBanner(ctx context.Context, acct *Account, role string, now
for _, n := range planNoticesOf(states, now, s.planStage(ctx, acct, now)) {
lines = append(lines, planNoticeText(n, "banner"))
}
- if role != RoleOwner || len(lines) == 0 {
+ if role != RoleOwner || len(lines) == 0 || !s.ownerNoticeCounts(ctx, acct) {
return lines, nil
}
return lines, shownStates(states, now)
@@ -442,7 +442,7 @@ func (s *Server) writePlanWarnings(w http.ResponseWriter, r *http.Request, p Pri
w.Header().Add(planWarningHeader, planNoticeText(n, "cli"))
}
seen := shownStates(states, now)
- if len(seen) == 0 || p.Kind != PrincipalUser || !s.isOwner(acct, p.Address) {
+ if len(seen) == 0 || p.Kind != PrincipalUser || !s.isOwner(acct, p.Address) || !s.ownerNoticeCounts(r.Context(), acct) {
return
}
if err := s.store.RecordCapNotice(r.Context(), acct.ID, seen, now); err != nil {
diff --git a/internal/console/platformlinked.go b/internal/console/platformlinked.go
index 53ccd0599..7bcfbf643 100644
--- a/internal/console/platformlinked.go
+++ b/internal/console/platformlinked.go
@@ -12,6 +12,7 @@ package console
import (
"context"
"fmt"
+ "log"
"strings"
"time"
)
@@ -64,6 +65,20 @@ func (s *Server) planNoticeRecipients(ctx context.Context, acct *Account) (owner
return owners, platform, nil
}
+// ownerNoticeCounts is whether a banner or CLI warning shown to one of
+// acct's own owners counts as notice for afterGraceDue. Not for a linked
+// account: its notices are its platform's owners' (spec §8), so only a
+// delivered email to them (notifyPlanOwners) counts. The customer's owner
+// still sees the warning. A failed link read counts nothing.
+func (s *Server) ownerNoticeCounts(ctx context.Context, acct *Account) bool {
+ platform, _, err := s.store.AccountPlatform(ctx, acct.ID)
+ if err != nil {
+ log.Printf("console: plan notice %s: platform link: %v", acct.Sqid, err)
+ return false
+ }
+ return platform == ""
+}
+
// platformPlanNoticeEmail is planNoticeEmail for a customer account's
// notice to its platform's owners: the same per-cap lines, and ways out
// through carlos platform instead of links into the customer account,
diff --git a/internal/console/platformlinked_test.go b/internal/console/platformlinked_test.go
index 1f5a5a6f7..c8d90d83e 100644
--- a/internal/console/platformlinked_test.go
+++ b/internal/console/platformlinked_test.go
@@ -940,3 +940,77 @@ func TestPlatformOwnerNoticeCountsForAfterGraceDue(t *testing.T) {
t.Fatalf("row %+v %v, want no notice and nothing due", row, ok)
}
}
+
+// customerOwnerSeesWarnings has owner, an owner of the linked account acct
+// (over a cap), browse its account page and use a declaring CLI on it: both
+// still show the warning, and neither may record notice (spec §8: only a
+// delivery to the platform's owners counts).
+func customerOwnerSeesWarnings(t *testing.T, fx *consoleFixture, acct *Account, owner, code string) {
+ t.Helper()
+ if err := fx.st.AddMember(acct.ID, owner, RoleOwner, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ c := newBrowser(t)
+ fx.setUser(owner)
+ signUp(t, fx, c, code+"-browser")
+ // storageOver's usage, as the banner words it.
+ if _, _, body := get(t, c, fx.ts.URL+"/a/"+acct.Sqid+"/"); !strings.Contains(body, "2.1 GB of 1.1 GB object storage") {
+ t.Fatalf("the customer's owner sees no banner on %s", acct.Sqid)
+ }
+ if st, _ := capRow(t, fx, acct, capStorage); !st.NoticeAt.IsZero() {
+ t.Fatalf("the customer owner's page view recorded notice: %v", st.NoticeAt)
+ }
+ tok := cliToken(t, fx, owner, code+"-cli")
+ req, err := http.NewRequest(http.MethodGet, fx.ts.URL+"/api/cli/apps/"+acct.Sqid+"/list", nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ req.Header.Set("Authorization", "Bearer "+tok)
+ req.Header.Set(planWarningsAccept, "1")
+ resp, err := http.DefaultClient.Do(req)
+ if err != nil {
+ t.Fatal(err)
+ }
+ resp.Body.Close()
+ if resp.StatusCode != http.StatusOK || len(resp.Header.Values(planWarningHeader)) != 1 {
+ t.Fatalf("CLI list on %s = %d, warnings %q, want 200 and the warning", acct.Sqid, resp.StatusCode, resp.Header.Values(planWarningHeader))
+ }
+ if st, _ := capRow(t, fx, acct, capStorage); !st.NoticeAt.IsZero() {
+ t.Fatalf("the customer owner's CLI recorded notice: %v", st.NoticeAt)
+ }
+}
+
+func TestLinkedCustomerOwnerWarningsEarnNoNotice(t *testing.T) {
+ fx, _, shop, mail := noticeWorld(t)
+ ctx := context.Background()
+ // The real clock: page views and CLI requests record at time.Now().
+ st := storageOver(t, fx, shop, time.Now().Add(-time.Hour))
+ customerOwnerSeesWarnings(t, fx, shop, "claimer@example.com", "code-linked-warn")
+ if err := fx.srv.notifyPlanOwners(ctx, shop, []capState{st}, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ if n := len(mail.sentCopy()); n != 1 {
+ t.Fatalf("sent %d notices, want one to the platform's owner", n)
+ }
+ if row, _ := capRow(t, fx, shop, capStorage); row.NoticeAt.IsZero() {
+ t.Fatal("the platform owner's delivered email recorded no notice")
+ }
+
+ // A platform with no owners here: the customer's owner still earns none.
+ orphan := testAccountID()
+ if _, err := fx.st.EnsureLinkedAccount(orphan, domains.Sqid(orphan), "orphan", "zzzz", "", strings.Repeat("ef", 16), time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ o, err := fx.st.AccountBySqid(domains.Sqid(orphan))
+ if err != nil || o == nil {
+ t.Fatal(o, err)
+ }
+ ost := storageOver(t, fx, o, time.Now().Add(-time.Hour))
+ customerOwnerSeesWarnings(t, fx, o, "orphanowner@example.com", "code-orphan-warn")
+ if err := fx.srv.notifyPlanOwners(ctx, o, []capState{ost}, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ if row, _ := capRow(t, fx, o, capStorage); !row.NoticeAt.IsZero() {
+ t.Fatalf("no platform owners, yet notice %v", row.NoticeAt)
+ }
+}