Add ENABLE_DISCUSSION_EMAIL_DIGEST feature, to enable discussion emails digest by default for all users
This commit is contained in:
committed by
Matjaz Gregoric
parent
c6aa4416c4
commit
ac445d6eff
@@ -14,6 +14,7 @@ import mock
|
||||
|
||||
from openedx.core.djangoapps.user_api.models import UserPreference
|
||||
from lang_pref import LANGUAGE_KEY
|
||||
from notification_prefs import NOTIFICATION_PREF_KEY
|
||||
|
||||
from edxmako.tests import mako_middleware_process_request
|
||||
from external_auth.models import ExternalAuthMap
|
||||
@@ -50,8 +51,8 @@ class TestCreateAccount(TestCase):
|
||||
@ddt.data("en", "eo")
|
||||
def test_header_lang_pref_saved(self, lang):
|
||||
response = self.client.post(self.url, self.params, HTTP_ACCEPT_LANGUAGE=lang)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
user = User.objects.get(username=self.username)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(UserPreference.get_preference(user, LANGUAGE_KEY), lang)
|
||||
|
||||
def base_extauth_bypass_sending_activation_email(self, bypass_activation_email_for_extauth_setting):
|
||||
@@ -98,6 +99,18 @@ class TestCreateAccount(TestCase):
|
||||
"""
|
||||
self.base_extauth_bypass_sending_activation_email(False)
|
||||
|
||||
@ddt.data(True, False)
|
||||
def test_discussions_email_digest_pref(self, digest_enabled):
|
||||
with mock.patch.dict("student.models.settings.FEATURES", {"ENABLE_DISCUSSION_EMAIL_DIGEST": digest_enabled}):
|
||||
response = self.client.post(self.url, self.params)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
user = User.objects.get(username=self.username)
|
||||
preference = UserPreference.get_preference(user, NOTIFICATION_PREF_KEY)
|
||||
if digest_enabled:
|
||||
self.assertIsNotNone(preference)
|
||||
else:
|
||||
self.assertIsNone(preference)
|
||||
|
||||
|
||||
@mock.patch.dict("student.models.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True})
|
||||
@mock.patch("lms.lib.comment_client.User.base_url", TEST_CS_URL)
|
||||
|
||||
@@ -86,6 +86,7 @@ from bulk_email.models import Optout, CourseAuthorization
|
||||
import shoppingcart
|
||||
from openedx.core.djangoapps.user_api.models import UserPreference
|
||||
from lang_pref import LANGUAGE_KEY
|
||||
from notification_prefs.views import enable_notifications
|
||||
|
||||
import track.views
|
||||
|
||||
@@ -1589,6 +1590,12 @@ def create_account(request, post_override=None): # pylint: disable-msg=too-many
|
||||
|
||||
(user, profile, registration) = ret
|
||||
|
||||
if settings.FEATURES.get('ENABLE_DISCUSSION_EMAIL_DIGEST'):
|
||||
try:
|
||||
enable_notifications(user)
|
||||
except Exception:
|
||||
log.exception("Enable discussion notifications failed for user {id}.".format(id=user.id))
|
||||
|
||||
dog_stats_api.increment("common.student.account_created")
|
||||
|
||||
email = post_vars['email']
|
||||
|
||||
@@ -90,6 +90,31 @@ class UsernameCipher(object):
|
||||
return UsernameCipher._remove_padding(decrypted)
|
||||
|
||||
|
||||
def enable_notifications(user):
|
||||
"""
|
||||
Enable notifications for a user.
|
||||
Currently only used for daily forum digests.
|
||||
"""
|
||||
UserPreference.objects.get_or_create(
|
||||
user=user,
|
||||
key=NOTIFICATION_PREF_KEY,
|
||||
defaults={
|
||||
"value": UsernameCipher.encrypt(user.username)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def disable_notifications(user):
|
||||
"""
|
||||
Disable notifications for a user.
|
||||
Currently only used for daily forum digests.
|
||||
"""
|
||||
UserPreference.objects.filter(
|
||||
user=user,
|
||||
key=NOTIFICATION_PREF_KEY
|
||||
).delete()
|
||||
|
||||
|
||||
@require_POST
|
||||
def ajax_enable(request):
|
||||
"""
|
||||
@@ -103,13 +128,7 @@ def ajax_enable(request):
|
||||
if not request.user.is_authenticated():
|
||||
raise PermissionDenied
|
||||
|
||||
UserPreference.objects.get_or_create(
|
||||
user=request.user,
|
||||
key=NOTIFICATION_PREF_KEY,
|
||||
defaults={
|
||||
"value": UsernameCipher.encrypt(request.user.username)
|
||||
}
|
||||
)
|
||||
enable_notifications(request.user)
|
||||
|
||||
return HttpResponse(status=204)
|
||||
|
||||
@@ -125,10 +144,7 @@ def ajax_disable(request):
|
||||
if not request.user.is_authenticated():
|
||||
raise PermissionDenied
|
||||
|
||||
UserPreference.objects.filter(
|
||||
user=request.user,
|
||||
key=NOTIFICATION_PREF_KEY
|
||||
).delete()
|
||||
disable_notifications(request.user)
|
||||
|
||||
return HttpResponse(status=204)
|
||||
|
||||
|
||||
@@ -103,6 +103,13 @@ FEATURES = {
|
||||
# this should remain off in production until digest notifications are online.
|
||||
'ENABLE_DISCUSSION_HOME_PANEL': False,
|
||||
|
||||
# Set this to True if you want the discussion digest emails enabled automatically for new users.
|
||||
# This will be set on all new account registrations.
|
||||
# It is not recommended to enable this feature if ENABLE_DISCUSSION_HOME_PANEL is not enabled, since
|
||||
# subscribers who receive digests in that case will only be able to unsubscribe via links embedded
|
||||
# in their emails, and they will have no way to resubscribe.
|
||||
'ENABLE_DISCUSSION_EMAIL_DIGEST': False,
|
||||
|
||||
'ENABLE_PSYCHOMETRICS': False, # real-time psychometrics (eg item response theory analysis in instructor dashboard)
|
||||
|
||||
'ENABLE_DJANGO_ADMIN_SITE': True, # set true to enable django's admin site, even on prod (e.g. for course ops)
|
||||
|
||||
Reference in New Issue
Block a user