Phase 14, parts 5 and 6: seats, and moving down to Free
Seats: inviting past the seats paid for offers the owner to add one (Stripe prorates it); admins are told to ask the owner; Free has two. Moving down: past the plan's seats, the owner and one other (the owner's pick, or the first to join) edit and the rest read; storage is measured hourly, and past the plan's, photo uploads and the SEO crawl stop. Nothing is deleted. TEST.md section 18. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/appmail"
|
||||
@@ -44,6 +45,10 @@ type billingData struct {
|
||||
InvoiceErr string
|
||||
Yearly bool
|
||||
Problem string
|
||||
// More people than the plan's seats: who keeps editing (the owner
|
||||
// picks one), and the others the owner could pick.
|
||||
Kept map[int64]bool
|
||||
Others []users.TeamUser
|
||||
}
|
||||
|
||||
// people counts the team's people (not agents), invited ones too.
|
||||
@@ -88,6 +93,14 @@ func (s *Server) renderBilling(w http.ResponseWriter, r *http.Request, problem s
|
||||
}
|
||||
d.StorageOf = plan.StorageBytes(seats, a.StorageBlocks)
|
||||
d.Yearly = d.Paid.PriceYear != ""
|
||||
if d.Kept, _ = s.kept(); d.Kept != nil {
|
||||
list, _ := users.Members(s.platform(), s.team())
|
||||
for _, m := range list {
|
||||
if m.Kind == users.Person && m.Status != users.Disabled && m.Role != users.Owner {
|
||||
d.Others = append(d.Others, m)
|
||||
}
|
||||
}
|
||||
}
|
||||
if d.Owner && a.Customer != "" && a.Subscription != "" {
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
|
||||
d.Invoice, err = s.billingStripe().Upcoming(ctx, a.Customer)
|
||||
@@ -283,6 +296,12 @@ func (s *Server) billingTurn(ctx context.Context, now time.Time) {
|
||||
s.Log.Error("billing: saving", "team", a.Team, "err", err)
|
||||
}
|
||||
}
|
||||
if used, err := ts.measureStorage(ctx); err != nil {
|
||||
s.Log.Warn("billing: measuring storage", "team", a.Team, "err", err)
|
||||
} else if used != a.StorageUsed {
|
||||
a.StorageUsed = used
|
||||
save()
|
||||
}
|
||||
owner := ts.ownerOf()
|
||||
switch {
|
||||
case a.Status == billing.Trialing && a.Subscription == "" && !now.Before(a.TrialEnds):
|
||||
@@ -379,3 +398,38 @@ func (s *Server) lapseUndone(team int64, now time.Time) {
|
||||
s.Log.Error("billing: saving", "team", team, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
// billingKeep is the owner choosing who keeps editing when the team has
|
||||
// more people than its plan's seats.
|
||||
func (s *Server) billingKeep(w http.ResponseWriter, r *http.Request) {
|
||||
v := s.owner(w, r)
|
||||
if v == nil || !s.billingOn() {
|
||||
if v != nil {
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
return
|
||||
}
|
||||
id, _ := strconv.ParseInt(r.PostFormValue("user"), 10, 64)
|
||||
m, err := users.MembershipOf(s.platform(), s.team(), id)
|
||||
if err != nil || m.Role == users.Owner {
|
||||
s.renderBilling(w, r, "Choose someone in the team.")
|
||||
return
|
||||
}
|
||||
u, err := users.ByID(s.platform(), id)
|
||||
if err != nil || u.Kind != users.Person {
|
||||
s.renderBilling(w, r, "Choose someone in the team.")
|
||||
return
|
||||
}
|
||||
a, err := billing.Get(s.platform(), s.team())
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
a.KeptMember = id
|
||||
if err := billing.Save(s.platform(), a, time.Now()); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
s.audit(r, "billing-kept", u.Email, "keeps editing")
|
||||
redirect(w, r, "/settings/billing", "saved")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user