Merge lp:~edwin-grubbs/launchpad/bug-555734-coc-oops into lp:launchpad

Proposed by Edwin Grubbs
Status: Merged
Approved by: Aaron Bentley
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~edwin-grubbs/launchpad/bug-555734-coc-oops
Merge into: lp:launchpad
Diff against target: 155 lines (+84/-14)
2 files modified
lib/lp/registry/browser/tests/coc-views.txt (+67/-0)
lib/lp/registry/templates/codeofconduct-list.pt (+17/-14)
To merge this branch: bzr merge lp:~edwin-grubbs/launchpad/bug-555734-coc-oops
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Canonical Launchpad Engineering code Pending
Review via email: mp+23268@code.launchpad.net

Commit message

Fix oops on /codeofconduct page when a user has a gpg key but has not signed the CoC.

Description of the change

Summary
-------

Fixed bug where a template tried to access to user/gpg_keys
attribute as user/gpgkeys. I changed the template variable to
gpg_keys to make it more consistent with user/gpg_keys.

Tests
-----

./bin/test -vv -t coc-views.txt

Demo and Q/A
------------

* Run this sql to add a gpg key, since the bug only occured when
  a user had a gpg key but had not signed the CoC yet.

  INSERT INTO gpgkey (
        owner, keyid, fingerprint, active, algorithm, keysize)
  SELECT
    52,
    keyid,
    'ABCDEF0123456789ABCDDCBA0000111112345670',
    active,
    algorithm,
    keysize
  FROM gpgkey
  WHERE id = 1;

* Open http://launchpad.dev/codeofcontact
  * Log in as <email address hidden>
  * You should no longer get an oops.

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/browser/tests/coc-views.txt'
2--- lib/lp/registry/browser/tests/coc-views.txt 2009-11-13 13:06:50 +0000
3+++ lib/lp/registry/browser/tests/coc-views.txt 2010-04-12 20:36:33 +0000
4@@ -2,6 +2,9 @@
5 Codes of conduct views
6 ======================
7
8+Signed code of conduct for a user
9+---------------------------------
10+
11 The PersonCodeOfConductEditView controls ~person/+codesofconduct. It displays
12 the person's name in the page label.
13
14@@ -10,3 +13,67 @@
15 >>> view = create_initialized_view(geddy, '+codesofconduct')
16 >>> print view.label
17 Codes of Conduct for Geddy Lee
18+
19+
20+Directions for signing code of conduct
21+--------------------------------------
22+
23+If the user hasn't signed the code of conduct and does not have a GPG
24+key registered, directions are shown.
25+
26+ >>> def print_coc_directions(content):
27+ ... ol = content.find('ol')
28+ ... if ol is not None:
29+ ... for index, li in enumerate(ol.findAll('li')):
30+ ... print '%s. %s' % ((index+1), extract_text(li))
31+ >>> user = factory.makePerson()
32+ >>> login_person(user)
33+ >>> from lp.registry.interfaces.person import IPersonSet
34+ >>> from lp.registry.interfaces.codeofconduct import ICodeOfConductSet
35+ >>> from canonical.launchpad.testing.pages import (
36+ ... extract_text, find_tag_by_id)
37+ >>> coc_set = getUtility(ICodeOfConductSet)
38+ >>> view = create_initialized_view(coc_set, '+index', principal=user)
39+ >>> print_coc_directions(find_tag_by_id(view.render(), 'maincontent'))
40+ 1. Register an OpenPGP key.
41+ 2. Download the current Code of Conduct.
42+ 3. Sign it!
43+
44+If the user hasn't signed the code of conduct but does have a GPG key
45+registered, directions are shown with a message indicating that the
46+first step can be skipped.
47+
48+ >>> _ignore = factory.makeGPGKey(user)
49+ >>> view = create_initialized_view(coc_set, '+index', principal=user)
50+ >>> print_coc_directions(find_tag_by_id(view.render(), 'maincontent'))
51+ 1. Register an OpenPGP key.
52+ It appears you have already done this.
53+ The key ... is registered on your account.
54+ You can skip to the next step if you are not intending
55+ on signing with a different key.
56+ 2. Download the current Code of Conduct.
57+ 3. Sign it!
58+
59+If the user has multiple keys, a count is shown.
60+
61+ >>> _ignore = factory.makeGPGKey(user)
62+ >>> view = create_initialized_view(coc_set, '+index', principal=user)
63+ >>> print_coc_directions(find_tag_by_id(view.render(), 'maincontent'))
64+ 1. Register an OpenPGP key.
65+ It appears you have already done this.
66+ 2 keys are registered on your account.
67+ You can skip to the next step if you are not intending
68+ on signing with a different key.
69+ 2. Download the current Code of Conduct.
70+ 3. Sign it!
71+
72+If the user has already signed the code of conduct, no directions are shown.
73+
74+ >>> admin = getUtility(IPersonSet).getByEmail('admin@canonical.com')
75+ >>> login_person(admin)
76+ >>> view = create_initialized_view(coc_set, '+index', principal=admin)
77+ >>> content = find_tag_by_id(view.render(), 'maincontent')
78+ >>> print_coc_directions(content)
79+ >>> print extract_text(content)
80+ Ubuntu Codes of Conduct...
81+ Congratulations, you have already signed the Ubuntu Code of Conduct...
82
83=== modified file 'lib/lp/registry/templates/codeofconduct-list.pt'
84--- lib/lp/registry/templates/codeofconduct-list.pt 2010-03-11 16:09:29 +0000
85+++ lib/lp/registry/templates/codeofconduct-list.pt 2010-04-12 20:36:33 +0000
86@@ -11,7 +11,7 @@
87 <div metal:fill-slot="main"
88 tal:define="user view/user;
89 is_ubuntu_coc_signer user/is_ubuntu_coc_signer|nothing;
90- gpgkeys user/gpg_keys|nothing">
91+ gpg_keys user/gpg_keys|nothing">
92
93 <h1>Ubuntu Codes of Conduct</h1>
94 <p>
95@@ -32,20 +32,22 @@
96 <ol style="margin-left: 4em">
97 <li>
98 <tal:logged_in condition="user">
99- <a tal:attributes="href string:${user/fmt:url}/+editpgpkeys">Register
100- an OpenPGP key</a>.</tal:logged_in>
101+ <a tal:attributes="href string:${user/fmt:url}/+editpgpkeys">
102+ Register an OpenPGP key</a>.</tal:logged_in>
103 <tal:not_logged_in tal:condition="not: user">
104 <a href="+login">Log in</a> and register an OpenPGP key.
105 </tal:not_logged_in>
106- <p class="informational message" tal:condition="gpgkeys">
107- It appears you have already done this;
108+ <p tal:condition="gpg_keys"
109+ class="informational message"
110+ style="margin-top: 20px">
111+ It appears you have already done this.
112
113- <tal:multiple_keys condition="python: gpgkeys.count() > 1">
114- <span tal:replace="user/gpgkeys/count" /> keys are
115+ <tal:multiple_keys condition="python: gpg_keys.count() > 1">
116+ <span tal:replace="gpg_keys/count" /> keys are
117 </tal:multiple_keys>
118
119- <tal:single_key condition="python: gpgkeys.count() == 1">
120- the key <code tal:content="python: gpgkeys[0].keyid" /> is
121+ <tal:single_key condition="python: gpg_keys.count() == 1">
122+ The key <code tal:content="python: gpg_keys[0].keyid" /> is
123 </tal:single_key>
124
125 registered on your account. You can skip to the next step if
126@@ -54,15 +56,16 @@
127 </p>
128 </li>
129 <li><a tal:attributes="href
130- string:${context/current_code_of_conduct/fmt:url}/+download">Download</a>
131- the current Code of Conduct.</li>
132+ string:${context/current_code_of_conduct/fmt:url}/+download">
133+ Download</a> the current Code of Conduct.</li>
134 <li><a tal:attributes="href
135- string:${context/current_code_of_conduct/fmt:url}/+sign">Sign it!</a></li>
136+ string:${context/current_code_of_conduct/fmt:url}/+sign">
137+ Sign it!</a></li>
138 </ol>
139 </div>
140
141 <p tal:condition="is_ubuntu_coc_signer">
142- Congratulations; you have already <a tal:attributes="href
143+ Congratulations, you have already <a tal:attributes="href
144 string:${user/fmt:url}/+codesofconduct">signed</a> the Ubuntu Code
145 of Conduct.
146 </p>
147@@ -77,7 +80,7 @@
148 </tal:not_current>
149 </tal:codes>
150 </ul>
151-
152+
153 <br />
154 <p>
155 <a tal:replace="structure context/menu:overview/admin/render" />