Merge lp:~jtv/launchpad/bug-135052 into lp:launchpad

Proposed by Jeroen T. Vermeulen on 2010-01-21
Status: Merged
Approved by: Curtis Hovey on 2010-01-22
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~jtv/launchpad/bug-135052
Merge into: lp:launchpad
Diff against target: 70 lines (+52/-0)
2 files modified
lib/lp/translations/browser/potemplate.py (+15/-0)
lib/lp/translations/stories/standalone/xx-potemplate-admin.txt (+37/-0)
To merge this branch: bzr merge lp:~jtv/launchpad/bug-135052
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve on 2010-01-22
Henning Eggers 2010-01-21 Pending
Review via email: mp+17824@code.launchpad.net

Commit Message

Catch attempt to set both productseries and distroseries for a POTemplate.

To post a comment you must log in.
Jeroen T. Vermeulen (jtv) wrote :

= Bug 135052 =

A failure to validate input to the POTemplate admin form meant that an administrator could attempt to assign a translation template to both a ProductSeries and a DistroSeries. This triggered and assertion failure (and would otherwise have violated a database constraint). Actually this was an old, known bug that we never bothered to fix because it can only affect a handful of people, and even then when they attempt to do something that they know they shouldn't. I'm only fixing it now because we have a zero-oops policy.

In this branch you'll see a validation method for the form added, plus of course a test to exercise it. The solution is so idiomatic and, frankly, bloody obvious that I did not bother having a proper pre-imp call.

Test:
{{{
./bin/test -vv -t xx-potemplate-admin
}}}

No lint.

Jeroen

Curtis Hovey (sinzui) wrote :

Hi Jeroen.

Thanks for fixing this oops.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/translations/browser/potemplate.py'
2--- lib/lp/translations/browser/potemplate.py 2010-01-20 20:36:13 +0000
3+++ lib/lp/translations/browser/potemplate.py 2010-01-26 12:48:20 +0000
4@@ -556,6 +556,21 @@
5 label = 'Administer translation template'
6 page_title = "Administer"
7
8+ def validate(self, data):
9+ distroseries = data['distroseries']
10+ productseries = data['productseries']
11+ if distroseries is not None and productseries is not None:
12+ message = ("Choose a distribution release series or a project "
13+ "release series, but not both.")
14+ elif distroseries is None and productseries is None:
15+ message = ("Choose either a distribution release series or a "
16+ "project release series.")
17+ else:
18+ message = None
19+
20+ if message is not None:
21+ self.addError(message)
22+
23
24 class POTemplateExportView(BaseExportView):
25 """Request downloads of a `POTemplate` and its translations."""
26
27=== modified file 'lib/lp/translations/stories/standalone/xx-potemplate-admin.txt'
28--- lib/lp/translations/stories/standalone/xx-potemplate-admin.txt 2009-12-11 11:33:39 +0000
29+++ lib/lp/translations/stories/standalone/xx-potemplate-admin.txt 2010-01-26 12:48:20 +0000
30@@ -254,3 +254,40 @@
31 >>> group_owner_browser.getControl('Change').click()
32
33
34+Input Check
35+-----------
36+
37+The template admin form requires either a productseries or a
38+distroseries.
39+
40+ >>> login(ANONYMOUS)
41+ >>> product = factory.makeProduct(name='aproduct')
42+ >>> template = factory.makePOTemplate(
43+ ... productseries=product.getSeries('trunk'))
44+ >>> template_url = canonical_url(template)
45+ >>> logout()
46+
47+ >>> admin_browser.open(template_url + '/+admin')
48+
49+ >>> admin_browser.getControl(name='field.distroseries').value = [None]
50+ >>> admin_browser.getControl(name='field.productseries').value = ''
51+ >>> admin_browser.getControl('Change').click()
52+ >>> print_errors(admin_browser.contents)
53+ There is 1 error.
54+ Choose either a distribution release series or a project release series.
55+
56+It can't be both.
57+
58+ >>> admin_browser.open(template_url + '/+admin')
59+
60+ >>> admin_browser.getControl(name='field.distroseries').value = [
61+ ... 'ubuntu/hoary']
62+ >>> print admin_browser.getControl(name='field.productseries').value
63+ aproduct/trunk
64+ >>> admin_browser.getControl('Change').click()
65+ >>> print_errors(admin_browser.contents)
66+ There is 1 error.
67+ Choose a distribution release series or a project release series,
68+ but not both.
69+
70+