Merge lp:~thumper/launchpad/show-recipe-upload-issue into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 12186
Proposed branch: lp:~thumper/launchpad/show-recipe-upload-issue
Merge into: lp:launchpad
Diff against target: 129 lines (+69/-0)
3 files modified
lib/lp/app/browser/tales.py (+6/-0)
lib/lp/code/browser/sourcepackagerecipe.py (+23/-0)
lib/lp/code/browser/tests/test_sourcepackagerecipe.py (+40/-0)
To merge this branch: bzr merge lp:~thumper/launchpad/show-recipe-upload-issue
Reviewer Review Type Date Requested Status
Curtis Hovey (community) ui Approve
Graham Binns (community) code Approve
Review via email: mp+45804@code.launchpad.net

Commit message

[r=gmb][ui=sinzui][bug=700864] Show a warning to the user if the daily build won't happen due to PPA upload permission problems.

Description of the change

This issue was discovered while debugging a problem with the awn-testing recipe.

If the recipe owner does not have upload rights to the daily build PPA the daily recipe jobs are not created.

Here is an example of the error shown:
  http://people.canonical.com/~tim/recipe_upload_issue.png

This is not something we can always check on creation or editing as the person may be removed from a team that has a PPA that was having the builds working.

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :

I'm happy with the code here but it should probably get a review for the UI, too. I'll request a UI review for it whilst I'm here.

review: Approve (code)
Revision history for this message
Curtis Hovey (sinzui) wrote :

Look good.

review: Approve (ui)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/app/browser/tales.py'
2--- lib/lp/app/browser/tales.py 2010-11-03 08:17:36 +0000
3+++ lib/lp/app/browser/tales.py 2011-01-11 01:27:00 +0000
4@@ -75,6 +75,12 @@
5 SEPARATOR = ' : '
6
7
8+def format_link(obj, view_name=None):
9+ """Return the equivalent of obj/fmt:link as a string."""
10+ adapter = queryAdapter(obj, IPathAdapter, 'fmt')
11+ return adapter.link(view_name)
12+
13+
14 class MenuLinksDict(dict):
15 """A dict class to construct menu links when asked for and not before.
16
17
18=== modified file 'lib/lp/code/browser/sourcepackagerecipe.py'
19--- lib/lp/code/browser/sourcepackagerecipe.py 2010-12-22 02:01:36 +0000
20+++ lib/lp/code/browser/sourcepackagerecipe.py 2011-01-11 01:27:00 +0000
21@@ -73,6 +73,7 @@
22 LaunchpadFormView,
23 render_radio_widget_part,
24 )
25+from lp.app.browser.tales import format_link
26 from lp.code.errors import (
27 BuildAlreadyPending,
28 NoSuchBranch,
29@@ -194,6 +195,16 @@
30 # are put into production. spec=sourcepackagerecipes
31 super(SourcePackageRecipeView, self).initialize()
32 self.request.response.addWarningNotification(RECIPE_BETA_MESSAGE)
33+ recipe = self.context
34+ if self.dailyBuildWithoutUploadPermission():
35+ self.request.response.addWarningNotification(
36+ structured(
37+ "Daily builds for this recipe will <strong>not</strong> "
38+ "occur.<br/><br/>The owner of the recipe (%s) does not "
39+ "have permission to upload packages into the daily "
40+ "build PPA (%s)" % (
41+ format_link(recipe.owner),
42+ format_link(recipe.daily_build_archive))))
43
44 @property
45 def page_title(self):
46@@ -217,6 +228,18 @@
47 break
48 return builds
49
50+ def dailyBuildWithoutUploadPermission(self):
51+ """Returns true if there are upload permissions to the daily archive.
52+
53+ If the recipe isn't built daily, we don't consider this a problem.
54+ """
55+ recipe = self.context
56+ ppa = recipe.daily_build_archive
57+ if recipe.build_daily:
58+ has_upload = ppa.checkArchivePermission(recipe.owner)
59+ return not has_upload
60+ return False
61+
62
63 class SourcePackageRecipeRequestBuildsView(LaunchpadFormView):
64 """A view for requesting builds of a SourcePackageRecipe."""
65
66=== modified file 'lib/lp/code/browser/tests/test_sourcepackagerecipe.py'
67--- lib/lp/code/browser/tests/test_sourcepackagerecipe.py 2010-12-22 02:01:36 +0000
68+++ lib/lp/code/browser/tests/test_sourcepackagerecipe.py 2011-01-11 01:27:00 +0000
69@@ -25,6 +25,7 @@
70 extract_text,
71 find_main_content,
72 find_tags_by_class,
73+ get_feedback_messages,
74 get_radio_button_text_for_field,
75 )
76 from canonical.launchpad.webapp import canonical_url
77@@ -53,6 +54,7 @@
78 person_logged_in,
79 )
80 from lp.testing.factory import remove_security_proxy_and_shout_at_engineer
81+from lp.testing.views import create_initialized_view
82
83
84 class TestCaseForRecipe(BrowserTestCase):
85@@ -1113,6 +1115,44 @@
86 "An identical build is already pending for ubuntu woody.",
87 extract_text(find_main_content(browser.contents)))
88
89+ def makeRecipeWithUploadIssues(self):
90+ """Make a recipe where the owner can't upload to the PPA."""
91+ # This occurs when the PPA that the recipe is being built daily into
92+ # is owned by a team, and the owner of the recipe isn't in the team
93+ # that owns the PPA.
94+ registrant = self.factory.makePerson()
95+ owner_team = self.factory.makeTeam(members=[registrant], name='team1')
96+ ppa_team = self.factory.makeTeam(members=[registrant], name='team2')
97+ ppa = self.factory.makeArchive(owner=ppa_team, name='ppa')
98+ return self.factory.makeSourcePackageRecipe(
99+ registrant=registrant, owner=owner_team, daily_build_archive=ppa,
100+ build_daily=True)
101+
102+ def test_owner_with_no_ppa_upload_permission(self):
103+ # Daily build with upload issues are a problem.
104+ recipe = self.makeRecipeWithUploadIssues()
105+ view = create_initialized_view(recipe, '+index')
106+ self.assertTrue(view.dailyBuildWithoutUploadPermission())
107+
108+ def test_owner_with_no_ppa_upload_permission_non_daily(self):
109+ # Non-daily builds with upload issues are not so much of an issue.
110+ recipe = self.makeRecipeWithUploadIssues()
111+ with person_logged_in(recipe.registrant):
112+ recipe.build_daily = False
113+ view = create_initialized_view(recipe, '+index')
114+ self.assertFalse(view.dailyBuildWithoutUploadPermission())
115+
116+ def test_owner_with_no_ppa_upload_permission_message(self):
117+ # If there is an issue, a message is shown.
118+ recipe = self.makeRecipeWithUploadIssues()
119+ browser = self.getViewBrowser(recipe, '+index')
120+ messages = get_feedback_messages(browser.contents)
121+ self.assertEqual(
122+ "Daily builds for this recipe will not occur.\n"
123+ "The owner of the recipe (Team1) does not have permission to "
124+ "upload packages into the daily build PPA (PPA for Team2)",
125+ messages[-1])
126+
127
128 class TestSourcePackageRecipeBuildView(BrowserTestCase):
129 """Test behaviour of SourcePackageReciptBuildView."""