Skip to content

Commit 019c629

Browse files
authored
Merge pull request #21 from bugout-dev/welcome-email-for-app
Moonstream welcome email
2 parents 26d4dae + 6c4edd1 commit 019c629

4 files changed

Lines changed: 25 additions & 6 deletions

File tree

brood/actions.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
DEFAULT_USER_GROUP_LIMIT,
4444
group_invite_link_from_env,
4545
TEMPLATE_ID_BUGOUT_WELCOME_EMAIL,
46+
TEMPLATE_ID_MOONSTREAM_WELCOME_EMAIL,
47+
MOONSTREAM_APPLICATION_ID,
4648
)
4749

4850
logger = logging.getLogger(__name__)
@@ -601,23 +603,34 @@ def change_password(
601603
return user
602604

603605

604-
def send_welcome_email(user: User) -> None:
606+
def send_welcome_email(user: User, application_id: Optional[uuid.UUID] = None) -> None:
605607
"""
606608
Send welcome email to each new user.
607609
"""
608610
user_id = str(user.id)
609611
if SENDGRID_API_KEY is None:
610612
logger.error(
611-
"Missed SENDGRID_API_KEY, message was not sent to user with id: {user_id}"
613+
f"Missed SENDGRID_API_KEY, message was not sent to user with id: {user_id}"
612614
)
613615
return
614616

615-
logger.info(f"Sending welcome email for user with id={user_id}...")
616617
message = Mail(
617618
from_email=f"Sophia from Bugout <{BUGOUT_FROM_EMAIL}>", to_emails=user.email
618619
)
619620
message.dynamic_template_data = {"username": user.username}
620-
message.template_id = TEMPLATE_ID_BUGOUT_WELCOME_EMAIL
621+
622+
if application_id is not None:
623+
if str(application_id) != MOONSTREAM_APPLICATION_ID:
624+
logger.error(
625+
f"Unhandled welcome email for application with id: {str(application_id)}"
626+
)
627+
return
628+
else:
629+
message.template_id = TEMPLATE_ID_MOONSTREAM_WELCOME_EMAIL
630+
else:
631+
message.template_id = TEMPLATE_ID_BUGOUT_WELCOME_EMAIL
632+
633+
logger.info(f"Sending welcome email for user with id={user_id}...")
621634

622635
try:
623636
sg = SendGridAPIClient(SENDGRID_API_KEY)

brood/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ async def create_user_handler(
146146
if autogenerated_user:
147147
return user
148148

149-
if SEND_EMAIL_WELCOME and application_id is None:
149+
if SEND_EMAIL_WELCOME:
150150
background_tasks.add_task(
151-
actions.send_welcome_email, user=user,
151+
actions.send_welcome_email, user=user, application_id=application_id,
152152
)
153153

154154
if not REQUIRE_EMAIL_VERIFICATION:

brood/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
TEMPLATE_ID_BUGOUT_WELCOME_EMAIL = os.environ.get(
2222
"SENDGRID_TEMPLATE_ID_BUGOUT_WELCOME_EMAIL"
2323
)
24+
TEMPLATE_ID_MOONSTREAM_WELCOME_EMAIL = os.environ.get(
25+
"SENDGRID_TEMPLATE_ID_MOONSTREAM_WELCOME_EMAIL"
26+
)
27+
MOONSTREAM_APPLICATION_ID = os.environ.get("MOONSTREAM_APPLICATION_ID")
2428

2529
DB_URI = os.environ.get("BROOD_DB_URI")
2630

sample.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ export STRIPE_SECRET_KEY="<Stripe API secret key>"
99
export STRIPE_SIGNING_SECRET="<Stripe Webhook signing key>"
1010
export BROOD_OPENAPI_LIST="resources"
1111
export SENDGRID_TEMPLATE_ID_BUGOUT_WELCOME_EMAIL="<template id welcome email>"
12+
export MOONSTREAM_APPLICATION_ID="<moonstream app id>"
13+
export SENDGRID_TEMPLATE_ID_MOONSTREAM_WELCOME_EMAIL="<template id welcome email for moonstream app>"

0 commit comments

Comments
 (0)