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
=== modified file 'lib/lp/code/model/branch.py'
--- lib/lp/code/model/branch.py 2012-06-18 01:04:30 +0000
+++ lib/lp/code/model/branch.py 2012-06-27 22:34:23 +0000
@@ -137,6 +137,10 @@
137 PRIVATE_INFORMATION_TYPES,137 PRIVATE_INFORMATION_TYPES,
138 PUBLIC_INFORMATION_TYPES,138 PUBLIC_INFORMATION_TYPES,
139 )139 )
140from lp.registry.interfaces.accesspolicy import (
141 IAccessArtifactGrantSource,
142 IAccessArtifactSource,
143 )
140from lp.registry.interfaces.person import (144from lp.registry.interfaces.person import (
141 validate_person,145 validate_person,
142 validate_public_person,146 validate_public_person,
@@ -878,6 +882,9 @@
878 person.displayname))882 person.displayname))
879 store = Store.of(subscription)883 store = Store.of(subscription)
880 store.remove(subscription)884 store.remove(subscription)
885 artifact = getUtility(IAccessArtifactSource).find([self])
886 getUtility(IAccessArtifactGrantSource).revokeByArtifact(
887 artifact, [person])
881 store.flush()888 store.flush()
882889
883 def getBranchRevision(self, sequence=None, revision=None,890 def getBranchRevision(self, sequence=None, revision=None,
884891
=== modified file 'lib/lp/code/model/tests/test_branchsubscription.py'
--- lib/lp/code/model/tests/test_branchsubscription.py 2012-06-06 05:58:44 +0000
+++ lib/lp/code/model/tests/test_branchsubscription.py 2012-06-27 22:34:23 +0000
@@ -95,6 +95,20 @@
95 None, CodeReviewNotificationLevel.NOEMAIL, owner)95 None, CodeReviewNotificationLevel.NOEMAIL, owner)
96 self.assertTrue(branch.visibleByUser(subscribee))96 self.assertTrue(branch.visibleByUser(subscribee))
9797
98 def test_unsubscribe_gives_access(self):
99 """Unsubscibing a user to a branch removes their access."""
100 owner = self.factory.makePerson()
101 branch = self.factory.makeBranch(
102 information_type=InformationType.USERDATA, owner=owner)
103 subscribee = self.factory.makePerson()
104 with person_logged_in(owner):
105 branch.subscribe(
106 subscribee, BranchSubscriptionNotificationLevel.NOEMAIL,
107 None, CodeReviewNotificationLevel.NOEMAIL, owner)
108 self.assertTrue(branch.visibleByUser(subscribee))
109 branch.unsubscribe(subscribee, owner)
110 self.assertFalse(branch.visibleByUser(subscribee))
111
98112
99class TestBranchSubscriptionCanBeUnsubscribedbyUser(TestCaseWithFactory):113class TestBranchSubscriptionCanBeUnsubscribedbyUser(TestCaseWithFactory):
100 """Tests for BranchSubscription.canBeUnsubscribedByUser."""114 """Tests for BranchSubscription.canBeUnsubscribedByUser."""