diff --git a/osf/models/notification.py b/osf/models/notification.py index 533a05a4e97..d0202b57166 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 as osf_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,28 @@ 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 osf_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 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.' + ) if save: self.mark_sent() 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/'