Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions osf/models/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -21,7 +22,6 @@ class Notification(models.Model):

def send(
self,
protocol_type='email',
destination_address=None,
email_context=None,
save=True,
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions website/settings/local-ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
Expand Down