From 92aadda4fc941f0df0fd22b35d54eea5eca0b418 Mon Sep 17 00:00:00 2001 From: Ostap Zherebetskyi Date: Thu, 21 May 2026 16:13:09 +0300 Subject: [PATCH 1/4] Refactor Notification.send method to remove protocol_type parameter and simplify email sending logic --- osf/models/notification.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osf/models/notification.py b/osf/models/notification.py index 533a05a4e97..43ed81247c2 100644 --- a/osf/models/notification.py +++ b/osf/models/notification.py @@ -5,6 +5,7 @@ from django.utils import timezone from api.base import settings as api_settings +from website import settings from osf import email, features @@ -21,7 +22,6 @@ class Notification(models.Model): def send( self, - protocol_type='email', destination_address=None, email_context=None, save=True, @@ -36,22 +36,22 @@ def send( f"\ncontext={self.event_context}" f"\nemail_context={email_context}" ) - if protocol_type == 'email' and waffle.switch_is_active(features.ENABLE_MAILHOG): + + if waffle.switch_is_active(features.ENABLE_MAILHOG): email.send_email_over_smtp( recipient_address, self.subscription.notification_type, self.event_context, email_context ) - elif protocol_type == 'email': + + if not settings.LOCAL_MODE: email.send_email_with_send_grid( recipient_address, self.subscription.notification_type, self.event_context, email_context ) - else: - raise NotImplementedError(f'protocol `{protocol_type}` is not supported.') if save: self.mark_sent() From d485113d1341c83b1dbc065a5b9c47954ab2e40a Mon Sep 17 00:00:00 2001 From: Ostap Zherebetskyi Date: Thu, 21 May 2026 16:28:17 +0300 Subject: [PATCH 2/4] Set LOCAL_MODE to True for local-ci --- website/settings/local-ci.py | 1 + 1 file changed, 1 insertion(+) diff --git a/website/settings/local-ci.py b/website/settings/local-ci.py index a4d250a9792..ba589b2c445 100644 --- a/website/settings/local-ci.py +++ b/website/settings/local-ci.py @@ -12,6 +12,7 @@ DEV_MODE = True DEBUG_MODE = True # Sets app to debug mode, turns off template caching, etc. SECURE_MODE = not DEBUG_MODE # Disable osf secure cookie +LOCAL_MODE = True # Local development environment, used to toggle certain features on/off PROTOCOL = 'https://' if SECURE_MODE else 'http://' DOMAIN = PROTOCOL + 'localhost:5000/' From 7e3d7f5ae642eaa1b4c0acdfa6b309713be4da4b Mon Sep 17 00:00:00 2001 From: Ostap Zherebetskyi Date: Thu, 21 May 2026 16:55:01 +0300 Subject: [PATCH 3/4] Add warning log for email sending in LOCAL_MODE without MailHog --- osf/models/notification.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/osf/models/notification.py b/osf/models/notification.py index 43ed81247c2..10015b2d7f6 100644 --- a/osf/models/notification.py +++ b/osf/models/notification.py @@ -53,6 +53,12 @@ def send( email_context ) + if settings.LOCAL_MODE and not waffle.switch_is_active(features.ENABLE_MAILHOG): + logging.warning( + 'Both ENABLE_MAILHOG and LOCAL_MODE are disabled. Emails will not be sent to MailHog or real email addresses. ' + 'Turn on ENABLE_MAILHOG to send emails to MailHog for testing, or turn on LOCAL_MODE to send emails with SendGrid.' + ) + if save: self.mark_sent() From 4ecf7e39f064444614f503d2c7af035087fe0a06 Mon Sep 17 00:00:00 2001 From: Longze Chen Date: Thu, 21 May 2026 09:59:24 -0400 Subject: [PATCH 4/4] Apply CR suggestions Co-authored-by: Longze Chen --- osf/models/notification.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osf/models/notification.py b/osf/models/notification.py index 10015b2d7f6..d0202b57166 100644 --- a/osf/models/notification.py +++ b/osf/models/notification.py @@ -5,7 +5,7 @@ from django.utils import timezone from api.base import settings as api_settings -from website import settings +from website import settings as osf_settings from osf import email, features @@ -45,7 +45,7 @@ def send( email_context ) - if not settings.LOCAL_MODE: + if not osf_settings.LOCAL_MODE: email.send_email_with_send_grid( recipient_address, self.subscription.notification_type, @@ -53,7 +53,7 @@ def send( email_context ) - if settings.LOCAL_MODE and not waffle.switch_is_active(features.ENABLE_MAILHOG): + if osf_settings.LOCAL_MODE and not waffle.switch_is_active(features.ENABLE_MAILHOG): logging.warning( 'Both ENABLE_MAILHOG and LOCAL_MODE are disabled. Emails will not be sent to MailHog or real email addresses. ' 'Turn on ENABLE_MAILHOG to send emails to MailHog for testing, or turn on LOCAL_MODE to send emails with SendGrid.'