Skip to content

[PB-5977]: feat/integrate MailService for downgrade and upgrade handling#375

Open
jzunigax2 wants to merge 2 commits into
masterfrom
feat/mail-upgrade-and-downgrade-handling
Open

[PB-5977]: feat/integrate MailService for downgrade and upgrade handling#375
jzunigax2 wants to merge 2 commits into
masterfrom
feat/mail-upgrade-and-downgrade-handling

Conversation

@jzunigax2

@jzunigax2 jzunigax2 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Calls the new mail-server gateway suspend/reactivate endpoints so a user's mail account follows their plan state.

  • Reactivate on invoice.paid: InvoiceCompletedHandler calls applyMailFeatures after Drive/VPN, gated on featuresPerService[Service.Mail].enabled.
  • Suspend on plan cancellation/downgrade: TiersService.removeTier now handles case Service.Mail reached via handleCancelPlan.

⚠️ Introduces new env variables:

  • MAIL_URL: base URL of the mail-server gateway
  • MAIL_GATEWAY_SECRET: matching RSA key pair from mail's GATEWAY_PUBLIC_SECRET variable

- Added MailService to handle account suspension and reactivation.
- Updated .env.template to include MAIL_URL and MAIL_GATEWAY_SECRET.
- Modified TiersService to apply and remove mail features based on user tiers.
- Enhanced InvoiceCompletedHandler to apply mail features upon invoice completion.
- Introduced tests for MailService and updated TiersService tests to cover mail feature logic.
@jzunigax2 jzunigax2 requested a review from xabg2 June 22, 2026 05:22
@jzunigax2 jzunigax2 self-assigned this Jun 22, 2026
@jzunigax2 jzunigax2 added the enhancement New feature or request label Jun 22, 2026

async reactivateAccount(payload: { customerId: string }): Promise<void> {
const jwt = signToken('5m', this.config.OBJECT_STORAGE_GATEWAY_SECRET);
const jwt = signGatewayToken('5m', this.config.OBJECT_STORAGE_GATEWAY_SECRET);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🚀

Comment thread tests/src/services/mail.service.test.ts Outdated
};

describe('suspendAccount', () => {
it('When called, then it POSTs to the suspend gateway endpoint with the signed token', async () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Use test instead of it

});

describe('Enable Mail access based on user tier', () => {
it('When Mail is enabled, then a request to reactivate the mail account is sent', async () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
83.3% Coverage on New Code (required ≥ 85%)

See analysis details on SonarQube Cloud

@jzunigax2 jzunigax2 marked this pull request as ready for review June 30, 2026 13:22
@jzunigax2 jzunigax2 requested a review from sg-gs as a code owner June 30, 2026 13:22
@jzunigax2 jzunigax2 requested a review from xabg2 June 30, 2026 13:22
Comment thread src/utils/signGatewayToken.ts
) {}

async suspendAccount(uuid: User['uuid']): Promise<void> {
await this.axios.post(`${this.config.MAIL_URL}/gateway/accounts/${uuid}/suspend`, {}, this.requestConfig());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is related to mail, not to here, but, shouldn't this be a PATCH as it is a partial update of the user enabled status field or so?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It also disables some mail features (e.g. disable send emails, update emails and destroy emails), not just updating a status field. Not sure if PATCH is better. POST is also accepted, don't you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

plus a post feels more appropiate to me as its an explicit action /resource/id/suspend, don't you think?

@sg-gs

sg-gs commented Jun 30, 2026

Copy link
Copy Markdown
Member

Please @jzunigax2 on any PR that needs new environment variables: add a warning to the PR's description. Otherwise, I may ignore it and cause a downtime

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

Labels

enhancement New feature or request ready-for-preview

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants