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
1=== modified file 'lib/lp/code/model/tests/test_branchsubscription.py'
2--- lib/lp/code/model/tests/test_branchsubscription.py 2010-10-26 15:47:24 +0000
3+++ lib/lp/code/model/tests/test_branchsubscription.py 2011-07-13 01:01:41 +0000
4@@ -5,8 +5,6 @@
5
6 __metaclass__ = type
7
8-import unittest
9-
10 from canonical.testing.layers import DatabaseFunctionalLayer
11 from lp.app.errors import UserCannotUnsubscribePerson
12 from lp.code.enums import (
13@@ -119,6 +117,30 @@
14 person=team, subscribed_by=subscribed_by)
15 self.assertTrue(subscription.canBeUnsubscribedByUser(subscribed_by))
16
17-
18-def test_suite():
19- return unittest.TestLoader().loadTestsFromName(__name__)
20+ def test_branch_person_owner_can_unsubscribe(self):
21+ """Branch owner can unsubscribe someone from a branch."""
22+ branch_owner = self.factory.makePerson()
23+ branch = self.factory.makeBranch(owner=branch_owner)
24+ subscribed_by = self.factory.makePerson()
25+ subscriber = self.factory.makePerson()
26+ subscription = self.factory.makeBranchSubscription(
27+ branch=branch, person=subscriber, subscribed_by=subscribed_by)
28+ self.assertTrue(subscription.canBeUnsubscribedByUser(branch_owner))
29+
30+ def test_branch_team_owner_can_unsubscribe(self):
31+ """Branch team owner can unsubscribe someone from a branch.
32+
33+ If the owner of a branch is a team, then the team members can
34+ unsubscribe someone.
35+ """
36+ team_owner = self.factory.makePerson()
37+ team_member = self.factory.makePerson()
38+ branch_owner = self.factory.makeTeam(
39+ owner=team_owner, members=[team_member])
40+ branch = self.factory.makeBranch(owner=branch_owner)
41+ subscribed_by = self.factory.makePerson()
42+ subscriber = self.factory.makePerson()
43+ subscription = self.factory.makeBranchSubscription(
44+ branch=branch, person=subscriber, subscribed_by=subscribed_by)
45+ self.assertTrue(subscription.canBeUnsubscribedByUser(team_owner))
46+ self.assertTrue(subscription.canBeUnsubscribedByUser(team_member))
47
48=== modified file 'lib/lp/code/security.py'
49--- lib/lp/code/security.py 2011-04-27 16:14:32 +0000
50+++ lib/lp/code/security.py 2011-07-13 01:01:41 +0000
51@@ -22,8 +22,12 @@
52
53 Any team member can edit a branch subscription for their team.
54 Launchpad Admins can also edit any branch subscription.
55+ The owner of the subscribed branch can edit the subscription. If the
56+ branch owner is a team, then members of the team can edit the
57+ subscription.
58 """
59- return (user.inTeam(self.obj.person) or
60+ return (user.inTeam(self.obj.branch.owner) or
61+ user.inTeam(self.obj.person) or
62 user.inTeam(self.obj.subscribed_by) or
63 user.in_admin or
64 user.in_bazaar_experts)
65@@ -31,5 +35,3 @@
66
67 class BranchSubscriptionView(BranchSubscriptionEdit):
68 permission = 'launchpad.View'
69-
70-
71
72=== modified file 'lib/lp/testing/factory.py'
73--- lib/lp/testing/factory.py 2011-07-07 15:47:36 +0000
74+++ lib/lp/testing/factory.py 2011-07-13 01:01:41 +0000
75@@ -1486,11 +1486,7 @@
76
77 def makeBranchSubscription(self, branch=None, person=None,
78 subscribed_by=None):
79- """Create a BranchSubscription.
80-
81- :param branch_title: The title to use for the created Branch
82- :param person_displayname: The displayname for the created Person
83- """
84+ """Create a BranchSubscription."""
85 if branch is None:
86 branch = self.makeBranch()
87 if person is None: