Merge lp:~stevenk/launchpad/sharingservice-rasj-miss into lp:launchpad

Proposed by Steve Kowalik on 2012-07-20
Status: Merged
Approved by: Steve Kowalik on 2012-07-20
Approved revision: no longer in the source branch.
Merged at revision: 15660
Proposed branch: lp:~stevenk/launchpad/sharingservice-rasj-miss
Merge into: lp:launchpad
Diff against target: 172 lines (+53/-39)
2 files modified
lib/lp/registry/services/sharingservice.py (+2/-5)
lib/lp/registry/services/tests/test_sharingservice.py (+51/-34)
To merge this branch: bzr merge lp:~stevenk/launchpad/sharingservice-rasj-miss
Reviewer Review Type Date Requested Status
Ian Booth (community) 2012-07-20 Approve on 2012-07-20
Review via email: mp+115874@code.launchpad.net

Commit Message

Fix the sharing service to create a RemoveArtifactSubscriptionsJob for branches as well as bugs, as well as writing some extra branch tests.

Description of the Change

Fix the sharing services to create a job for branches as well as bugs. Also fix a little bit of lint, remove a few XXXes, and write some branch tests.

To post a comment you must log in.
Ian Booth (wallyworld) wrote :

Looks good, thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/services/sharingservice.py'
2--- lib/lp/registry/services/sharingservice.py 2012-07-17 21:58:06 +0000
3+++ lib/lp/registry/services/sharingservice.py 2012-07-20 02:48:18 +0000
4@@ -463,11 +463,8 @@
5
6 # Create a job to remove subscriptions for artifacts the sharee can no
7 # longer see.
8- if bugs:
9- getUtility(IRemoveArtifactSubscriptionsJobSource).create(
10- user, bugs, grantee=sharee, pillar=pillar)
11- # XXX 2012-06-13 wallyworld bug=1012448
12- # Remove branch subscriptions when information type fully implemented.
13+ getUtility(IRemoveArtifactSubscriptionsJobSource).create(
14+ user, artifacts, grantee=sharee, pillar=pillar)
15
16 def ensureAccessGrants(self, sharees, user, branches=None, bugs=None,
17 ignore_permissions=False):
18
19=== modified file 'lib/lp/registry/services/tests/test_sharingservice.py'
20--- lib/lp/registry/services/tests/test_sharingservice.py 2012-07-17 21:58:06 +0000
21+++ lib/lp/registry/services/tests/test_sharingservice.py 2012-07-20 02:48:18 +0000
22@@ -15,7 +15,6 @@
23 from lp.app.interfaces.services import IService
24 from lp.bugs.interfaces.bug import IBug
25 from lp.code.enums import (
26- BranchSubscriptionDiffSize,
27 BranchSubscriptionNotificationLevel,
28 CodeReviewNotificationLevel,
29 )
30@@ -816,9 +815,10 @@
31 self.assertEqual(0, permission_info.count())
32
33 # Check that the grantee's subscriptions have been removed.
34- # Branches will be done once they have the information_type attribute.
35 for bug in bugs or []:
36 self.assertNotIn(grantee, bug.getDirectSubscribers())
37+ for branch in branches or []:
38+ self.assertNotIn(grantee, branch.subscribers)
39
40 # Someone else still has access to the bugs and branches.
41 grants = accessartifact_grant_source.findByArtifact(
42@@ -840,6 +840,15 @@
43 information_type=InformationType.USERDATA)
44 self._assert_revokeAccessGrants(distro, [bug], None)
45
46+ def test_revokeAccessGrantsBranches(self):
47+ owner = self.factory.makePerson()
48+ product = self.factory.makeProduct(owner=owner)
49+ login_person(owner)
50+ branch = self.factory.makeBranch(
51+ product=product, owner=owner,
52+ information_type=InformationType.USERDATA)
53+ self._assert_revokeAccessGrants(product, None, [branch])
54+
55 def _assert_revokeTeamAccessGrants(self, pillar, bugs, branches):
56 artifacts = []
57 if bugs:
58@@ -866,9 +875,9 @@
59 getUtility(IAccessArtifactGrantSource).revokeByArtifact(
60 accessartifact_source.find([bug]), [person_grantee])
61 for branch in branches or []:
62- branch.subscribe(person,
63- BranchSubscriptionNotificationLevel.NOEMAIL, None,
64- CodeReviewNotificationLevel.NOEMAIL, pillar.owner)
65+ branch.subscribe(
66+ person, BranchSubscriptionNotificationLevel.NOEMAIL,
67+ None, CodeReviewNotificationLevel.NOEMAIL, pillar.owner)
68
69 # Check that grantees have expected access grants and subscriptions.
70 for person in [team_grantee, person_grantee]:
71@@ -913,6 +922,15 @@
72 information_type=InformationType.USERDATA)
73 self._assert_revokeTeamAccessGrants(distro, [bug], None)
74
75+ def test_revokeTeamAccessGrantsBranches(self):
76+ # Users with launchpad.Edit can delete all access for a sharee.
77+ owner = self.factory.makePerson()
78+ product = self.factory.makeProduct(owner=owner)
79+ login_person(owner)
80+ branch = self.factory.makeBranch(
81+ owner=owner, information_type=InformationType.USERDATA)
82+ self._assert_revokeTeamAccessGrants(product, None, [branch])
83+
84 def _assert_revokeAccessGrantsUnauthorized(self):
85 # revokeAccessGrants raises an Unauthorized exception if the user
86 # is not permitted to do so.
87@@ -1094,17 +1112,6 @@
88 grant_access(bug, i == 9)
89 for i, branch in enumerate(branches):
90 grant_access(branch, i == 9)
91- # XXX bug=1001042 wallyworld 2012-05-18
92- # for now we need to subscribe users to the branch in order
93- # for the underlying BranchCollection to allow access. This will
94- # no longer be the case when BranchCollection supports the new
95- # access policy framework.
96- if i < 9:
97- branch.subscribe(
98- user, BranchSubscriptionNotificationLevel.NOEMAIL,
99- BranchSubscriptionDiffSize.NODIFF,
100- CodeReviewNotificationLevel.NOEMAIL,
101- owner)
102
103 # Check the results.
104 shared_bugtasks, shared_branches = self.service.getSharedArtifacts(
105@@ -1112,12 +1119,28 @@
106 self.assertContentEqual(bug_tasks[:9], shared_bugtasks)
107 self.assertContentEqual(branches[:9], shared_branches)
108
109- def test_getPeopleWithoutAccess_bugs(self):
110- # Test the getPeopleWithoutAccess method.
111- owner = self.factory.makePerson()
112- product = self.factory.makeProduct(owner=owner)
113- login_person(owner)
114-
115+ def test_getPeopleWithAccessBugs(self):
116+ # Test the getPeopleWithoutAccess method with bugs.
117+ owner = self.factory.makePerson()
118+ product = self.factory.makeProduct(owner=owner)
119+ bug = self.factory.makeBug(
120+ product=product, owner=owner,
121+ information_type=InformationType.USERDATA)
122+ login_person(owner)
123+ self._assert_getPeopleWithoutAccess(product, bug)
124+
125+ def test_getPeopleWithAccessBranches(self):
126+ # Test the getPeopleWithoutAccess method with branches.
127+ owner = self.factory.makePerson()
128+ product = self.factory.makeProduct(owner=owner)
129+ branch = self.factory.makeBranch(
130+ product=product, owner=owner,
131+ information_type=InformationType.USERDATA)
132+ login_person(owner)
133+ self._assert_getPeopleWithoutAccess(product, branch)
134+
135+ def _assert_getPeopleWithoutAccess(self, product, artifact):
136+ access_artifact = self.factory.makeAccessArtifact(concrete=artifact)
137 # Make some people to check. people[:5] will not have access.
138 people = []
139 # Make a team with access.
140@@ -1133,26 +1156,20 @@
141 people.append(team_with_access)
142 people.append(member_with_access)
143
144- # Make the bug to use.
145- bug = self.factory.makeBug(
146- product=product, owner=owner,
147- information_type=InformationType.USERDATA)
148- access_artifact = self.factory.makeAccessArtifact(concrete=bug)
149-
150- # Grant access to some of the people.
151- # Some access policy grants.
152+ # Create some access policy grants.
153 [policy] = getUtility(IAccessPolicySource).find(
154 [(product, InformationType.USERDATA)])
155 for person in people[5:7]:
156 self.factory.makeAccessPolicyGrant(
157- policy=policy, grantee=person, grantor=owner)
158- # Some access artifact grants.
159+ policy=policy, grantee=person, grantor=product.owner)
160+ # And some access artifact grants.
161 for person in people[7:]:
162 self.factory.makeAccessArtifactGrant(
163- artifact=access_artifact, grantee=person, grantor=owner)
164+ artifact=access_artifact, grantee=person,
165+ grantor=product.owner)
166
167 # Check the results.
168- without_access = self.service.getPeopleWithoutAccess(bug, people)
169+ without_access = self.service.getPeopleWithoutAccess(artifact, people)
170 self.assertContentEqual(people[:5], without_access)
171
172 def _make_Artifacts(self):