Skip to content

merge - #3123

Closed
SwallOwDili wants to merge 4 commits into
QuantumNous:mainfrom
SwallOwDili:main
Closed

merge#3123
SwallOwDili wants to merge 4 commits into
QuantumNous:mainfrom
SwallOwDili:main

Conversation

@SwallOwDili

@SwallOwDili SwallOwDili commented Mar 5, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features

    • Added support for multiple redemption code types: balance recharge, subscription plan activation, and combo (balance + subscription).
    • Implemented subscription group restrictions to limit plan access by user groups.
    • Added Docker deployment support with multi-architecture builds and container registry integration.
    • Enabled multi-instance rolling deployment with automated health checks.
  • Improvements

    • Enhanced redemption UI with type selection and plan configuration.
    • Added subscription purchase limits and related error messaging.
    • Expanded internationalization with new translations.

SwallOwDili and others added 4 commits February 13, 2026 17:29
- 兑换码新增订阅套餐类型,支持通过兑换码激活订阅
- 添加 push 触发的 Docker 镜像构建 workflow (GHCR)
- 添加部署脚本、nginx 配置和部署文档
- 更新 docker-compose 配置

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 套餐支持配置 allowed_groups,限制用户仅能使用指定分组
- 创建/更新套餐时校验分组存在,API 请求时校验分组在允许列表
- 明确分组与 auto 选组后均校验;仅在有生效订阅且套餐配置限制时生效
- 套餐缓存 TTL 默认 30 分钟,创建/更新/状态变更后失效;事务内不写缓存
- 管理端与购买弹窗展示限制分组,多语言错误提示与 i18n

Made-with: Cursor
@SwallOwDili SwallOwDili closed this Mar 5, 2026
@coderabbitai

coderabbitai Bot commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9b605fde-43c5-4cc4-babd-c690929d41fa

📥 Commits

Reviewing files that changed from the base of the PR and between 887a929 and a83836d.

📒 Files selected for processing (40)
  • .dockerignore
  • .github/workflows/docker-image-push.yml
  • DOCKER_DEPLOYMENT.md
  • SUBSCRIPTION_GROUP_RESTRICTION.md
  • VERSION
  • common/constants.go
  • controller/redemption.go
  • controller/subscription.go
  • controller/user.go
  • deploy.sh
  • docker-compose.test.yml
  • docker-compose.yml
  • docs/deploy/01-ddl-changes.sql
  • docs/deploy/02-backup.sql
  • docs/deploy/03-release-plan.md
  • i18n/i18n.go
  • i18n/keys.go
  • i18n/locales/en.yaml
  • i18n/locales/zh-CN.yaml
  • i18n/locales/zh-TW.yaml
  • middleware/distributor.go
  • model/main.go
  • model/redemption.go
  • model/redemption_group_test.go
  • model/subscription.go
  • model/subscription_group_restriction_test.go
  • model/subscription_group_test.go
  • model/test_helpers_test.go
  • model/user.go
  • nginx.conf
  • web/src/components/table/redemptions/RedemptionsColumnDefs.jsx
  • web/src/components/table/redemptions/modals/EditRedemptionModal.jsx
  • web/src/components/table/subscriptions/modals/AddEditSubscriptionModal.jsx
  • web/src/components/topup/RechargeCard.jsx
  • web/src/components/topup/SubscriptionPlansCard.jsx
  • web/src/components/topup/index.jsx
  • web/src/components/topup/modals/SubscriptionPurchaseModal.jsx
  • web/src/i18n/locales/en.json
  • web/src/i18n/locales/zh-CN.json
  • web/src/i18n/locales/zh-TW.json

Walkthrough

This PR introduces two interconnected features: multi-type redemption code support (balance, subscription, combo) and per-subscription group restrictions. It includes database schema changes, backend validation and caching logic, middleware enforcement of group restrictions, frontend UI updates for managing redemptions and subscription plans, and deployment/Docker infrastructure changes with multi-instance support.

Changes

Cohort / File(s) Summary
Docker & Deployment Infrastructure
.dockerignore, .github/workflows/docker-image-push.yml, docker-compose.yml, docker-compose.test.yml, nginx.conf, deploy.sh
Added multi-architecture Docker build workflow, restructured Docker Compose to support two API instances with rolling updates, new Nginx config for load balancing across instances, and rolling deployment script with health checks.
Database Migrations & Documentation
docs/deploy/01-ddl-changes.sql, docs/deploy/02-backup.sql, docs/deploy/03-release-plan.md, DOCKER_DEPLOYMENT.md, SUBSCRIPTION_GROUP_RESTRICTION.md, VERSION
Added DDL migrations for redemptions table (type, subscription_plan_id columns) and subscription_plans (allowed_groups), backup/verification SQL, and comprehensive deployment and feature documentation.
Redemption Code Type Support
common/constants.go, controller/redemption.go, model/redemption.go
Introduced three redemption types (quota, subscription, combo), validation of type and subscription_plan_id, and refactored Redeem flow to return RedeemResult with support for subscription activation paths.
Subscription Plan Group Restrictions
controller/subscription.go, model/subscription.go, middleware/distributor.go
Added allowed_groups field to subscription plans with validation, group resolution helpers (resolveUserGroupBySubscriptions, applyResolvedUserGroup), and runtime enforcement in middleware with 403 responses when group restrictions are violated.
User Model & Grouping
model/user.go, model/main.go
Added BaseLevel field to User for tracking base group level when not under subscription upgrades.
Test Infrastructure
model/test_helpers_test.go, model/redemption_group_test.go, model/subscription_group_test.go, model/subscription_group_restriction_test.go
Comprehensive test helpers for database setup/teardown and new test suites covering redemption types with upgrade groups, subscription group resolution logic, and allowed_groups parsing/membership.
i18n & Localization
i18n/i18n.go, i18n/keys.go, i18n/locales/en.yaml, i18n/locales/zh-CN.yaml, i18n/locales/zh-TW.yaml, web/src/i18n/locales/en.json, web/src/i18n/locales/zh-CN.json, web/src/i18n/locales/zh-TW.json
Added translation keys for subscription purchase limits, group restriction errors, and redemption type labels; changed default language fallback to Simplified Chinese.
Frontend - Redemption Management
web/src/components/table/redemptions/RedemptionsColumnDefs.jsx, web/src/components/table/redemptions/modals/EditRedemptionModal.jsx
Added type column with upgrade group context, dynamic form fields for subscription plan selection and upgrade group configuration based on redemption type, auto-generated names for different redemption types.
Frontend - Subscription Plan Management
web/src/components/table/subscriptions/modals/AddEditSubscriptionModal.jsx, web/src/components/topup/SubscriptionPlansCard.jsx, web/src/components/topup/modals/SubscriptionPurchaseModal.jsx
Added allowed_groups multi-select field to plan creation/editing, display of restricted groups in plan cards and purchase modals with "限制分组" indicator.
Frontend - Top-up & Recharge
web/src/components/topup/index.jsx, web/src/components/topup/RechargeCard.jsx, controller/user.go
Updated success flow to branch on redemption type (quota vs. subscription), added new subscription activation modal path, updated recharge text to reflect multi-type support, added error handling for subscription purchase limits.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Frontend
    participant Controller
    participant Model
    participant Database

    User->>Frontend: Enter redemption code
    Frontend->>Controller: POST /topup (redemption key)
    Controller->>Model: Redeem(key, userId)
    
    Model->>Database: Fetch redemption by key
    Database-->>Model: Redemption record (type, subscription_plan_id, upgrade_group)
    
    alt Type = 1 (Quota)
        Model->>Database: Update user quota
        Model-->>Controller: RedeemResult{Quota, Type=1}
    else Type = 2 (Subscription)
        Model->>Database: Fetch subscription plan
        Model->>Database: Create subscription record
        Model->>Database: Apply resolved user group
        Model-->>Controller: RedeemResult{Type=2, PlanTitle}
    else Type = 3 (Combo)
        Model->>Database: Update user quota
        Model->>Database: Create subscription record
        Model->>Database: Apply resolved user group
        Model-->>Controller: RedeemResult{Quota, Type=3, PlanTitle}
    end
    
    Controller-->>Frontend: RedeemResult response
    
    alt Type = 2
        Frontend->>User: Show subscription activation modal
    else Other
        Frontend->>User: Show quota update success modal
        Frontend->>User: Increment displayed quota
    end
Loading
sequenceDiagram
    participant User
    participant Middleware
    participant Model
    participant Database
    participant API

    User->>Middleware: API request with group
    Middleware->>Model: GetUserActiveSubscriptionPlan(userId)
    Model->>Database: Fetch active subscription for user
    Database-->>Model: SubscriptionPlan{allowed_groups}
    
    alt allowed_groups is not empty
        Middleware->>Model: IsGroupAllowed(group)
        
        alt Group is in allowed_groups
            Model-->>Middleware: true
            Middleware->>API: Pass request through
            API-->>User: Success response
        else Group is NOT allowed
            Model-->>Middleware: false
            Middleware-->>User: 403 Forbidden (group restriction error)
        end
    else allowed_groups is empty (no restriction)
        Middleware->>API: Pass request through
        API-->>User: Success response
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • Calcium-Ion
  • seefs001

Poem

🐰 Hopping through redemption types with glee,
Subscriptions now restrict by group decree,
Balance and upgrades in harmony dance,
Multi-arch Docker steps forward—what a chance!
Base levels and caches, all set just right,
This feature release shines oh so bright!

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant