Merge lp:~roadmr/canonical-identity-provider/2fa-use-backup-codes-in-sequence into lp:canonical-identity-provider/release

Proposed by Daniel Manrique
Status: Merged
Approved by: Daniel Manrique
Approved revision: no longer in the source branch.
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: lp:~roadmr/canonical-identity-provider/2fa-use-backup-codes-in-sequence
Merge into: lp:canonical-identity-provider/release
Diff against target: 88 lines (+34/-14)
3 files modified
src/webui/templates/device/code-list.html (+20/-12)
src/webui/templates/device/print-codes.html (+2/-0)
src/webui/tests/test_views_devices.py (+12/-2)
To merge this branch: bzr merge lp:~roadmr/canonical-identity-provider/2fa-use-backup-codes-in-sequence
Reviewer Review Type Date Requested Status
Maximiliano Bertacchini Approve
Review via email: mp+382088@code.launchpad.net

Commit message

Tweaks to list of printable codes for more clarity.

   * Instructions on using them in order and crossing them out once consumed.
   * Show actual codes in a table format with an ordering indicator
   * Fix printable layout with smaller font and padding so it all fits in one sheet and doesn't truncate.

Description of the change

Part zero of 2FA backup/recovery improvements.

To post a comment you must log in.
Revision history for this message
Maximiliano Bertacchini (maxiberta) wrote :

LGTM, thanks. Just a CSS question.

review: Approve
Revision history for this message
Daniel Manrique (roadmr) wrote :

Thanks!

Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :
Revision history for this message
Maximiliano Bertacchini (maxiberta) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/webui/templates/device/code-list.html'
--- src/webui/templates/device/code-list.html 2019-12-17 14:05:19 +0000
+++ src/webui/templates/device/code-list.html 2020-04-14 15:09:37 +0000
@@ -1,19 +1,27 @@
1{% load i18n %}1{% load i18n %}
2<div id="codes" data-qa-id="codelist">2<div id="codes" data-qa-id="codelist">
3 <ol class="p-list">3 <table style="margin-bottom: 2em">
4 {% for code in codes %}4 <thead>
5 <li class="p-list__item">{% spaceless %}5 <tr>
6 {% if forloop.counter0 < counter|default:0 %}6 <th>Order</th>
7 <strike>{{ code }}</strike>7 <th>Access Code</th>
8 {% else %}8 </tr>
9 {{ code }}9 </thead>
10 {% endif %}10 {% for code in codes %}
11 {% endspaceless %}</li>11 <tr>
12 {% endfor %}12 <td>{{forloop.counter }}</td>{% spaceless %}
13 </ol>13 <td>{% if forloop.counter0 < counter|default:0 %}
14 <strike>{{ code }}</strike>
15 {% else %}{{ code }}
16 {% endif %}
17 {% endspaceless %}</td>
18 </tr>
19 {% endfor %}
20 </table>
14</div>21</div>
1522
16<style media="print">23<style media="print">
17header, .p-sidebar, footer, p { display: none; }24header, .p-sidebar, footer, p { display: none; }
18#codes ol { list-style:none; margin:0; padding:0 }25#codes table { margin:0; padding:0}
26#codes table tr td{ margin:0; padding:0 ; font-size: 80%}
19</style>27</style>
2028
=== modified file 'src/webui/templates/device/print-codes.html'
--- src/webui/templates/device/print-codes.html 2020-01-22 12:52:26 +0000
+++ src/webui/templates/device/print-codes.html 2020-04-14 15:09:37 +0000
@@ -18,6 +18,8 @@
18{% block content %}18{% block content %}
19 <h2>{% trans "Printable backup codes" %}</h2>19 <h2>{% trans "Printable backup codes" %}</h2>
20 <p>{% trans "Print this list of backup codes and keep them safe." %}</p>20 <p>{% trans "Print this list of backup codes and keep them safe." %}</p>
21 <p>{% trans "The codes must be used in the order shown below." %}</p>
22 <p>{% trans "Each code can be used only once, please cross it out once you've used it." %}</p>
21 {% include 'device/code-list.html' %}23 {% include 'device/code-list.html' %}
22 <button class="p-button--positive" id="printbtn" onclick="window.print()" data-qa-id="print_codes">{% trans "Print Codes" %}</button>24 <button class="p-button--positive" id="printbtn" onclick="window.print()" data-qa-id="print_codes">{% trans "Print Codes" %}</button>
23 {% if token and not needs_renewal %}25 {% if token and not needs_renewal %}
2426
=== modified file 'src/webui/tests/test_views_devices.py'
--- src/webui/tests/test_views_devices.py 2019-12-17 14:05:19 +0000
+++ src/webui/tests/test_views_devices.py 2020-04-14 15:09:37 +0000
@@ -572,7 +572,12 @@
572 response = self.client.get(self.print_url)572 response = self.client.get(self.print_url)
573573
574 doc = PyQuery(response.content)574 doc = PyQuery(response.content)
575 code_nodes = doc.find('#codes li')575 code_nodes = doc.find('#codes td')
576 # We only need every other <td> (the first one is the sequence
577 # number)
578 code_nodes = [
579 node for idx, node in enumerate(code_nodes)
580 if idx % 2]
576 used = code_nodes[:position]581 used = code_nodes[:position]
577 unused = code_nodes[position:]582 unused = code_nodes[position:]
578583
@@ -647,7 +652,12 @@
647 response = self.client.get(self.generate_url)652 response = self.client.get(self.generate_url)
648653
649 doc = PyQuery(response.content)654 doc = PyQuery(response.content)
650 code_nodes = doc.find('#codes li')655 code_nodes = doc.find('#codes td')
656 # We only need every other <td> (the first one is the sequence
657 # number)
658 code_nodes = [
659 node for idx, node in enumerate(code_nodes)
660 if idx % 2]
651661
652 start = settings.TWOFACTOR_PAPER_CODES * 4662 start = settings.TWOFACTOR_PAPER_CODES * 4
653 end = settings.TWOFACTOR_PAPER_CODES * 5663 end = settings.TWOFACTOR_PAPER_CODES * 5