feat(pruefwerk): entry plan sends extra_targets 0
The entry plan (CRA-CSA-CLD-EIN) refuses targets beyond the included ones: the entitlement check now sends extra_targets 0 for it, which Prüfwerk turns into 409 target_limit when a target would be added. Standard, Business and Enterprise send no extra_targets, so extras stay allowed and billed; a key left in a grant's config is dropped, the plan decides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
17bffab165
commit
2fcfaaff02
3 files changed
+28
-8
No files matched your search
@@ -35,11 +35,14 @@ import (
|
||||
const pruefwerkProduct = "pruefwerk"
|
||||
|
||||
// Limit keys of the entitlement check, always sent for Prüfwerk; null is
|
||||
// unlimited (no cap set).
|
||||
// unlimited (no cap set). limitExtraTargets is sent only by a plan without
|
||||
// extra targets (0: Prüfwerk refuses a new target beyond included_targets
|
||||
// with 409 target_limit); missing, Prüfwerk allows extras and bills them.
|
||||
const (
|
||||
limitIncludedTargets = "included_targets"
|
||||
limitMonthlyPruefungen = "monthly_pruefungen"
|
||||
limitPrueftagCap = "prueftag_cap"
|
||||
limitExtraTargets = "extra_targets"
|
||||
)
|
||||
|
||||
// maxPrueftagCap bounds the cap a workspace can set.
|
||||
@@ -47,7 +50,8 @@ const maxPrueftagCap = 10000
|
||||
|
||||
// pruefwerkPlan is one Prüfwerk plan, identified by its subscription SKU.
|
||||
// Unlimited: no target or Prüfung limit and no Prüftag cap. NoPrueftage:
|
||||
// the Prüftag cap is always 0, whatever the workspace saved.
|
||||
// the Prüftag cap is always 0, whatever the workspace saved. NoExtraTargets:
|
||||
// no target beyond the included ones (extra_targets 0).
|
||||
type pruefwerkPlan struct {
|
||||
Name string
|
||||
SKU string
|
||||
@@ -55,6 +59,7 @@ type pruefwerkPlan struct {
|
||||
MonthlyPruefungen int
|
||||
Unlimited bool
|
||||
NoPrueftage bool
|
||||
NoExtraTargets bool
|
||||
}
|
||||
|
||||
// capApplies reports whether the workspace's saved Prüftag cap is the one
|
||||
@@ -75,8 +80,8 @@ var pruefwerkPlans = []pruefwerkPlan{
|
||||
// grant the plan with POST /v1/admin/tenants/{id}/entry-offer; it is not a
|
||||
// subscription and never comes from the ERP.
|
||||
//
|
||||
// The plan has no monthly quota and no Prüftage, so nothing beyond the
|
||||
// order can be used or billed: the scans staff start for the delivery are
|
||||
// The plan has no monthly quota, no Prüftage and no extra targets, so
|
||||
// nothing beyond the order can be used or billed: the scans staff start for the delivery are
|
||||
// support scans, which never count; change-driven scans of the included
|
||||
// targets do not count either. The included targets are the order's
|
||||
// (entryTargetsMax at most), set per grant in config["included_targets"].
|
||||
@@ -91,7 +96,7 @@ const (
|
||||
|
||||
// pruefwerkEntryPlan is the entry plan with one included target; the grant's
|
||||
// config sets the order's number (pruefwerkPlanOfConfig).
|
||||
var pruefwerkEntryPlan = pruefwerkPlan{Name: "einstieg", SKU: entryPlanSKU, IncludedTargets: 1, MonthlyPruefungen: 0, NoPrueftage: true}
|
||||
var pruefwerkEntryPlan = pruefwerkPlan{Name: "einstieg", SKU: entryPlanSKU, IncludedTargets: 1, MonthlyPruefungen: 0, NoPrueftage: true, NoExtraTargets: true}
|
||||
|
||||
// pruefwerkPlanFor resolves the plan from tenant_products.config["skus"]:
|
||||
// []string as recomputeEntitlements writes it, []interface{} once it has
|
||||
@@ -176,12 +181,17 @@ func pruefwerkLimits(cfg map[string]interface{}, prueftagCap *int) map[string]in
|
||||
out[k] = v
|
||||
}
|
||||
plan := pruefwerkPlanOfConfig(cfg)
|
||||
// The plan decides, not a key left in the grant's config.
|
||||
delete(out, limitExtraTargets)
|
||||
if plan.Unlimited {
|
||||
out[limitIncludedTargets], out[limitMonthlyPruefungen], out[limitPrueftagCap] = nil, nil, nil
|
||||
return out
|
||||
}
|
||||
out[limitIncludedTargets] = plan.IncludedTargets
|
||||
out[limitMonthlyPruefungen] = plan.MonthlyPruefungen
|
||||
if plan.NoExtraTargets {
|
||||
out[limitExtraTargets] = 0
|
||||
}
|
||||
if plan.NoPrueftage {
|
||||
out[limitPrueftagCap] = 0
|
||||
} else {
|
||||
|
||||
@@ -245,8 +245,15 @@ func TestPruefwerkLimitsEntry(t *testing.T) {
|
||||
cfg["included_targets"] = c.targets
|
||||
}
|
||||
got := pruefwerkLimits(cfg, c.cap)
|
||||
if got[limitIncludedTargets] != c.want || got[limitMonthlyPruefungen] != 0 || got[limitPrueftagCap] != 0 {
|
||||
t.Errorf("%s: %v / %v / %v, want %d / 0 / 0", c.name, got[limitIncludedTargets], got[limitMonthlyPruefungen], got[limitPrueftagCap], c.want)
|
||||
if got[limitIncludedTargets] != c.want || got[limitMonthlyPruefungen] != 0 || got[limitPrueftagCap] != 0 || got[limitExtraTargets] != 0 {
|
||||
t.Errorf("%s: %v / %v / %v / %v, want %d / 0 / 0 / 0", c.name, got[limitIncludedTargets], got[limitMonthlyPruefungen], got[limitPrueftagCap], got[limitExtraTargets], c.want)
|
||||
}
|
||||
}
|
||||
// The paid plans keep billing extras: no extra_targets, even one left in the config.
|
||||
for _, sku := range []string{"CRA-CSA-CLD-STD", "CRA-CSA-CLD-BUS", "CRA-CSA-CLD-ENT", ""} {
|
||||
got := pruefwerkLimits(map[string]interface{}{"skus": []string{sku}, limitExtraTargets: 0}, nil)
|
||||
if _, ok := got[limitExtraTargets]; ok {
|
||||
t.Errorf("%q sends extra_targets: %v", sku, got[limitExtraTargets])
|
||||
}
|
||||
}
|
||||
if p := pruefwerkPlanOfConfig(map[string]interface{}{"skus": []string{"CRA-CSA-CLD-EIN"}}); p.capApplies() {
|
||||
|
||||
+4
-1
@@ -2895,7 +2895,10 @@ components:
|
||||
Business 25/500, Enterprise null; no plan SKU counts as Standard)
|
||||
and `prueftag_cap` (the workspace's monthly cap on Prüftage,
|
||||
null when none is set and always null on Enterprise). null means
|
||||
unlimited.
|
||||
unlimited. The entry plan (CRA-CSA-CLD-EIN) also sends
|
||||
`extra_targets: 0` (no target beyond the included ones, with
|
||||
`monthly_pruefungen` 0 and `prueftag_cap` 0); without the key,
|
||||
extra targets are allowed and billed.
|
||||
expires_at: { type: string, format: date-time, nullable: true }
|
||||
reason: { type: string, enum: [unknown_product, unknown_addon, tenant_not_found, tenant_archived, tenant_halted, entitlement_disabled, entitlement_expired, preview_expired, addon_not_purchased, not_entitled, member_blocked, user_unknown] }
|
||||
preview: { type: boolean, description: "allowed through a staff preview grant; usage under it is not invoiced" }
|
||||
|
||||
Reference in new issue
Block a user