fix(license): 修复面板发放授权码无法激活(无环境配置时目录漏合并 DB 码)

This commit is contained in:
z.zhang 2026-10-23 00:45:11 +08:00
parent 68d8167b05
commit 8fb7054f4f
2 changed files with 18 additions and 0 deletions

View File

@ -359,6 +359,8 @@ class CodeLicenseProvider(LicenseProvider):
} }
configured = (os.environ.get("APS_LICENSE_CODES") or "").strip() configured = (os.environ.get("APS_LICENSE_CODES") or "").strip()
if not configured: if not configured:
# 无环境变量发码时也必须合并面板发放的 DB 授权码,否则新码无法激活
catalog.update(self._db_codes())
return catalog return catalog
try: try:
data = json.loads(configured) data = json.loads(configured)

View File

@ -270,6 +270,22 @@ def test_admin_issues_code_and_user_activates_with_name(codes_app):
assert entry["activation"]["status"] == "active" assert entry["activation"]["status"] == "active"
def test_panel_issued_code_activates_without_env_codes(codes_app, monkeypatch):
"""回归:未配置 APS_LICENSE_CODES 时,面板发放的 DB 授权码也必须可激活。"""
monkeypatch.delenv("APS_LICENSE_CODES", raising=False)
admin = _admin_client(codes_app)
created = admin.post("/api/admin/license/codes", json={
"name": "无环境配置", "licenseType": "year",
})
assert created.status_code == 200
issued = created.json()["code"]
user = TestClient(codes_app)
response = user.post("/api/auth/license/activate", json={"code": issued["code"]})
assert response.status_code == 200
assert response.json()["user"]["fullname"] == "无环境配置"
def test_non_admin_cannot_manage_codes(codes_app): def test_non_admin_cannot_manage_codes(codes_app):
user = TestClient(codes_app) user = TestClient(codes_app)
assert user.post("/api/auth/license/activate", json={"code": "USER-CODE-ALPHA"}).status_code == 200 assert user.post("/api/auth/license/activate", json={"code": "USER-CODE-ALPHA"}).status_code == 200