Merge lp:~stevenk/launchpad/squash-archivesubscriptionerror into lp:launchpad

Proposed by Steve Kowalik on 2012-12-12
Status: Merged
Approved by: Steve Kowalik on 2012-12-12
Approved revision: no longer in the source branch.
Merged at revision: 16365
Proposed branch: lp:~stevenk/launchpad/squash-archivesubscriptionerror
Merge into: lp:launchpad
Diff against target: 135 lines (+18/-25)
4 files modified
lib/lp/soyuz/browser/archive.py (+2/-2)
lib/lp/soyuz/browser/archivesubscription.py (+3/-10)
lib/lp/soyuz/browser/sourceslist.py (+6/-13)
lib/lp/soyuz/browser/tests/archivesubscription-views.txt (+7/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/squash-archivesubscriptionerror
Reviewer Review Type Date Requested Status
William Grant code 2012-12-12 Approve on 2012-12-12
Review via email: mp+139382@code.launchpad.net

Commit Message

Stop SourcesListEntriesWidget assuming that the currently logged in user is the only one who activates tokens.

Description of the Change

Fix the cause of the random ArchiveSubscriptionError's we were seeing.

SourcesListEntriesWidget was assuming that self.user was always the user, so when an admin went to activate a token for a user that already had one, the code would check that the admin didn't have an token, which they didn't, so would immediately try and create a token for the user. Which would fail.

I have put a stop to SourcesListEntriesWidget's assumptions.

To post a comment you must log in.
William Grant (wgrant) :
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/soyuz/browser/archive.py'
2--- lib/lp/soyuz/browser/archive.py 2012-11-26 08:40:20 +0000
3+++ lib/lp/soyuz/browser/archive.py 2012-12-12 05:30:25 +0000
4@@ -586,9 +586,9 @@
5 "being dispatched.")
6 self.request.response.addNotification(structured(notification))
7 super(ArchiveViewBase, self).initialize()
8- # Set the archive attribute so SourcesListEntriesWidget can be built
9- # correctly.
10+ # Set properties for SourcesListEntriesWidget.
11 self.archive = self.context
12+ self.sources_list_user = self.user
13
14 @cachedproperty
15 def private(self):
16
17=== modified file 'lib/lp/soyuz/browser/archivesubscription.py'
18--- lib/lp/soyuz/browser/archivesubscription.py 2012-04-17 22:09:28 +0000
19+++ lib/lp/soyuz/browser/archivesubscription.py 2012-12-12 05:30:25 +0000
20@@ -1,8 +1,6 @@
21-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
22+# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
23 # GNU Affero General Public License version 3 (see the file LICENSE).
24
25-# pylint: disable-msg=F0401
26-
27 """Browser views related to archive subscriptions."""
28
29 __metaclass__ = type
30@@ -362,30 +360,25 @@
31 def initialize(self):
32 """Process any posted actions."""
33 super(PersonArchiveSubscriptionView, self).initialize()
34- # Set the archive attribute so SourcesListEntriesWidget can be built
35- # correctly.
36+ # Set properties for SourcesListEntriesWidget.
37 self.archive = self.context.archive
38+ self.sources_list_user = self.context.subscriber
39
40 # If an activation was requested and there isn't a currently
41 # active token, then create a token, provide a notification
42 # and redirect.
43 if self.request.form.get('activate') and not self.active_token:
44 self.context.archive.newAuthToken(self.context.subscriber)
45-
46 self.request.response.redirect(self.request.getURL())
47-
48 # Otherwise, if a regeneration was requested and there is an
49 # active token, then cancel the old token, create a new one,
50 # provide a notification and redirect.
51 elif self.request.form.get('regenerate') and self.active_token:
52 self.active_token.deactivate()
53-
54 self.context.archive.newAuthToken(self.context.subscriber)
55-
56 self.request.response.addNotification(
57 "Launchpad has generated the new password you requested "
58 "for your access to the archive %s. Please follow "
59 "the instructions below to update your custom "
60 "\"sources.list\"." % self.context.archive.displayname)
61-
62 self.request.response.redirect(self.request.getURL())
63
64=== modified file 'lib/lp/soyuz/browser/sourceslist.py'
65--- lib/lp/soyuz/browser/sourceslist.py 2012-01-01 02:58:52 +0000
66+++ lib/lp/soyuz/browser/sourceslist.py 2012-12-12 05:30:25 +0000
67@@ -1,8 +1,6 @@
68-# Copyright 2009 Canonical Ltd. This software is licensed under the
69+# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
70 # GNU Affero General Public License version 3 (see the file LICENSE).
71
72-# pylint: disable-msg=F0401
73-
74 """Browser views for sources list entries."""
75
76 from z3c.ptcompat import ViewPageTemplateFile
77@@ -138,10 +136,7 @@
78
79
80 class SourcesListEntriesWidget:
81- """Setup the sources list entries widget.
82-
83- This class assumes self.user is set in child classes.
84- """
85+ """Setup the sources list entries widget."""
86
87 @cachedproperty
88 def sources_list_entries(self):
89@@ -153,12 +148,10 @@
90 return SourcesListEntriesView(entries, self.request)
91 else:
92 comment = "Personal access of %s (%s) to %s" % (
93- self.user.displayname,
94- self.user.name,
95- self.archive.displayname)
96+ self.sources_list_user.displayname,
97+ self.sources_list_user.name, self.archive.displayname)
98 entries = SourcesListEntries(
99- self.archive.distribution,
100- self.active_token.archive_url,
101+ self.archive.distribution, self.active_token.archive_url,
102 self.archive.series_with_sources)
103 return SourcesListEntriesView(
104 entries, self.request, comment=comment)
105@@ -168,7 +161,7 @@
106 """Return the corresponding current token for this subscription."""
107 token_set = getUtility(IArchiveAuthTokenSet)
108 return token_set.getActiveTokenForArchiveAndPerson(
109- self.archive, self.user)
110+ self.archive, self.sources_list_user)
111
112 @property
113 def archive_url(self):
114
115=== modified file 'lib/lp/soyuz/browser/tests/archivesubscription-views.txt'
116--- lib/lp/soyuz/browser/tests/archivesubscription-views.txt 2012-12-10 13:43:47 +0000
117+++ lib/lp/soyuz/browser/tests/archivesubscription-views.txt 2012-12-12 05:30:25 +0000
118@@ -363,6 +363,7 @@
119 >>> view = create_initialized_view(spiv_subscription, name="+index")
120 >>> view.active_token.token == original_token
121 False
122+ >>> current_token = view.active_token.token
123
124 The security for the PersonalArchiveSubscription provides spiv, as the
125 subscriber, with view access:
126@@ -384,3 +385,9 @@
127 >>> check_permission('launchpad.View', spiv_subscription)
128 True
129
130+Now that we're logged in as Celso, the view still realizes the user in question
131+is spiv:
132+
133+ >>> view = create_initialized_view(spiv_subscription, name="+index")
134+ >>> view.active_token.token == current_token
135+ True