Merge lp:~rockstar/launchpad/fix-reassign-ownership-of-recipes into lp:launchpad

Proposed by Paul Hummer
Status: Merged
Approved by: Deryck Hodge
Approved revision: no longer in the source branch.
Merged at revision: 11860
Proposed branch: lp:~rockstar/launchpad/fix-reassign-ownership-of-recipes
Merge into: lp:launchpad
Diff against target: 129 lines (+84/-0)
2 files modified
lib/lp/code/browser/sourcepackagerecipe.py (+22/-0)
lib/lp/code/browser/tests/test_sourcepackagerecipe.py (+62/-0)
To merge this branch: bzr merge lp:~rockstar/launchpad/fix-reassign-ownership-of-recipes
Reviewer Review Type Date Requested Status
Deryck Hodge (community) code Approve
Review via email: mp+39590@code.launchpad.net

Commit message

Fix the source package recipe edit flow for admins to prevent accidental changes.

Description of the change

This branch removes some widgets that aren't compatible with launchpad.Admin in the SourcePackageRecipe edit flow. It changes the owner widget to be a lazr-js person picker in the cases where it's an admin editing the recipe.

To post a comment you must log in.
Revision history for this message
Deryck Hodge (deryck) wrote :

Looks fine to me, especially since we talked it through in person.

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/code/browser/sourcepackagerecipe.py'
2--- lib/lp/code/browser/sourcepackagerecipe.py 2010-10-25 13:16:10 +0000
3+++ lib/lp/code/browser/sourcepackagerecipe.py 2010-10-29 00:29:48 +0000
4@@ -26,6 +26,7 @@
5 from storm.locals import Store
6 from zope.component import getUtility
7 from zope.event import notify
8+from zope.formlib import form
9 from zope.interface import (
10 implements,
11 Interface,
12@@ -54,6 +55,7 @@
13 stepthrough,
14 structured,
15 )
16+from canonical.launchpad.webapp.authorization import check_permission
17 from canonical.launchpad.webapp.breadcrumb import Breadcrumb
18 from canonical.widgets.itemswidgets import LabeledMultiCheckBoxWidget
19 from lp.code.errors import (
20@@ -380,6 +382,26 @@
21 schema = ISourcePackageAddEditSchema
22 custom_widget('distros', LabeledMultiCheckBoxWidget)
23
24+ def setUpFields(self):
25+ super(SourcePackageRecipeEditView, self).setUpFields()
26+
27+ if check_permission('launchpad.Admin', self.context):
28+ # Exclude the PPA archive dropdown.
29+ self.form_fields = self.form_fields.omit('daily_build_archive')
30+
31+ owner_field = self.schema['owner']
32+ any_owner_choice = Choice(
33+ __name__='owner', title=owner_field.title,
34+ description=(u"As an administrator you are able to reassign"
35+ u" this branch to any person or team."),
36+ required=True, vocabulary='ValidPersonOrTeam')
37+ any_owner_field = form.Fields(
38+ any_owner_choice, render_context=self.render_context)
39+ # Replace the normal owner field with a more permissive vocab.
40+ self.form_fields = self.form_fields.omit('owner')
41+ self.form_fields = any_owner_field + self.form_fields
42+
43+
44 @property
45 def initial_values(self):
46 return {
47
48=== modified file 'lib/lp/code/browser/tests/test_sourcepackagerecipe.py'
49--- lib/lp/code/browser/tests/test_sourcepackagerecipe.py 2010-10-26 15:47:24 +0000
50+++ lib/lp/code/browser/tests/test_sourcepackagerecipe.py 2010-10-29 00:29:48 +0000
51@@ -16,9 +16,11 @@
52 from mechanize import LinkNotFoundError
53 from pytz import utc
54 import transaction
55+from zope.component import getUtility
56 from zope.security.interfaces import Unauthorized
57 from zope.security.proxy import removeSecurityProxy
58
59+from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
60 from canonical.launchpad.testing.pages import (
61 extract_text,
62 find_main_content,
63@@ -420,6 +422,66 @@
64 self.assertTextMatchesExpressionIgnoreWhitespace(
65 pattern, main_text)
66
67+ def test_admin_edit(self):
68+ self.factory.makeDistroSeries(
69+ displayname='Mumbly Midget', name='mumbly',
70+ distribution=self.ppa.distribution)
71+ product = self.factory.makeProduct(
72+ name='ratatouille', displayname='Ratatouille')
73+ veggie_branch = self.factory.makeBranch(
74+ owner=self.chef, product=product, name='veggies')
75+ meat_branch = self.factory.makeBranch(
76+ owner=self.chef, product=product, name='meat')
77+ recipe = self.factory.makeSourcePackageRecipe(
78+ owner=self.chef, registrant=self.chef,
79+ name=u'things', description=u'This is a recipe',
80+ distroseries=self.squirrel, branches=[veggie_branch],
81+ daily_build_archive=self.ppa)
82+
83+ meat_path = meat_branch.bzr_identity
84+ expert = getUtility(ILaunchpadCelebrities).admin.teamowner
85+
86+ browser = self.getUserBrowser(canonical_url(recipe), user=expert)
87+ browser.getLink('Edit recipe').click()
88+
89+ # There shouldn't be a daily build archive property.
90+ self.assertRaises(
91+ LookupError,
92+ browser.getControl,
93+ name='field.daily_build_archive')
94+
95+ browser.getControl(name='field.name').value = 'fings'
96+ browser.getControl('Description').value = 'This is stuff'
97+ browser.getControl('Recipe text').value = (
98+ MINIMAL_RECIPE_TEXT % meat_path)
99+ browser.getControl('Secret Squirrel').click()
100+ browser.getControl('Mumbly Midget').click()
101+ browser.getControl('Update Recipe').click()
102+
103+ pattern = """\
104+ Master Chef's fings recipe
105+ .*
106+
107+ Description
108+ This is stuff
109+
110+ Recipe information
111+ Build schedule: Built on request
112+ Owner: Master Chef
113+ Base branch: lp://dev/~chef/ratatouille/meat
114+ Debian version: 0\+\{revno\}
115+ Daily build archive:
116+ Secret PPA
117+ Distribution series: Mumbly Midget
118+ .*
119+
120+ Recipe contents
121+ # bzr-builder format 0.2 deb-version 0\+\{revno\}
122+ lp://dev/~chef/ratatouille/meat"""
123+ main_text = extract_text(find_main_content(browser.contents))
124+ self.assertTextMatchesExpressionIgnoreWhitespace(
125+ pattern, main_text)
126+
127 def test_edit_recipe_forbidden_instruction(self):
128 self.factory.makeDistroSeries(
129 displayname='Mumbly Midget', name='mumbly',