Refactor(application): Extract default email as magic values to avoid hardcoding
This commit is contained in:
parent
11c1cc811d
commit
1d6f41c3b5
@ -6,7 +6,7 @@ from common.exception.exceptions import InvalidDataError
|
||||
from backend.business.tenant_notification_manager import TenantNotificationManager
|
||||
from backend.application.template_message_hub import TemplateMessageHub
|
||||
from backend.application.email_sender_hub import EmailSenderHub
|
||||
|
||||
from backend.models.constants import NotificationConstants
|
||||
|
||||
class TenantNotificationHub:
|
||||
def __init__(self):
|
||||
@ -14,6 +14,7 @@ class TenantNotificationHub:
|
||||
self.template_message_hub = TemplateMessageHub()
|
||||
self.email_sender_hub = EmailSenderHub()
|
||||
self.module_logger = ModuleLogger(sender_id="TenantNotificationHub")
|
||||
self.notification_constants = NotificationConstants()
|
||||
|
||||
async def send_tenant_email(
|
||||
self,
|
||||
@ -41,23 +42,23 @@ class TenantNotificationHub:
|
||||
)
|
||||
|
||||
# 3. get tenant email senders
|
||||
default_sender_email = self.notification_constants.DEFAULT_EMAIL_SENDER
|
||||
if sender_emails is None:
|
||||
# TODO: use default email sender directly
|
||||
tenant_email_senders = await self.email_sender_hub.get_email_senders(tenant_id)
|
||||
if not tenant_email_senders:
|
||||
sender_emails = ["support@freeleaps.com"]
|
||||
sender_emails = [default_sender_email]
|
||||
await self.module_logger.log_info(
|
||||
"Using default email sender for tenant",
|
||||
properties={
|
||||
"tenant_id": tenant_id,
|
||||
"default_sender": "support@freeleaps.com"
|
||||
"default_sender": default_sender_email
|
||||
}
|
||||
)
|
||||
else:
|
||||
sender_emails = tenant_email_senders
|
||||
|
||||
# 4. check if sender_emails are valid
|
||||
if sender_emails != ["support@freeleaps.com"]:
|
||||
if sender_emails != [default_sender_email]:
|
||||
tenant_senders = await self.email_sender_hub.get_email_senders(tenant_id)
|
||||
invalid_senders = [email for email in sender_emails if email not in tenant_senders]
|
||||
if invalid_senders:
|
||||
|
||||
@ -125,3 +125,12 @@ SystemNotifications = {
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
class NotificationConstants:
|
||||
DEFAULT_EMAIL_SENDER: str = "support@freeleaps.com"
|
||||
|
||||
class Settings:
|
||||
name = "notification_constants"
|
||||
indexes = [
|
||||
"DEFAULT_EMAIL_SENDER"
|
||||
]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user