[PB-6473]: feat/set quota on provisioning#83
Conversation
|
Warning Review limit reached
Next review available in: 35 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughAccount provisioning now validates mail-plan access and storage quota, retrieves usage through the bridge client, and passes quota to the provider. The controller delegates entitlement checks to ChangesMail provisioning controls
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant UserController
participant AccountService
participant PaymentsService
participant BridgeClient
participant Provider
UserController->>AccountService: provisionAccount(...)
AccountService->>PaymentsService: getUserTier(userId)
AccountService->>BridgeClient: getUserUsage(userId)
PaymentsService-->>AccountService: tier features
BridgeClient-->>AccountService: usage snapshot
AccountService->>Provider: createAccount(..., quota)
Provider-->>AccountService: provisioned account
AccountService-->>UserController: account details
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
| this.payments.getUserTier(params.userId), | ||
| this.bridge.getUserUsage(params.userId), | ||
| this.domains.findByDomain(params.domain), | ||
| this.addresses.findByAddress(params.address), | ||
| this.accounts.findByUserId(params.userId), | ||
| ]); |
There was a problem hiding this comment.
Will need to cache these values if we're not doing it yet (in a near future).
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/modules/infrastructure/bridge/bridge.service.ts`:
- Around line 55-79: Remove one of the duplicate getUserUsage method definitions
from the bridge service class, retaining a single implementation with the
existing request, error handling, and JSON parsing behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7c7788a0-9c73-4125-b8ad-2487b1bc3df8
📒 Files selected for processing (6)
src/modules/account/account.service.spec.tssrc/modules/account/account.service.tssrc/modules/account/user.controller.spec.tssrc/modules/account/user.controller.tssrc/modules/infrastructure/bridge/bridge.service.spec.tssrc/modules/infrastructure/bridge/bridge.service.ts
| async getUserUsage(userUuid: string): Promise<UserSpaceSnapshot> { | ||
| const token = this.signGatewayToken(userUuid); | ||
|
|
||
| const { statusCode, body } = await this.httpClient.request({ | ||
| method: 'GET', | ||
| path: `${this.basePath}/v2/gateway/users/${encodeURIComponent(userUuid)}/usage`, | ||
| headers: { | ||
| accept: 'application/json', | ||
| authorization: `Bearer ${token}`, | ||
| }, | ||
| }); | ||
|
|
||
| const text = await body.text(); | ||
|
|
||
| if (statusCode !== 200) { | ||
| throw new BridgeApiError( | ||
| `Failed to get storage usage for user '${userUuid}': HTTP ${statusCode}`, | ||
| statusCode, | ||
| text, | ||
| ); | ||
| } | ||
|
|
||
| return JSON.parse(text) as UserSpaceSnapshot; | ||
| } | ||
|
|
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Remove duplicate method definition.
The method getUserUsage is defined twice in this class (here at lines 55-79 and again at lines 190-213). This causes a duplicate identifier compilation error in TypeScript. Please remove one of the duplicate definitions.
🐛 Proposed fix to remove the duplicate method
- async getUserUsage(userUuid: string): Promise<UserSpaceSnapshot> {
- const token = this.signGatewayToken(userUuid);
-
- const { statusCode, body } = await this.httpClient.request({
- method: 'GET',
- path: `${this.basePath}/v2/gateway/users/${encodeURIComponent(userUuid)}/usage`,
- headers: {
- accept: 'application/json',
- authorization: `Bearer ${token}`,
- },
- });
-
- const text = await body.text();
-
- if (statusCode !== 200) {
- throw new BridgeApiError(
- `Failed to get storage usage for user '${userUuid}': HTTP ${statusCode}`,
- statusCode,
- text,
- );
- }
-
- return JSON.parse(text) as UserSpaceSnapshot;
- }
-📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| async getUserUsage(userUuid: string): Promise<UserSpaceSnapshot> { | |
| const token = this.signGatewayToken(userUuid); | |
| const { statusCode, body } = await this.httpClient.request({ | |
| method: 'GET', | |
| path: `${this.basePath}/v2/gateway/users/${encodeURIComponent(userUuid)}/usage`, | |
| headers: { | |
| accept: 'application/json', | |
| authorization: `Bearer ${token}`, | |
| }, | |
| }); | |
| const text = await body.text(); | |
| if (statusCode !== 200) { | |
| throw new BridgeApiError( | |
| `Failed to get storage usage for user '${userUuid}': HTTP ${statusCode}`, | |
| statusCode, | |
| text, | |
| ); | |
| } | |
| return JSON.parse(text) as UserSpaceSnapshot; | |
| } |
🧰 Tools
🪛 GitHub Actions: Pre build ( Health check ) / 0_build (24.x).txt
[error] 55-55: TypeScript (TS2393) Duplicate function implementation. async getUserUsage(userUuid: string): Promise is implemented more than once.
🪛 GitHub Actions: Pre build ( Health check ) / build (24.x)
[error] 55-55: TS2393: Duplicate function implementation. Function 'getUserUsage(userUuid: string): Promise' is implemented more than once.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/modules/infrastructure/bridge/bridge.service.ts` around lines 55 - 79,
Remove one of the duplicate getUserUsage method definitions from the bridge
service class, retaining a single implementation with the existing request,
error handling, and JSON parsing behavior.
bec8f57 to
536a40d
Compare
|



Set a user's quota right on account provisioning, otherwise an account is left as unlimited and the user's stalwart quota would be reported back as 0
Summary by CodeRabbit
New Features
Bug Fixes