Merge pull request #19770 from edx/revert-19018-opencraft/taranjeet/opt-out-weekly-highlight-messages
Revert "Add api support to let users opt out of email updates."
This commit is contained in:
@@ -1,80 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Test the bulk email opt out view.
|
||||
"""
|
||||
from six import text_type
|
||||
|
||||
import ddt
|
||||
from django.http import Http404
|
||||
from django.test.client import RequestFactory
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
|
||||
from bulk_email.models import Optout
|
||||
from bulk_email.views import opt_out_email_updates
|
||||
from notification_prefs.views import UsernameCipher
|
||||
from openedx.core.lib.tests import attr
|
||||
from student.tests.factories import UserFactory
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
|
||||
|
||||
@attr(shard=1)
|
||||
@ddt.ddt
|
||||
@override_settings(SECRET_KEY="test secret key")
|
||||
class OptOutEmailUpdatesViewTest(ModuleStoreTestCase):
|
||||
"""
|
||||
Check the opt out email functionality.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(OptOutEmailUpdatesViewTest, self).setUp()
|
||||
self.user = UserFactory.create(username="testuser1")
|
||||
self.token = UsernameCipher.encrypt('testuser1')
|
||||
self.request_factory = RequestFactory()
|
||||
self.course = CourseFactory.create(run='testcourse1', display_name='Test Course Title')
|
||||
self.url = reverse('bulk_email_opt_out', args=[self.token, text_type(self.course.id)])
|
||||
|
||||
# Ensure we start with no opt-out records
|
||||
self.assertEqual(Optout.objects.count(), 0)
|
||||
|
||||
def test_opt_out_email_confirm(self):
|
||||
"""
|
||||
Ensure that the default GET view asks for confirmation.
|
||||
"""
|
||||
response = self.client.get(self.url)
|
||||
self.assertContains(response, "Do you want to unsubscribe from emails for Test Course Title?")
|
||||
self.assertEqual(Optout.objects.count(), 0)
|
||||
|
||||
def test_opt_out_email_unsubscribe(self):
|
||||
"""
|
||||
Ensure that the POSTing "confirm" creates the opt-out record.
|
||||
"""
|
||||
response = self.client.post(self.url, {'submit': 'confirm'})
|
||||
self.assertContains(response, "You have been unsubscribed from emails for Test Course Title.")
|
||||
self.assertEqual(Optout.objects.count(), 1)
|
||||
|
||||
def test_opt_out_email_cancel(self):
|
||||
"""
|
||||
Ensure that the POSTing "cancel" does not create the opt-out record
|
||||
"""
|
||||
response = self.client.post(self.url, {'submit': 'cancel'})
|
||||
self.assertContains(response, "You have not been unsubscribed from emails for Test Course Title.")
|
||||
self.assertEqual(Optout.objects.count(), 0)
|
||||
|
||||
@ddt.data(
|
||||
("ZOMG INVALID BASE64 CHARS!!!", "base64url", False),
|
||||
("Non-ASCII\xff", "base64url", False),
|
||||
("D6L8Q01ztywqnr3coMOlq0C3DG05686lXX_1ArEd0ok", "base64url", False),
|
||||
("AAAAAAAAAAA=", "initialization_vector", False),
|
||||
("nMXVK7PdSlKPOovci-M7iqS09Ux8VoCNDJixLBmj", "aes", False),
|
||||
("AAAAAAAAAAAAAAAAAAAAAMoazRI7ePLjEWXN1N7keLw=", "padding", False),
|
||||
("AAAAAAAAAAAAAAAAAAAAACpyUxTGIrUjnpuUsNi7mAY=", "username", False),
|
||||
("_KHGdCAUIToc4iaRGy7K57mNZiiXxO61qfKT08ExlY8=", "course", 'course-v1:testcourse'),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_unsubscribe_invalid_token(self, token, message, course):
|
||||
"""
|
||||
Make sure that view returns 404 in case token is not valid
|
||||
"""
|
||||
request = self.request_factory.get("dummy")
|
||||
self.assertRaisesRegexp(Http404, "^{}$".format(message), opt_out_email_updates, request, token, course)
|
||||
@@ -1,18 +0,0 @@
|
||||
"""
|
||||
URLs for bulk_email app
|
||||
"""
|
||||
|
||||
from django.conf import settings
|
||||
from django.conf.urls import url
|
||||
|
||||
from bulk_email import views
|
||||
|
||||
urlpatterns = [
|
||||
url(
|
||||
r'^email/optout/(?P<token>[a-zA-Z0-9-_=]+)/{}/$'.format(
|
||||
settings.COURSE_ID_PATTERN,
|
||||
),
|
||||
views.opt_out_email_updates,
|
||||
name='bulk_email_opt_out',
|
||||
),
|
||||
]
|
||||
@@ -1,72 +0,0 @@
|
||||
"""
|
||||
Views to support bulk email functionalities like opt-out.
|
||||
"""
|
||||
|
||||
from __future__ import division
|
||||
|
||||
import logging
|
||||
|
||||
from six import text_type
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.http import Http404
|
||||
|
||||
from bulk_email.models import Optout
|
||||
from courseware.courses import get_course_by_id
|
||||
from edxmako.shortcuts import render_to_response
|
||||
from notification_prefs.views import (
|
||||
UsernameCipher,
|
||||
UsernameDecryptionException,
|
||||
)
|
||||
|
||||
from opaque_keys import InvalidKeyError
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def opt_out_email_updates(request, token, course_id):
|
||||
"""
|
||||
A view that let users opt out of any email updates.
|
||||
|
||||
This meant is meant to be the target of an opt-out link or button.
|
||||
The `token` parameter must decrypt to a valid username.
|
||||
The `course_id` is the string course key of any course.
|
||||
|
||||
Raises a 404 if there are any errors parsing the input.
|
||||
"""
|
||||
try:
|
||||
username = UsernameCipher().decrypt(token.encode())
|
||||
user = User.objects.get(username=username)
|
||||
course_key = CourseKey.from_string(course_id)
|
||||
course = get_course_by_id(course_key, depth=0)
|
||||
except UnicodeDecodeError:
|
||||
raise Http404("base64url")
|
||||
except UsernameDecryptionException as exn:
|
||||
raise Http404(text_type(exn))
|
||||
except User.DoesNotExist:
|
||||
raise Http404("username")
|
||||
except InvalidKeyError:
|
||||
raise Http404("course")
|
||||
|
||||
context = {
|
||||
'course': course,
|
||||
'cancelled': False,
|
||||
'confirmed': False,
|
||||
}
|
||||
|
||||
if request.method == 'POST':
|
||||
if request.POST.get('submit') == 'confirm':
|
||||
Optout.objects.get_or_create(user=user, course_id=course.id)
|
||||
log.info(
|
||||
u"User %s (%s) opted out of receiving emails from course %s",
|
||||
user.username,
|
||||
user.email,
|
||||
course_id,
|
||||
)
|
||||
context['confirmed'] = True
|
||||
else:
|
||||
context['cancelled'] = True
|
||||
|
||||
return render_to_response('bulk_email/unsubscribe.html', context)
|
||||
@@ -1,48 +0,0 @@
|
||||
<%page expression_filter="h" />
|
||||
<%inherit file="../main.html" />
|
||||
<%!
|
||||
from openedx.core.djangolib.markup import Text
|
||||
from django.utils.translation import ugettext as _
|
||||
%>
|
||||
<%def name="header()">
|
||||
%if confirmed:
|
||||
${Text(_("Unsubscribe Successful"))}
|
||||
%elif cancelled:
|
||||
${Text(_("Unsubscribe Cancelled"))}
|
||||
%else:
|
||||
${Text(_("Confirm Unsubscribe"))}
|
||||
%endif
|
||||
</%def>
|
||||
|
||||
<%block name="pagetitle">${header()}</%block>
|
||||
<section class="container unsubscribe">
|
||||
|
||||
<section class="message">
|
||||
<h1>
|
||||
<%block name="pageheader">${header()}</%block>
|
||||
</h1>
|
||||
<p>
|
||||
<%block name="pagecontent">
|
||||
%if confirmed:
|
||||
${Text(_("You have been unsubscribed from emails for {course}.")).format(
|
||||
course=course.display_name_with_default
|
||||
)}
|
||||
%elif cancelled:
|
||||
${Text(_("You have not been unsubscribed from emails for {course}.")).format(
|
||||
course=course.display_name_with_default
|
||||
)}
|
||||
%else:
|
||||
${Text(_("Do you want to unsubscribe from emails for {course}?")).format(
|
||||
course=course.display_name_with_default
|
||||
)}
|
||||
<br /><br />
|
||||
<form method="post">
|
||||
<input type="hidden" id="csrf_token" name="csrfmiddlewaretoken" value="${csrf_token}">
|
||||
<button name="submit" value="confirm" type="submit">${Text(_('Unsubscribe'))}</button>
|
||||
<button name="submit" value="cancel" type="submit">${Text(_('Cancel'))}</button>
|
||||
</form>
|
||||
%endif
|
||||
</%block>
|
||||
</p>
|
||||
</section>
|
||||
</section>
|
||||
@@ -746,10 +746,6 @@ if settings.FEATURES.get('ENABLE_DISCUSSION_SERVICE'):
|
||||
),
|
||||
]
|
||||
|
||||
urlpatterns += [
|
||||
url(r'^bulk_email/', include('bulk_email.urls')),
|
||||
]
|
||||
|
||||
urlpatterns += [
|
||||
url(
|
||||
r'^courses/{}/tab/(?P<tab_type>[^/]+)/$'.format(
|
||||
|
||||
Reference in New Issue
Block a user