Merge lp:~stevenk/launchpad/branch-unsubscribe-revokes into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 15511
Proposed branch: lp:~stevenk/launchpad/branch-unsubscribe-revokes
Merge into: lp:launchpad
Diff against target: 49 lines (+21/-0)
2 files modified
lib/lp/code/model/branch.py (+7/-0)
lib/lp/code/model/tests/test_branchsubscription.py (+14/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/branch-unsubscribe-revokes
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+112272@code.launchpad.net

Commit message

Fix IBranch.unsubscribe() to remove AccessArtifactGrants, like it should have when subscribe() added them.

Description of the change

In https://code.launchpad.net/~stevenk/launchpad/branch-subscribe-aag/+merge/108881 I changed Branch.subscribe() to add an AccessArtifactGrant if required. Unfortunately, I neglected to change Branch.unsubscribe() to remove the AAG, hence this branch.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

I think the unsubscribe case needs a test.

review: Needs Information (code)
Revision history for this message
Curtis Hovey (sinzui) :
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/model/branch.py'
2--- lib/lp/code/model/branch.py 2012-06-18 01:04:30 +0000
3+++ lib/lp/code/model/branch.py 2012-06-27 22:34:23 +0000
4@@ -137,6 +137,10 @@
5 PRIVATE_INFORMATION_TYPES,
6 PUBLIC_INFORMATION_TYPES,
7 )
8+from lp.registry.interfaces.accesspolicy import (
9+ IAccessArtifactGrantSource,
10+ IAccessArtifactSource,
11+ )
12 from lp.registry.interfaces.person import (
13 validate_person,
14 validate_public_person,
15@@ -878,6 +882,9 @@
16 person.displayname))
17 store = Store.of(subscription)
18 store.remove(subscription)
19+ artifact = getUtility(IAccessArtifactSource).find([self])
20+ getUtility(IAccessArtifactGrantSource).revokeByArtifact(
21+ artifact, [person])
22 store.flush()
23
24 def getBranchRevision(self, sequence=None, revision=None,
25
26=== modified file 'lib/lp/code/model/tests/test_branchsubscription.py'
27--- lib/lp/code/model/tests/test_branchsubscription.py 2012-06-06 05:58:44 +0000
28+++ lib/lp/code/model/tests/test_branchsubscription.py 2012-06-27 22:34:23 +0000
29@@ -95,6 +95,20 @@
30 None, CodeReviewNotificationLevel.NOEMAIL, owner)
31 self.assertTrue(branch.visibleByUser(subscribee))
32
33+ def test_unsubscribe_gives_access(self):
34+ """Unsubscibing a user to a branch removes their access."""
35+ owner = self.factory.makePerson()
36+ branch = self.factory.makeBranch(
37+ information_type=InformationType.USERDATA, owner=owner)
38+ subscribee = self.factory.makePerson()
39+ with person_logged_in(owner):
40+ branch.subscribe(
41+ subscribee, BranchSubscriptionNotificationLevel.NOEMAIL,
42+ None, CodeReviewNotificationLevel.NOEMAIL, owner)
43+ self.assertTrue(branch.visibleByUser(subscribee))
44+ branch.unsubscribe(subscribee, owner)
45+ self.assertFalse(branch.visibleByUser(subscribee))
46+
47
48 class TestBranchSubscriptionCanBeUnsubscribedbyUser(TestCaseWithFactory):
49 """Tests for BranchSubscription.canBeUnsubscribedByUser."""