feat(backend): license entitlements, enforced limits, free tier
Platform v2 step 1.4 (APPS_PLATFORM D-3..D-6, D-21, §5). - core/modules/entitlements.py: compute() turns the evaluated license into per-module grants: the v2 token's `modules` map (own `exp` with the 5-day grace, never cut mid-service) + the free tier; no/invalid token, expired after grace, inactive, locked or clock tampering -> free tier only; core always. limit(module, name) with token value -> manifest licensed_default -> free value; None = unlimited. LICENSE_MODE=off (dev/test only) = everything - module gating says why: module.not_licensed (402, the first unlicensed module in the dependency chain) before module.disabled (403) - services/license.py accepts only v2 tokens with a modules map; the v1 "legacy unsigned 72h" path is gone - apply_license() always installs entitlements (startup before workers, every heartbeat, workday close); workers follow license changes - the global license middleware is deleted (no more whole-API 402/423); license_state moved to services/license_state.py - history_days enforced in every report/history endpoint: lower date bounds clamped (also when no "from" is given), and business days older than the limit refused by id (license.history_limited); data is never deleted - bootstrap/modules API show license mode, entitlement source and limit values - LICENSE_MODE=off in docker-compose.dev.yml and the e2e launchers; sites default to enforced - tests: entitlement rules, limits, the three done-when checks, signed-token apply_license path; license tests moved to v2 tokens Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""In-memory license status, shared by cloud_sync (writes), system/business-day routers (read).
|
||||
|
||||
Persisted to <data dir>/license_state.json by services/cloud_sync.py. What the site may
|
||||
USE is decided by core/modules/entitlements.py from the same evaluation; this dict is
|
||||
the status the manager's license page shows.
|
||||
|
||||
Fields:
|
||||
license_mode "enforced" | "off" (config LICENSE_MODE; "off" only on dev machines)
|
||||
licensed bool - the global license is valid (expiry/grace/lock deferred to
|
||||
the end of an open workday). False = the free tier applies.
|
||||
license_problem None | "unverified" | "expired" | "inactive" | "clock"
|
||||
entitlement_mode "licensed" | "free" | "dev" (from entitlements.compute)
|
||||
locked bool - remote lock enforced (applied at workday close)
|
||||
lock_pending bool - the cloud asked for a lock; waiting for the workday to close
|
||||
expires_at, days_until_expiry, grace_expires_at, grace_days_remaining, grace_over
|
||||
license_token the signed token as received (verified on every evaluation)
|
||||
last_sync, sync_failed, offline_days, time_high_water, latest_version,
|
||||
waiter_domain, site_numeric_id
|
||||
"""
|
||||
license_state: dict = {
|
||||
"license_mode": "enforced",
|
||||
"licensed": False,
|
||||
"license_problem": "unverified",
|
||||
"entitlement_mode": "free",
|
||||
"locked": False,
|
||||
"lock_pending": False,
|
||||
"expires_at": None,
|
||||
"days_until_expiry": None,
|
||||
"grace_expires_at": None,
|
||||
"last_sync": None,
|
||||
"sync_failed": False,
|
||||
"latest_version": None,
|
||||
}
|
||||
Reference in New Issue
Block a user