Skip to content

Commit

Permalink
fix(mailer): Use DB config only for Wizard mode
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekSuchanek committed Dec 28, 2022
1 parent cc01ea2 commit ca703a9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
10 changes: 5 additions & 5 deletions packages/dsw-config/dsw/config/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class _DatabaseKeys(ConfigKeysContainer):
queue_timeout = ConfigKey(
yaml_path=['database', 'queueTimeout'],
var_names=['DATABASE_QUEUE_TIMEOUT'],
default=300,
default=180,
cast=cast_int,
)

Expand Down Expand Up @@ -235,12 +235,12 @@ class _MailKeys(ConfigKeysContainer):
ssl = ConfigKey(
yaml_path=['mail', 'ssl'],
var_names=[],
cast=cast_str,
cast=cast_optional_str,
)
security = ConfigKey(
yaml_path=['mail', 'security'],
var_names=['MAIL_SECURITY'],
cast=cast_str,
cast=cast_optional_str,
)
auth_enabled = ConfigKey(
yaml_path=['mail', 'authEnabled'],
Expand Down Expand Up @@ -271,9 +271,9 @@ class _MailKeys(ConfigKeysContainer):
cast=cast_int,
)
timeout = ConfigKey(
yaml_path=['mail', 'enabled'],
yaml_path=['mail', 'timeout'],
var_names=['MAIL_TIMEOUT'],
default=5,
default=10,
cast=cast_int,
)

Expand Down
3 changes: 2 additions & 1 deletion packages/dsw-config/dsw/config/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,5 @@ def __str__(self):
f'- security = {self.security}\n' \
f'- auth = {self.auth}\n' \
f'- rate_limit_window = {self.rate_limit_window}\n' \
f'- rate_limit_count = {self.rate_limit_count}\n'
f'- rate_limit_count = {self.rate_limit_count}\n' \
f'- timeout = {self.timeout}\n'
8 changes: 5 additions & 3 deletions packages/dsw-mailer/dsw/mailer/connection/smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ def send(self, message: MailMessage, cfg: Optional[MailConfig]):
Context.logger.info(f'Sending via SMTP: {used_cfg.host}:{used_cfg.port}')
self._send(message, used_cfg)

def _send(self, mail: MailMessage, cfg: MailConfig):
@classmethod
def _send(cls, mail: MailMessage, cfg: MailConfig):
if cfg.is_ssl:
return self._send_smtp_ssl(mail=mail, cfg=cfg)
return self._send_smtp(mail=mail, cfg=cfg)
return cls._send_smtp_ssl(mail=mail, cfg=cfg)
return cls._send_smtp(mail=mail, cfg=cfg)

@classmethod
def _send_smtp_ssl(cls, mail: MailMessage, cfg: MailConfig):
context = ssl.create_default_context()
with smtplib.SMTP_SSL(
Expand Down
10 changes: 6 additions & 4 deletions packages/dsw-mailer/dsw/mailer/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ def _process_command(self, cmd: PersistentCommand):
trigger='PersistentComment',
)
# get mailer config from DB
cfg = _transform_mail_config(
cfg=app_ctx.db.get_mail_config(app_uuid=cmd.app_uuid),
)
cfg = None
if Context.is_wizard_mode():
cfg = _transform_mail_config(
cfg=app_ctx.db.get_mail_config(app_uuid=cmd.app_uuid),
)
Context.logger.debug(f'Config from DB: {cfg}')
# update Sentry info
SentryReporter.set_context('template', rq.template_name)
Expand Down Expand Up @@ -507,7 +509,7 @@ def registry_link(self) -> str:
def callback_link(self) -> Optional[str]:
if self.callback_url is None:
return None
return f'{self.client_url}/registry/signup/{self.org.id}/{self.code}'
return f'{self.callback_url}/registry/signup/{self.org.id}/{self.code}'

@property
def activation_link(self) -> Optional[str]:
Expand Down

0 comments on commit ca703a9

Please sign in to comment.