Phase 14, part 1: plans, each team's account, and their limits

The multi-tenant edition's plans (Free and Paid as decided, or a plans
file) and each team's billing account, with a 14-day trial of Paid. A
team's plan caps what its people and agents may change: modules outside it
stay readable, a lapsed team changes nothing, and agents, Market entries,
crawls and background jobs keep to it. Without a Stripe key, no billing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 13:15:00 -07:00
co-authored by Claude Opus 5.5
parent e47764a78e
commit a47990f9bf
19 changed files with 848 additions and 7 deletions
+21 -1
View File
@@ -7,6 +7,8 @@ import (
"net/http"
"regexp"
"strings"
"supermarket/internal/users"
)
// Who may reach what. Every route belongs to an area: a module, Settings
@@ -170,7 +172,25 @@ func (s *Server) allow(area string, next http.Handler) http.Handler {
s.toSignIn(w, r)
return
}
if !v.can(area, !safeMethod(r.Method)) {
write := !safeMethod(r.Method)
// A lapsed team changes nothing, but its billing, people's own
// accounts, and switching teams.
if v.ReadOnly && write && !strings.HasPrefix(r.URL.Path, "/settings/billing") &&
!platformPath(r.URL.Path) && !strings.HasPrefix(r.URL.Path, "/teams/") {
http.Error(w, sentence(errLapsed.Error())+".", http.StatusForbidden)
return
}
if !v.can(area, write) {
// A module the team's plan has only to read: say so.
if write && v.Member.Cap != nil && v.Member.Cap[area] == users.View && v.Member.Can(area, false) {
if ts, err := s.teamServer(r); err == nil {
if plan, _ := ts.teamPlan(); plan != nil {
http.Error(w, fmt.Sprintf("The %s plan doesn't include %s: what's there stays, to read. The team's owner can move up a plan under Settings → Billing.",
plan.Name, grantName(area)), http.StatusForbidden)
return
}
}
}
s.forbidden(w, r)
return
}