feat: localize license states and restore revoked licenses
Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
@@ -345,6 +345,15 @@ func (a *BusinessAPI) operateLicense(c *gin.Context, operation string) {
|
||||
apiError(c, 500, "internal_error", "撤销失败")
|
||||
return
|
||||
}
|
||||
} else if operation == "restore" {
|
||||
if rec.Status != "revoked" {
|
||||
apiError(c, 409, "invalid_state", "仅已撤销的授权可以恢复")
|
||||
return
|
||||
}
|
||||
if _, err = tx.ExecContext(c, "UPDATE licenses SET status='active',revoked_at=NULL WHERE id=?", id); err != nil {
|
||||
apiError(c, 500, "internal_error", "恢复失败")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if rec.Status == "revoked" || !expires.After(rec.ExpiresAt) {
|
||||
apiError(c, 400, "invalid_request", "续期时间必须晚于当前结束时间且授权未撤销")
|
||||
@@ -371,7 +380,9 @@ func (a *BusinessAPI) operateLicense(c *gin.Context, operation string) {
|
||||
if operation == "revoke" {
|
||||
rec.Status = "revoked"
|
||||
} else {
|
||||
rec.ExpiresAt = expires
|
||||
if operation == "renew" {
|
||||
rec.ExpiresAt = expires
|
||||
}
|
||||
rec.Status = currentLicenseStatus("active", rec.StartsAt, rec.ExpiresAt, time.Now().UTC())
|
||||
}
|
||||
c.JSON(200, gin.H{"data": rec, "idempotent_replay": false})
|
||||
|
||||
Reference in New Issue
Block a user