Brought SiteConfig checks back.
This commit is contained in:
@@ -25,6 +25,16 @@ def send_discussion_email_notification(sender, user, post, **kwargs):
|
||||
log.info('Discussion: No current site, not sending notification about post: %s.', post.id)
|
||||
return
|
||||
|
||||
try:
|
||||
if not current_site.configuration.get_value(ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY, False):
|
||||
log_message = 'Discussion: notifications not enabled for site: %s. Not sending message about post: %s.'
|
||||
log.info(log_message, current_site, post.id)
|
||||
return
|
||||
except SiteConfiguration.DoesNotExist:
|
||||
log_message = 'Discussion: No SiteConfiguration for site %s. Not sending message about post: %s.'
|
||||
log.info(log_message, current_site, post.id)
|
||||
return
|
||||
|
||||
send_message(post, current_site)
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ from django.test import TestCase
|
||||
import mock
|
||||
|
||||
from django_comment_common import signals
|
||||
from lms.djangoapps.discussion.signals.handlers import ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY
|
||||
from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory, SiteConfigurationFactory
|
||||
from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag
|
||||
|
||||
@@ -18,6 +19,9 @@ class SendMessageHandlerTestCase(TestCase):
|
||||
@mock.patch('lms.djangoapps.discussion.signals.handlers.get_current_site')
|
||||
@mock.patch('lms.djangoapps.discussion.signals.handlers.send_message')
|
||||
def test_comment_created_signal_sends_message(self, mock_send_message, mock_get_current_site):
|
||||
site_config = SiteConfigurationFactory.create(site=self.site)
|
||||
site_config.values[ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY] = True
|
||||
site_config.save()
|
||||
mock_get_current_site.return_value = self.site
|
||||
signals.comment_created.send(sender=self.sender, user=self.user, post=self.post)
|
||||
|
||||
@@ -41,3 +45,24 @@ class SendMessageHandlerTestCase(TestCase):
|
||||
signals.comment_created.send(sender=self.sender, user=self.user, post=self.post)
|
||||
|
||||
self.assertFalse(mock_send_message.called)
|
||||
|
||||
@mock.patch('lms.djangoapps.discussion.signals.handlers.get_current_site')
|
||||
@mock.patch('lms.djangoapps.discussion.signals.handlers.send_message')
|
||||
def test_comment_created_signal_msg_not_sent_without_site_config(self, mock_send_message, mock_get_current_site):
|
||||
mock_get_current_site.return_value = self.site
|
||||
signals.comment_created.send(sender=self.sender, user=self.user, post=self.post)
|
||||
|
||||
self.assertFalse(mock_send_message.called)
|
||||
|
||||
@mock.patch('lms.djangoapps.discussion.signals.handlers.get_current_site')
|
||||
@mock.patch('lms.djangoapps.discussion.signals.handlers.send_message')
|
||||
def test_comment_created_signal_msg_not_sent_with_site_config_disabled(
|
||||
self, mock_send_message, mock_get_current_site
|
||||
):
|
||||
site_config = SiteConfigurationFactory.create(site=self.site)
|
||||
site_config.values[ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY] = False
|
||||
site_config.save()
|
||||
mock_get_current_site.return_value = self.site
|
||||
signals.comment_created.send(sender=self.sender, user=self.user, post=self.post)
|
||||
|
||||
self.assertFalse(mock_send_message.called)
|
||||
|
||||
@@ -17,6 +17,7 @@ from django_comment_common.signals import comment_created
|
||||
from edx_ace.recipient import Recipient
|
||||
from edx_ace.renderers import EmailRenderer
|
||||
from edx_ace.utils import date
|
||||
from lms.djangoapps.discussion.signals.handlers import ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY
|
||||
from lms.djangoapps.discussion.tasks import _should_send_message
|
||||
from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory
|
||||
from openedx.core.djangoapps.ace_common.template_context import get_base_template_context
|
||||
@@ -182,6 +183,9 @@ class TaskTestCase(ModuleStoreTestCase):
|
||||
user = mock.Mock()
|
||||
comment = cc.Comment.find(id=self.comment['id']).retrieve()
|
||||
site = Site.objects.get_current()
|
||||
site_config = SiteConfigurationFactory.create(site=site)
|
||||
site_config.values[ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY] = True
|
||||
site_config.save()
|
||||
with mock.patch('lms.djangoapps.discussion.signals.handlers.get_current_site', return_value=site):
|
||||
comment_created.send(sender=None, user=user, post=comment)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user