Merge lp:~canonical-isd-hackers/canonical-identity-provider/add-2f-notifications into lp:canonical-identity-provider/release

Proposed by Stuart Metcalfe
Status: Merged
Approved by: David Owen
Approved revision: no longer in the source branch.
Merged at revision: 346
Proposed branch: lp:~canonical-isd-hackers/canonical-identity-provider/add-2f-notifications
Merge into: lp:canonical-identity-provider/release
Diff against target: 118 lines (+28/-14)
3 files modified
identityprovider/templates/device/list.html (+12/-8)
identityprovider/tests/unit/test_devices.py (+2/-5)
identityprovider/views/devices.py (+14/-1)
To merge this branch: bzr merge lp:~canonical-isd-hackers/canonical-identity-provider/add-2f-notifications
Reviewer Review Type Date Requested Status
David Owen (community) Approve
Review via email: mp+94235@code.launchpad.net

Commit message

Added notifications for 2-factor settings updates, addition, renaming and removal of devices (fixes bug #929516). Also, a small tweak to the devices list to hide the table when no devices are present (fixes bug #938796)

Description of the change

Added notifications for 2-factor settings updates, addition, renaming and removal of devices (fixes bug #929516). Also, a small tweak to the devices list to hide the table when no devices are present (fixes bug #938796)

To post a comment you must log in.
Revision history for this message
David Owen (dsowen) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'identityprovider/templates/device/list.html'
2--- identityprovider/templates/device/list.html 2012-02-22 14:08:08 +0000
3+++ identityprovider/templates/device/list.html 2012-02-22 17:45:23 +0000
4@@ -56,6 +56,7 @@
5 </form>
6
7 <div id="auth-devices">
8+ {% if devices %}
9 <h2>{% trans "Authentication devices you've added" %}</h2>
10
11 <table id="device-list">
12@@ -81,14 +82,17 @@
13 {% endfor %}
14 </tbody>
15 </table>
16-
17- <p><a href="{{ device_addition_path }}">
18- {% trans "Add a new authentication device" %}
19- </a></p>
20-
21- <p><a href="{{ lost_device_path }}">
22- {% trans "Report a stolen or lost device" %}
23- </a></p>
24+ {% else %}
25+ <p>{% trans "You don't have any authentication devices associated with this account." %}</p>
26+ {% endif %}
27+
28+ <p><a href="{{ device_addition_path }}">
29+ {% trans "Add a new authentication device" %}
30+ </a></p>
31+
32+ <p><a href="{{ lost_device_path }}">
33+ {% trans "Report a stolen or lost device" %}
34+ </a></p>
35 </div>
36
37 {% endblock %}
38
39=== modified file 'identityprovider/tests/unit/test_devices.py'
40--- identityprovider/tests/unit/test_devices.py 2012-02-17 13:05:48 +0000
41+++ identityprovider/tests/unit/test_devices.py 2012-02-22 17:45:23 +0000
42@@ -61,10 +61,7 @@
43 tree = PyQuery(fromstring(response.content))
44
45 devices = tree.find('table#device-list')
46- expected_headers = ['Name', None]
47- self.assertEqual([e.text for e in devices.find('th')],
48- expected_headers)
49- self.assertEqual(len(devices.find('tbody tr')), 0)
50+ self.assertEqual(devices, [])
51
52 radios = tree.find('input[type=radio]')
53 values = ['always', 'as-needed']
54@@ -388,7 +385,7 @@
55 with patch(MOD_PREFIX + '.get_object_or_404'):
56 device_removal(mock_request, 100)
57
58- self.assertEqual(mock_request.session, {})
59+ self.assertEqual(mock_request.session.keys(), ['message'])
60
61
62 class TestPrefs(TwoFactorTestCase):
63
64=== modified file 'identityprovider/views/devices.py'
65--- identityprovider/views/devices.py 2012-02-17 14:41:32 +0000
66+++ identityprovider/views/devices.py 2012-02-22 17:45:23 +0000
67@@ -67,6 +67,8 @@
68 request.user.twofactor_required = False
69 if request.user.twofactor_required != initial:
70 request.user.save()
71+ request.session['message'] = _("Your account details have been "\
72+ "successfully updated")
73 return HttpResponseSeeOther(reverse(DEVICE_LIST))
74
75 devices = request.user.devices.all()
76@@ -86,6 +88,8 @@
77 always_checked=always_checked,
78 as_needed_checked=as_needed_checked,
79 devices=devices,
80+ message=request.session.pop('message', None),
81+ message_style='informational',
82 )
83 return render_to_response('device/list.html', context)
84
85@@ -164,6 +168,9 @@
86 counter=new_counter
87 )
88 twofactor.login(request)
89+ request.session['message'] = _("Authentication device '%s' "\
90+ "has been successfully added" %
91+ device_name)
92 return HttpResponseSeeOther(reverse(DEVICE_LIST))
93 # Otherwise, set the error flag and fall through...
94 error = _("The one-time password didn't match the AES key.")
95@@ -227,7 +234,9 @@
96 request.user.twofactor_required = False
97 request.user.save()
98 twofactor.logout(request)
99-
100+
101+ request.session['message'] = _("Authentication device '%s' has been "\
102+ "successfully deleted" % device.name)
103 return HttpResponseSeeOther('/device-list')
104
105
106@@ -244,8 +253,12 @@
107 device = get_object_or_404(AuthenticationDevice, id=int(device_id))
108 form = DeviceRenameForm(request.POST)
109 if form.is_valid():
110+ original_name = device.name
111 device.name = form.cleaned_data['name']
112 device.save()
113+ request.session['message'] = _("Authentication device '%s' has "\
114+ "been successfully renamed to '%s'" %
115+ (original_name, device.name))
116 return HttpResponseRedirect(reverse(DEVICE_LIST))
117 else:
118 return render_to_response('device/rename.html',