Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
8abfdc63
Commit
8abfdc63
authored
Jan 17, 2014
by
Jason Bau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add undo (resub) to landing page of forum unsub link
parent
7f742978
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
10 deletions
+70
-10
lms/djangoapps/notification_prefs/tests.py
+18
-1
lms/djangoapps/notification_prefs/views.py
+13
-5
lms/templates/resubscribe.html
+24
-0
lms/templates/unsubscribe.html
+13
-4
lms/urls.py
+2
-0
No files found.
lms/djangoapps/notification_prefs/tests.py
View file @
8abfdc63
...
...
@@ -12,10 +12,11 @@ from notification_prefs import NOTIFICATION_PREF_KEY
from
notification_prefs.views
import
ajax_enable
,
ajax_disable
,
ajax_status
,
unsubscribe
from
student.tests.factories
import
UserFactory
from
user_api.models
import
UserPreference
from
util.testing
import
UrlResetMixin
@override_settings
(
SECRET_KEY
=
"test secret key"
)
class
NotificationPrefViewTest
(
TestCase
):
class
NotificationPrefViewTest
(
UrlResetMixin
,
TestCase
):
INITIALIZATION_VECTOR
=
"
\x00
"
*
16
@classmethod
...
...
@@ -23,7 +24,9 @@ class NotificationPrefViewTest(TestCase):
# Make sure global state is set up appropriately
Client
()
.
get
(
"/"
)
@patch.dict
(
"django.conf.settings.FEATURES"
,
{
"ENABLE_DISCUSSION_SERVICE"
:
True
})
def
setUp
(
self
):
super
(
NotificationPrefViewTest
,
self
)
.
setUp
()
self
.
user
=
UserFactory
.
create
(
username
=
"testuser"
)
# Tokens are intentionally hard-coded instead of computed to help us
# avoid breaking existing links.
...
...
@@ -230,3 +233,17 @@ class NotificationPrefViewTest(TestCase):
response
=
unsubscribe
(
request
,
self
.
tokens
[
self
.
user
])
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertNotPrefExists
(
self
.
user
)
def
test_resubscribe_success
(
self
):
def
test_user
(
user
):
# start without a pref key
self
.
assertFalse
(
UserPreference
.
objects
.
filter
(
user
=
user
,
key
=
NOTIFICATION_PREF_KEY
))
request
=
self
.
request_factory
.
get
(
"dummy"
)
request
.
user
=
AnonymousUser
()
response
=
unsubscribe
(
request
,
self
.
tokens
[
user
],
resubscribe
=
True
)
self
.
assertEqual
(
response
.
status_code
,
200
)
# this new DB entry will have a new value, so can't use assertPrefValid. Just check existence
self
.
assertTrue
(
UserPreference
.
objects
.
filter
(
user
=
user
,
key
=
NOTIFICATION_PREF_KEY
))
for
user
in
self
.
tokens
.
keys
():
test_user
(
user
)
lms/djangoapps/notification_prefs/views.py
View file @
8abfdc63
...
...
@@ -153,12 +153,13 @@ def ajax_status(request):
@require_GET
def
unsubscribe
(
request
,
token
):
def
unsubscribe
(
request
,
token
,
resubscribe
=
False
):
# pylint: disable=unused-argument
"""
A view that disables notifications for a user who may not be authenticated
A view that disables
or re-enables
notifications for a user who may not be authenticated
This view is meant to be the target of an unsubscribe link. The request
must be a GET, and the `token` parameter must decrypt to a valid username.
The resubscribe feature allows "undo" of accidentally clicking on unsubscribe
A 405 will be returned if the request method is not GET. A 404 will be
returned if the token parameter does not decrypt to a valid username. On
...
...
@@ -174,6 +175,13 @@ def unsubscribe(request, token):
except
User
.
DoesNotExist
:
raise
Http404
(
"username"
)
UserPreference
.
objects
.
filter
(
user
=
user
,
key
=
NOTIFICATION_PREF_KEY
)
.
delete
()
return
render_to_response
(
"unsubscribe.html"
,
{})
if
not
resubscribe
:
UserPreference
.
objects
.
filter
(
user
=
user
,
key
=
NOTIFICATION_PREF_KEY
)
.
delete
()
return
render_to_response
(
"unsubscribe.html"
,
{
'token'
:
token
})
else
:
UserPreference
.
objects
.
get_or_create
(
user
=
user
,
key
=
NOTIFICATION_PREF_KEY
,
defaults
=
{
"value"
:
UsernameCipher
.
encrypt
(
user
.
username
)
})
return
render_to_response
(
"resubscribe.html"
,
{
'token'
:
token
})
lms/templates/resubscribe.html
0 → 100644
View file @
8abfdc63
<
%!
from
django
.
core
.
urlresolvers
import
reverse
from
django
.
utils
.
translation
import
ugettext
as
_
from
django
.
conf
import
settings
%
>
<
%
inherit
file=
"main.html"
/>
<
%
namespace
name=
'static'
file=
'static_content.html'
/>
<section
class=
"container unsubscribe"
>
<section
class=
"message"
>
<h1>
${_("Re-subscribe Successful!")}
</h1>
<hr
class=
"horizontal-divider"
>
<p>
${_("You have re-enabled forum notification emails from {platform_name}. "
"Click {dashboard_link_start}here{link_end} to return to your dashboard. ").format(
platform_name=settings.PLATFORM_NAME,
dashboard_link_start="
<a
href=
'{}'
>
".format(reverse('dashboard')),
link_end="
</a>
",)}
</p>
</section>
</section>
lms/templates/unsubscribe.html
View file @
8abfdc63
<
%!
from
django
.
core
.
urlresolvers
import
reverse
%
>
<
%!
from
django
.
core
.
urlresolvers
import
reverse
from
django
.
utils
.
translation
import
ugettext
as
_
from
django
.
conf
import
settings
%
>
<
%
inherit
file=
"main.html"
/>
<
%
namespace
name=
'static'
file=
'static_content.html'
/>
...
...
@@ -6,12 +10,17 @@
<section
class=
"container unsubscribe"
>
<section
class=
"message"
>
<h1>
Unsubscribe Successful!
</h1>
<h1>
${_("Unsubscribe Successful!")}
</h1>
<hr
class=
"horizontal-divider"
>
<p>
You will no longer receive notification emails from edX.
Click
<a
href=
"${reverse('dashboard')}"
>
here
</a>
to return to your dashboard.
${_("You will no longer receive forum notification emails from {platform_name}. "
"Click {dashboard_link_start}here{link_end} to return to your dashboard. "
"If you did not mean to do this, click {undo_link_start}here{link_end} to re-subscribe.").format(
platform_name=settings.PLATFORM_NAME,
dashboard_link_start="
<a
href=
'{}'
>
".format(reverse('dashboard')),
undo_link_start="
<a
id=
'resub_link'
href=
'{}'
>
".format(reverse('resubscribe_forum_update', args=[token])),
link_end="
</a>
",)}
</p>
</section>
</section>
lms/urls.py
View file @
8abfdc63
...
...
@@ -339,6 +339,8 @@ if settings.COURSEWARE_ENABLED:
url
(
r'^notification_prefs/disable/'
,
'notification_prefs.views.ajax_disable'
),
url
(
r'^notification_prefs/status/'
,
'notification_prefs.views.ajax_status'
),
url
(
r'^notification_prefs/unsubscribe/(?P<token>[a-zA-Z0-9-_=]+)/'
,
'notification_prefs.views.unsubscribe'
),
url
(
r'^notification_prefs/resubscribe/(?P<token>[a-zA-Z0-9-_=]+)/'
,
'notification_prefs.views.unsubscribe'
,
{
'resubscribe'
:
True
},
name
=
"resubscribe_forum_update"
),
)
urlpatterns
+=
(
# This MUST be the last view in the courseware--it's a catch-all for custom tabs.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment