Skip to content

[PB-6473]: feat/set quota on provisioning#83

Merged
jzunigax2 merged 4 commits into
masterfrom
feat/set-quota-on-provisioning
Jul 18, 2026
Merged

[PB-6473]: feat/set quota on provisioning#83
jzunigax2 merged 4 commits into
masterfrom
feat/set-quota-on-provisioning

Conversation

@jzunigax2

@jzunigax2 jzunigax2 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

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

    • Mail account provisioning and additional address creation now respect plan permissions and available storage.
    • New accounts are assigned storage quotas based on the user’s plan.
    • Storage usage can be retrieved to support accurate quota validation.
  • Bug Fixes

    • Clear errors are returned when mail access is unavailable or storage capacity is insufficient.
    • Failed address setup now properly rolls back related provisioning changes.

@jzunigax2
jzunigax2 requested a review from xabg2 July 3, 2026 03:54
@jzunigax2 jzunigax2 self-assigned this Jul 3, 2026
@jzunigax2 jzunigax2 added the enhancement New feature or request label Jul 3, 2026
@jzunigax2
jzunigax2 marked this pull request as draft July 9, 2026 01:02
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jzunigax2, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 35 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a99bdbbf-eabd-4d5a-9614-32f16610801e

📥 Commits

Reviewing files that changed from the base of the PR and between bec8f57 and 536a40d.

📒 Files selected for processing (5)
  • src/modules/account/account.service.spec.ts
  • src/modules/account/account.service.ts
  • src/modules/account/user.controller.spec.ts
  • src/modules/account/user.controller.ts
  • src/modules/infrastructure/bridge/bridge.service.spec.ts
📝 Walkthrough

Walkthrough

Account 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 AccountService, while tests cover success, rejection, rollback, and bridge API errors.

Changes

Mail provisioning controls

Layer / File(s) Summary
Bridge usage API
src/modules/infrastructure/bridge/bridge.service.ts, src/modules/infrastructure/bridge/bridge.service.spec.ts
Adds authenticated user-usage retrieval, response parsing, error handling, and tests.
Account provisioning gating
src/modules/account/account.service.ts, src/modules/account/account.service.spec.ts
Validates mail availability and storage quota for account and address provisioning, passes quota to the provider, and adds success and rejection coverage.
Controller provisioning delegation
src/modules/account/user.controller.ts, src/modules/account/user.controller.spec.ts
Removes controller-level tier checks and the PaymentsService dependency, delegating provisioning to AccountService.

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
Loading

Possibly related PRs

Suggested reviewers: xabg2

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: adding quota assignment during provisioning.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/set-quota-on-provisioning

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.

@jzunigax2
jzunigax2 marked this pull request as ready for review July 13, 2026 22:30
Comment on lines +175 to +180
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),
]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need to cache these values if we're not doing it yet (in a near future).

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4592c3c and bec8f57.

📒 Files selected for processing (6)
  • src/modules/account/account.service.spec.ts
  • src/modules/account/account.service.ts
  • src/modules/account/user.controller.spec.ts
  • src/modules/account/user.controller.ts
  • src/modules/infrastructure/bridge/bridge.service.spec.ts
  • src/modules/infrastructure/bridge/bridge.service.ts

Comment on lines +55 to +79
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;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Suggested change
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.

@jzunigax2
jzunigax2 force-pushed the feat/set-quota-on-provisioning branch from bec8f57 to 536a40d Compare July 18, 2026 01:23
@sonarqubecloud

Copy link
Copy Markdown

@jzunigax2
jzunigax2 merged commit b2fe966 into master Jul 18, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants