Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HSB-439 feature: invite link with SMTP optional #4078

Open
wants to merge 11 commits into
base: next
Choose a base branch
from

Conversation

mirarifhasan
Copy link
Contributor

@mirarifhasan mirarifhasan commented May 20, 2024

Closes HSB-439

Description

This PR

  • Makes mailer-module optional
  • Makes mailer-module more configurable

Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

Additional Information

Nil

@mirarifhasan mirarifhasan requested a review from balub May 20, 2024 17:48
@mirarifhasan mirarifhasan self-assigned this May 20, 2024
@mirarifhasan mirarifhasan changed the base branch from main to next May 21, 2024 14:31
@mirarifhasan mirarifhasan marked this pull request as ready for review May 21, 2024 14:31
@mirarifhasan mirarifhasan changed the title HSB-43 feature: invite link with SMTP optional HSB-439 feature: invite link with SMTP optional May 27, 2024
.env.example Show resolved Hide resolved
.env.example Outdated Show resolved Hide resolved
.env.example Outdated Show resolved Hide resolved
@@ -42,6 +46,8 @@ export class MailerService {
to: string,
mailDesc: MailDescription | UserMagicLinkMailDescription,
) {
if (this.configService.get('INFRA.MAILER_SMTP_ENABLE') !== 'true') return;
Copy link
Member

Choose a reason for hiding this comment

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

We can throw an error here right saying "SMTP_NOT_ENABLED" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we using event emit, throwing errors is not effective.

@@ -64,6 +70,8 @@ export class MailerService {
to: string,
mailDesc: AdminUserInvitationMailDescription,
) {
if (this.configService.get('INFRA.MAILER_SMTP_ENABLE') !== 'true') return;
Copy link
Member

Choose a reason for hiding this comment

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

Same here too.

Comment on lines 25 to 53
// If mailer SMTP is DISABLED, return the module without any configuration (service, listener, etc.)
if (env.INFRA.MAILER_SMTP_ENABLE !== 'true') {
console.log('Mailer SMTP is disabled');
return { module: MailerModule };
}

// If mailer is ENABLED, return the module with configuration (service, listener, etc.)
let transportOption: TransportType;

const mailerAddressFrom =
env.INFRA.MAILER_ADDRESS_FROM ??
config.get('MAILER_ADDRESS_FROM') ??
throwErr(MAILER_SMTP_URL_UNDEFINED);

if (
(env.INFRA.MAILER_USE_ADVANCE_CONFIGS ??
config.get('MAILER_USE_ADVANCE_CONFIGS')) === 'false'
) {
console.log('Using simple mailer configuration');

transportOption =
env.INFRA.MAILER_SMTP_URL ??
config.get('MAILER_SMTP_URL') ??
throwErr(MAILER_SMTP_URL_UNDEFINED);
} else if (
(env.INFRA.MAILER_USE_ADVANCE_CONFIGS ??
config.get('MAILER_USE_ADVANCE_CONFIGS')) === 'true'
) {
console.log('Using advance mailer configuration');
Copy link
Member

Choose a reason for hiding this comment

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

Can you simplify this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll split this into different functions.

.env.example Outdated
Comment on lines 44 to 49
MAILER_SMTP_HOST="smtp.domain.com" # if MAILER_USE_ADVANCE_CONFIGS is false
MAILER_SMTP_PORT="587" # if MAILER_USE_ADVANCE_CONFIGS is false
MAILER_SMTP_SECURE="true" # if MAILER_USE_ADVANCE_CONFIGS is false
MAILER_SMTP_USER="user@domain.com" # if MAILER_USE_ADVANCE_CONFIGS is false
MAILER_SMTP_PASSWORD="pass" # if MAILER_USE_ADVANCE_CONFIGS is false
MAILER_TLS_REJECT_UNAUTHORIZED="true" # if MAILER_USE_ADVANCE_CONFIGS is false
Copy link
Member

Choose a reason for hiding this comment

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

Do all these have to be strings, can some of them normal booleans and numbers and we do a toString() conversion in the infra-config module anyway??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The default behavior is process.env always reads the env variable as string regarding of string/boolean.
No matter if you add an inverted comma or not, process.env reads it as a string.

packages/hoppscotch-backend/src/admin/infra.resolver.ts Outdated Show resolved Hide resolved
@balub balub self-requested a review May 27, 2024 09:51
@balub
Copy link
Member

balub commented May 27, 2024

EMAIL does not get added back to the VITE_ALLOWED_AUTH_PROVIDERS infra-config when SMTP is enabled again after being disabled.

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.

None yet

2 participants