Merge lp:~wallyworld/launchpad/private-branch-unsubscribe-283167 into lp:launchpad

Proposed by Ian Booth
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 13409
Proposed branch: lp:~wallyworld/launchpad/private-branch-unsubscribe-283167
Merge into: lp:launchpad
Diff against target: 87 lines (+33/-13)
3 files modified
lib/lp/code/model/tests/test_branchsubscription.py (+27/-5)
lib/lp/code/security.py (+5/-3)
lib/lp/testing/factory.py (+1/-5)
To merge this branch: bzr merge lp:~wallyworld/launchpad/private-branch-unsubscribe-283167
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+67651@code.launchpad.net

Commit message

[r=gmb][bug=283167] Branch owners can edit any subscriptions to the branch.

Description of the change

== Implementation ==

The bug report says that owners of private branches should be able to edit subscriptions to the branch. This mp does that, but for public branches too.

If the branch owner is a team, then the team owner can edit the subscriptions, but an arbitrary member of the owning team cannot.

== Tests ==

Added new tests to TestBranchSubscriptionCanBeUnsubscribedbyUser:
  test_branch_person_owner_can_unsubscribe
  test_branch_team_owner_can_unsubscribe

== Lint ==
Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/code/security.py
  lib/lp/code/model/tests/test_branchsubscription.py
  lib/lp/testing/factory.py

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :

Hi Ian,

Only one very minor comment, otherwise r=me.

[1]

36 +

Minor nit, I know, but this blank line shouldn't be here.

review: Approve (code)
Revision history for this message
Robert Collins (lifeless) wrote :

The team ownership thing is inconsistent with every other use of teams; why do it that way?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/model/tests/test_branchsubscription.py'
--- lib/lp/code/model/tests/test_branchsubscription.py 2010-10-26 15:47:24 +0000
+++ lib/lp/code/model/tests/test_branchsubscription.py 2011-07-13 01:01:41 +0000
@@ -5,8 +5,6 @@
55
6__metaclass__ = type6__metaclass__ = type
77
8import unittest
9
10from canonical.testing.layers import DatabaseFunctionalLayer8from canonical.testing.layers import DatabaseFunctionalLayer
11from lp.app.errors import UserCannotUnsubscribePerson9from lp.app.errors import UserCannotUnsubscribePerson
12from lp.code.enums import (10from lp.code.enums import (
@@ -119,6 +117,30 @@
119 person=team, subscribed_by=subscribed_by)117 person=team, subscribed_by=subscribed_by)
120 self.assertTrue(subscription.canBeUnsubscribedByUser(subscribed_by))118 self.assertTrue(subscription.canBeUnsubscribedByUser(subscribed_by))
121119
122120 def test_branch_person_owner_can_unsubscribe(self):
123def test_suite():121 """Branch owner can unsubscribe someone from a branch."""
124 return unittest.TestLoader().loadTestsFromName(__name__)122 branch_owner = self.factory.makePerson()
123 branch = self.factory.makeBranch(owner=branch_owner)
124 subscribed_by = self.factory.makePerson()
125 subscriber = self.factory.makePerson()
126 subscription = self.factory.makeBranchSubscription(
127 branch=branch, person=subscriber, subscribed_by=subscribed_by)
128 self.assertTrue(subscription.canBeUnsubscribedByUser(branch_owner))
129
130 def test_branch_team_owner_can_unsubscribe(self):
131 """Branch team owner can unsubscribe someone from a branch.
132
133 If the owner of a branch is a team, then the team members can
134 unsubscribe someone.
135 """
136 team_owner = self.factory.makePerson()
137 team_member = self.factory.makePerson()
138 branch_owner = self.factory.makeTeam(
139 owner=team_owner, members=[team_member])
140 branch = self.factory.makeBranch(owner=branch_owner)
141 subscribed_by = self.factory.makePerson()
142 subscriber = self.factory.makePerson()
143 subscription = self.factory.makeBranchSubscription(
144 branch=branch, person=subscriber, subscribed_by=subscribed_by)
145 self.assertTrue(subscription.canBeUnsubscribedByUser(team_owner))
146 self.assertTrue(subscription.canBeUnsubscribedByUser(team_member))
125147
=== modified file 'lib/lp/code/security.py'
--- lib/lp/code/security.py 2011-04-27 16:14:32 +0000
+++ lib/lp/code/security.py 2011-07-13 01:01:41 +0000
@@ -22,8 +22,12 @@
2222
23 Any team member can edit a branch subscription for their team.23 Any team member can edit a branch subscription for their team.
24 Launchpad Admins can also edit any branch subscription.24 Launchpad Admins can also edit any branch subscription.
25 The owner of the subscribed branch can edit the subscription. If the
26 branch owner is a team, then members of the team can edit the
27 subscription.
25 """28 """
26 return (user.inTeam(self.obj.person) or29 return (user.inTeam(self.obj.branch.owner) or
30 user.inTeam(self.obj.person) or
27 user.inTeam(self.obj.subscribed_by) or31 user.inTeam(self.obj.subscribed_by) or
28 user.in_admin or32 user.in_admin or
29 user.in_bazaar_experts)33 user.in_bazaar_experts)
@@ -31,5 +35,3 @@
3135
32class BranchSubscriptionView(BranchSubscriptionEdit):36class BranchSubscriptionView(BranchSubscriptionEdit):
33 permission = 'launchpad.View'37 permission = 'launchpad.View'
34
35
3638
=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py 2011-07-07 15:47:36 +0000
+++ lib/lp/testing/factory.py 2011-07-13 01:01:41 +0000
@@ -1486,11 +1486,7 @@
14861486
1487 def makeBranchSubscription(self, branch=None, person=None,1487 def makeBranchSubscription(self, branch=None, person=None,
1488 subscribed_by=None):1488 subscribed_by=None):
1489 """Create a BranchSubscription.1489 """Create a BranchSubscription."""
1490
1491 :param branch_title: The title to use for the created Branch
1492 :param person_displayname: The displayname for the created Person
1493 """
1494 if branch is None:1490 if branch is None:
1495 branch = self.makeBranch()1491 branch = self.makeBranch()
1496 if person is None:1492 if person is None: