fix
This commit is contained in:
@@ -602,6 +602,9 @@ func (s *Service) EnsureDefaultPlans(ctx context.Context) error {
|
||||
if err := s.EnsureDefaultFeatureSeeds(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.EnsureSuperAdminPlan(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.EnsurePlanCatalogHygiene(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package billing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
// SuperAdminPlanName is an internal assignable plan: every dashboard feature ON,
|
||||
// unlimited SKUs, and the Enterprise-sized credit grant. Not on the public ladder.
|
||||
const SuperAdminPlanName = "Super Admin"
|
||||
|
||||
// IsSuperAdminPlan reports the fully unlocked internal plan (assign via admin billing).
|
||||
func IsSuperAdminPlan(name string) bool {
|
||||
return strings.EqualFold(strings.TrimSpace(name), SuperAdminPlanName)
|
||||
}
|
||||
|
||||
// EnsureSuperAdminPlan upserts the Super Admin plan row (is_custom=true → enable-all features).
|
||||
func (s *Service) EnsureSuperAdminPlan(ctx context.Context) error {
|
||||
if s == nil || s.Pool == nil {
|
||||
return errors.New("billing service unavailable")
|
||||
}
|
||||
desc := "Internal unlock — every feature enabled, unlimited SKUs, large AI grant (not sold publicly)"
|
||||
var id int64
|
||||
err := s.Pool.QueryRow(ctx, `
|
||||
SELECT id FROM plans WHERE lower(name) = lower($1) ORDER BY id LIMIT 1`,
|
||||
SuperAdminPlanName).Scan(&id)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
_, err = s.Pool.Exec(ctx, `
|
||||
INSERT INTO plans (name, description, monthly_credits, yearly_credits, max_products, is_custom, term)
|
||||
VALUES ($1, $2, $3, NULL, NULL, true, 'monthly')`,
|
||||
SuperAdminPlanName, desc, EnterpriseUnlimitedCredits)
|
||||
return err
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = s.Pool.Exec(ctx, `
|
||||
UPDATE plans SET description = $2, monthly_credits = $3, max_products = NULL,
|
||||
is_custom = true, term = 'monthly', updated_at = now()
|
||||
WHERE id = $1`, id, desc, EnterpriseUnlimitedCredits)
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package billing
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestIsSuperAdminPlan(t *testing.T) {
|
||||
t.Parallel()
|
||||
if !IsSuperAdminPlan("Super Admin") || !IsSuperAdminPlan("super admin") {
|
||||
t.Fatal("expected Super Admin name match")
|
||||
}
|
||||
if IsSuperAdminPlan("Enterprise") || IsSuperAdminPlan("") {
|
||||
t.Fatal("Enterprise / empty must not match Super Admin")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSuperAdminPlanNotPublic(t *testing.T) {
|
||||
t.Parallel()
|
||||
if IsPublicProductPlan(SuperAdminPlanName) {
|
||||
t.Fatal("Super Admin must stay off the public pricing ladder")
|
||||
}
|
||||
if !IsCustomPackage(SuperAdminPlanName, true) {
|
||||
t.Fatal("Super Admin with is_custom must unlock via custom package defaults")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user