Merge lp:~wgrant/launchpad/bugsummary-v2-rebuild-ap into lp:launchpad

Proposed by William Grant
Status: Merged
Merged at revision: 15715
Proposed branch: lp:~wgrant/launchpad/bugsummary-v2-rebuild-ap
Merge into: lp:launchpad
Prerequisite: lp:launchpad/db-devel
Diff against target: 273 lines (+76/-45)
2 files modified
lib/lp/bugs/scripts/bugsummaryrebuild.py (+31/-14)
lib/lp/bugs/scripts/tests/test_bugsummaryrebuild.py (+45/-31)
To merge this branch: bzr merge lp:~wgrant/launchpad/bugsummary-v2-rebuild-ap
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+117211@code.launchpad.net

Commit message

Teach bugsummaryrebuild about BugSummary.access_policy.

Description of the change

This branch teaches bugsummaryrebuild about BugSummary.access_policy, as implemented in the DB in https://code.launchpad.net/~wgrant/launchpad/bugsummary-v2-apg-db/+merge/116595, completing the BugSummary.access_policy work. Pretty mechanical.

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

Looks good.

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/bugs/scripts/bugsummaryrebuild.py'
2--- lib/lp/bugs/scripts/bugsummaryrebuild.py 2012-07-24 07:24:58 +0000
3+++ lib/lp/bugs/scripts/bugsummaryrebuild.py 2012-07-30 02:13:23 +0000
4@@ -140,7 +140,8 @@
5 return IStore(RawBugSummary).find(
6 (RawBugSummary.status, RawBugSummary.milestone_id,
7 RawBugSummary.importance, RawBugSummary.has_patch, RawBugSummary.tag,
8- RawBugSummary.viewed_by_id, RawBugSummary.count),
9+ RawBugSummary.viewed_by_id, RawBugSummary.access_policy_id,
10+ RawBugSummary.count),
11 *get_bugsummary_constraint(target))
12
13
14@@ -191,7 +192,8 @@
15 key_cols = (
16 RawBugSummary.status, RawBugSummary.milestone_id,
17 RawBugSummary.importance, RawBugSummary.has_patch,
18- RawBugSummary.tag, RawBugSummary.viewed_by_id)
19+ RawBugSummary.tag, RawBugSummary.viewed_by_id,
20+ RawBugSummary.access_policy_id)
21
22 # Postgres doesn't do bulk updates, so do a delete+add.
23 for key, count in updated.iteritems():
24@@ -253,7 +255,7 @@
25 BugTaskFlat.status, BugTaskFlat.milestone_id,
26 BugTaskFlat.importance,
27 Alias(BugTaskFlat.latest_patch_uploaded != None, 'has_patch'),
28- BugTaskFlat.access_grants),
29+ BugTaskFlat.access_grants, BugTaskFlat.access_policies),
30 tables=[BugTaskFlat],
31 where=And(
32 BugTaskFlat.duplicateof_id == None,
33@@ -271,12 +273,14 @@
34
35 # Prepare a union for all combination of privacy and taggedness.
36 # It'll return a full set of
37- # (status, milestone, importance, has_patch, tag, viewed_by) rows.
38+ # (status, milestone, importance, has_patch, tag, viewed_by, access_policy)
39+ # rows.
40 common_cols = (
41 RelevantTask.status, RelevantTask.milestone_id,
42 RelevantTask.importance, RelevantTask.has_patch)
43 null_tag = Alias(Cast(None, 'text'), 'tag')
44 null_viewed_by = Alias(Cast(None, 'integer'), 'viewed_by')
45+ null_policy = Alias(Cast(None, 'integer'), 'access_policy')
46
47 tag_join = Join(BugTag, BugTag.bugID == RelevantTask.bug_id)
48
49@@ -288,19 +292,31 @@
50 unions = Union(
51 # Public, tagless
52 Select(
53- common_cols + (null_tag, null_viewed_by),
54+ common_cols + (null_tag, null_viewed_by, null_policy),
55 tables=[RelevantTask], where=public_constraint),
56 # Public, tagged
57 Select(
58- common_cols + (BugTag.tag, null_viewed_by),
59+ common_cols + (BugTag.tag, null_viewed_by, null_policy),
60 tables=[RelevantTask, tag_join], where=public_constraint),
61- # Private, tagless
62- Select(
63- common_cols + (null_tag, Unnest(RelevantTask.access_grants)),
64- tables=[RelevantTask], where=private_constraint),
65- # Private, tagged
66- Select(
67- common_cols + (BugTag.tag, Unnest(RelevantTask.access_grants)),
68+ # Private, access grant, tagless
69+ Select(
70+ common_cols +
71+ (null_tag, Unnest(RelevantTask.access_grants), null_policy),
72+ tables=[RelevantTask], where=private_constraint),
73+ # Private, access grant, tagged
74+ Select(
75+ common_cols +
76+ (BugTag.tag, Unnest(RelevantTask.access_grants), null_policy),
77+ tables=[RelevantTask, tag_join], where=private_constraint),
78+ # Private, access policy, tagless
79+ Select(
80+ common_cols +
81+ (null_tag, null_viewed_by, Unnest(RelevantTask.access_policies)),
82+ tables=[RelevantTask], where=private_constraint),
83+ # Private, access policy, tagged
84+ Select(
85+ common_cols +
86+ (BugTag.tag, null_viewed_by, Unnest(RelevantTask.access_policies)),
87 tables=[RelevantTask, tag_join], where=private_constraint),
88 all=True)
89
90@@ -308,7 +324,8 @@
91 proto_key_cols = (
92 BugSummaryPrototype.status, BugSummaryPrototype.milestone_id,
93 BugSummaryPrototype.importance, BugSummaryPrototype.has_patch,
94- BugSummaryPrototype.tag, BugSummaryPrototype.viewed_by_id)
95+ BugSummaryPrototype.tag, BugSummaryPrototype.viewed_by_id,
96+ BugSummaryPrototype.access_policy_id)
97 origin = IStore(BugTaskFlat).with_(relevant_tasks).using(
98 Alias(unions, 'bugsummary_prototype'))
99 results = origin.find(proto_key_cols + (Count(),))
100
101=== modified file 'lib/lp/bugs/scripts/tests/test_bugsummaryrebuild.py'
102--- lib/lp/bugs/scripts/tests/test_bugsummaryrebuild.py 2012-07-12 01:28:17 +0000
103+++ lib/lp/bugs/scripts/tests/test_bugsummaryrebuild.py 2012-07-30 02:13:23 +0000
104@@ -26,6 +26,7 @@
105 rebuild_bugsummary_for_target,
106 )
107 from lp.registry.enums import InformationType
108+from lp.registry.interfaces.accesspolicy import IAccessPolicySource
109 from lp.services.database.lpstorm import IStore
110 from lp.services.log.logger import BufferLogger
111 from lp.testing import TestCaseWithFactory
112@@ -107,22 +108,22 @@
113 with dbuser('bugsummaryrebuild'):
114 apply_bugsummary_changes(
115 product,
116- {(NEW, None, HIGH, False, None, None): 2,
117- (TRIAGED, None, LOW, False, None, None): 4},
118+ {(NEW, None, HIGH, False, None, None, None): 2,
119+ (TRIAGED, None, LOW, False, None, None, None): 4},
120 {}, [])
121 self.assertContentEqual(
122- [(NEW, None, HIGH, False, None, None, 2),
123- (TRIAGED, None, LOW, False, None, None, 4)],
124+ [(NEW, None, HIGH, False, None, None, None, 2),
125+ (TRIAGED, None, LOW, False, None, None, None, 4)],
126 get_bugsummary_rows(product))
127
128 # Delete one, mutate the other.
129 with dbuser('bugsummaryrebuild'):
130 apply_bugsummary_changes(
131 product,
132- {}, {(NEW, None, HIGH, False, None, None): 3},
133- [(TRIAGED, None, LOW, False, None, None)])
134+ {}, {(NEW, None, HIGH, False, None, None, None): 3},
135+ [(TRIAGED, None, LOW, False, None, None, None)])
136 self.assertContentEqual(
137- [(NEW, None, HIGH, False, None, None, 3)],
138+ [(NEW, None, HIGH, False, None, None, None, 3)],
139 get_bugsummary_rows(product))
140
141 def test_rebuild_bugsummary_for_target(self):
142@@ -172,7 +173,7 @@
143 rollup_journal()
144 new_rows = set(get_bugsummary_rows(product))
145 self.assertContentEqual(
146- [(task.status, None, task.importance, False, None, None, 1)],
147+ [(task.status, None, task.importance, False, None, None, None, 1)],
148 new_rows - orig_rows)
149
150
151@@ -186,7 +187,7 @@
152 product = self.factory.makeProduct()
153 bug = self.factory.makeBug(product=product).default_bugtask
154 self.assertContentEqual(
155- [(bug.status, None, bug.importance, False, None, None, 1)],
156+ [(bug.status, None, bug.importance, False, None, None, None, 1)],
157 calculate_bugsummary_rows(product))
158
159 def test_public_tagged(self):
160@@ -196,35 +197,46 @@
161 bug = self.factory.makeBug(
162 product=product, tags=[u'foo', u'bar']).default_bugtask
163 self.assertContentEqual(
164- [(bug.status, None, bug.importance, False, None, None, 1),
165- (bug.status, None, bug.importance, False, u'foo', None, 1),
166- (bug.status, None, bug.importance, False, u'bar', None, 1),
167+ [(bug.status, None, bug.importance, False, None, None, None, 1),
168+ (bug.status, None, bug.importance, False, u'foo', None, None, 1),
169+ (bug.status, None, bug.importance, False, u'bar', None, None, 1),
170 ], calculate_bugsummary_rows(product))
171
172 def test_private_untagged(self):
173 # Private untagged bugs show up with tag = None, viewed_by =
174- # subscriber. There's no viewed_by = None row.
175+ # subscriber; and tag = None, access_policy = ap. There's no
176+ # viewed_by = None, access_policy = None row.
177 product = self.factory.makeProduct()
178- owner = self.factory.makePerson()
179+ o = self.factory.makePerson()
180 bug = self.factory.makeBug(
181- product=product, owner=owner,
182+ product=product, owner=o,
183 information_type=InformationType.USERDATA).default_bugtask
184+ [ap] = getUtility(IAccessPolicySource).find(
185+ [(product, InformationType.USERDATA)])
186 self.assertContentEqual(
187- [(bug.status, None, bug.importance, False, None, owner.id, 1)],
188+ [(bug.status, None, bug.importance, False, None, o.id, None, 1),
189+ (bug.status, None, bug.importance, False, None, None, ap.id, 1)],
190 calculate_bugsummary_rows(product))
191
192 def test_private_tagged(self):
193- # Private tagged bugs show up with viewed_by = subscriber, with a
194- # row for each tag plus an untagged row.
195+ # Private tagged bugs show up with viewed_by = subscriber and
196+ # access_policy = ap rows, each with a row for each tag plus an
197+ # untagged row.
198 product = self.factory.makeProduct()
199- owner = self.factory.makePerson()
200+ o = self.factory.makePerson()
201 bug = self.factory.makeBug(
202- product=product, owner=owner, tags=[u'foo', u'bar'],
203+ product=product, owner=o, tags=[u'foo', u'bar'],
204 information_type=InformationType.USERDATA).default_bugtask
205+ [ap] = getUtility(IAccessPolicySource).find(
206+ [(product, InformationType.USERDATA)])
207 self.assertContentEqual(
208- [(bug.status, None, bug.importance, False, None, owner.id, 1),
209- (bug.status, None, bug.importance, False, u'foo', owner.id, 1),
210- (bug.status, None, bug.importance, False, u'bar', owner.id, 1)],
211+ [(bug.status, None, bug.importance, False, None, o.id, None, 1),
212+ (bug.status, None, bug.importance, False, u'foo', o.id, None, 1),
213+ (bug.status, None, bug.importance, False, u'bar', o.id, None, 1),
214+ (bug.status, None, bug.importance, False, None, None, ap.id, 1),
215+ (bug.status, None, bug.importance, False, u'foo', None, ap.id, 1),
216+ (bug.status, None, bug.importance, False, u'bar', None, ap.id, 1),
217+ ],
218 calculate_bugsummary_rows(product))
219
220 def test_aggregation(self):
221@@ -236,8 +248,8 @@
222 bug3 = self.factory.makeBug(
223 product=product, status=BugTaskStatus.TRIAGED).default_bugtask
224 self.assertContentEqual(
225- [(bug1.status, None, bug1.importance, False, None, None, 2),
226- (bug3.status, None, bug3.importance, False, None, None, 1)],
227+ [(bug1.status, None, bug1.importance, False, None, None, None, 2),
228+ (bug3.status, None, bug3.importance, False, None, None, None, 1)],
229 calculate_bugsummary_rows(product))
230
231 def test_has_patch(self):
232@@ -249,8 +261,8 @@
233 bug2 = self.factory.makeBug(
234 product=product, status=BugTaskStatus.TRIAGED).default_bugtask
235 self.assertContentEqual(
236- [(bug1.status, None, bug1.importance, True, None, None, 1),
237- (bug2.status, None, bug2.importance, False, None, None, 1)],
238+ [(bug1.status, None, bug1.importance, True, None, None, None, 1),
239+ (bug2.status, None, bug2.importance, False, None, None, None, 1)],
240 calculate_bugsummary_rows(product))
241
242 def test_milestone(self):
243@@ -264,8 +276,10 @@
244 product=product, milestone=mile2,
245 status=BugTaskStatus.TRIAGED).default_bugtask
246 self.assertContentEqual(
247- [(bug1.status, mile1.id, bug1.importance, False, None, None, 1),
248- (bug2.status, mile2.id, bug2.importance, False, None, None, 1)],
249+ [(bug1.status, mile1.id, bug1.importance, False, None, None, None,
250+ 1),
251+ (bug2.status, mile2.id, bug2.importance, False, None, None, None,
252+ 1)],
253 calculate_bugsummary_rows(product))
254
255 def test_distribution_includes_packages(self):
256@@ -282,7 +296,7 @@
257 # The DistributionSourcePackage task shows up in the
258 # Distribution's rows.
259 self.assertContentEqual(
260- [(bug1.status, None, bug1.importance, False, None, None, 1)],
261+ [(bug1.status, None, bug1.importance, False, None, None, None, 1)],
262 calculate_bugsummary_rows(dsp.distribution))
263 self.assertContentEqual(
264 calculate_bugsummary_rows(dsp.distribution),
265@@ -290,7 +304,7 @@
266
267 # The SourcePackage task shows up in the DistroSeries' rows.
268 self.assertContentEqual(
269- [(bug2.status, None, bug2.importance, False, None, None, 1)],
270+ [(bug2.status, None, bug2.importance, False, None, None, None, 1)],
271 calculate_bugsummary_rows(sp.distroseries))
272 self.assertContentEqual(
273 calculate_bugsummary_rows(sp.distroseries),