Quota management and Docker build workflow - #4
Conversation
Add comprehensive quota management system with per-user and per-domain quotas, SMTP delivery enforcement, and REST API endpoints for quota reporting and configuration. Create separate GitHub Actions workflow for building and pushing timestamped Docker images to Docker Hub supporting both amd64 and arm64. Changes: - New quota.go: GET/PUT endpoints for user and domain quotas - New internal/storage/imapsql/quota.go: CheckQuota enforcement logic - New internal/rest/model/quota.go: Quota response DTOs - New .github/workflows/docker-build.yml: Multi-platform Docker build workflow - Modified api.go: Added quota table initialization and routes - Modified delivery.go: Added quota checks in AddRcpt and Body methods - Updated CLAUDE.md and architecture.md: Documented quota tables and API Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. WalkthroughIntroduces a quota management system with REST API endpoints, database schema extensions, quota enforcement logic during SMTP delivery, HTTP handlers for get/set operations, and related data models. Also adds a Docker CI/CD workflow and documentation updates. Changes
Sequence DiagramssequenceDiagram
participant Client
participant API as API Handler
participant ImapSQL as imapsql.Storage
participant DB as Database
Client->>API: GET /v1/users/:id/quota
API->>ImapSQL: Query mailbox usage for user
ImapSQL->>DB: SELECT SUM(bodylen) FROM msgs GROUP BY mailbox
DB-->>ImapSQL: Usage per mailbox
ImapSQL-->>API: Usage data
API->>ImapSQL: Get user quota override
ImapSQL->>DB: SELECT quota_bytes FROM user_quotas WHERE username=:id
DB-->>ImapSQL: User quota (if exists)
ImapSQL-->>API: User quota
API->>ImapSQL: Get domain quota
ImapSQL->>DB: SELECT quota_bytes FROM domain_quotas WHERE domain=:domain
DB-->>ImapSQL: Domain quota (if exists)
ImapSQL-->>API: Domain quota
API->>API: Determine quota source & build response
API-->>Client: UserQuotaResponse (with mailbox breakdown)
sequenceDiagram
participant SMTP as SMTP Delivery
participant Storage as imapsql.Storage
participant Quota as CheckQuota
participant DB as Database
SMTP->>Storage: AddRcpt(recipient)
Storage->>Quota: CheckQuota(username, 0)
Quota->>DB: Get mailbox usage & quotas
DB-->>Quota: Usage + effective quota
alt Quota Exceeded
Quota-->>Storage: SMTPError 552
Storage-->>SMTP: Reject recipient
else Quota OK
Quota-->>Storage: nil
Storage-->>SMTP: Accept recipient
end
SMTP->>Storage: Body(message data)
Storage->>Quota: CheckQuota(username, message_size)
Quota->>DB: Get updated usage & quotas
DB-->>Quota: Usage + effective quota
alt Quota Would Exceed
Quota-->>Storage: SMTPError 552
Storage-->>SMTP: Fail delivery
else Within Quota
Quota-->>Storage: nil
Storage->>Storage: IMAP filter & store message
Storage-->>SMTP: Success
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro Cache: Disabled due to data retention organization setting Knowledge base: Disabled due to 📒 Files selected for processing (8)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.5.0)Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions 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. Comment |
Summary
Files Changed
New files: quota.go, internal/rest/model/quota.go, internal/storage/imapsql/quota.go, .github/workflows/docker-build.yml
Modified: api.go, delivery.go, CLAUDE.md, architecture.md
Implementation Details
Quota hierarchy: user_quotas > domain_quotas > unlimited (0). Quotas calculated using msgs.bodylen for storage usage. New tables created automatically on startup.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.