Merge lp:~thumper/launchpad/branch-push-permission into lp:launchpad

Proposed by Tim Penhey on 2010-02-22
Status: Merged
Approved by: Michael Hudson-Doyle on 2010-02-22
Approved revision: not available
Merged at revision: 10360
Proposed branch: lp:~thumper/launchpad/branch-push-permission
Merge into: lp:launchpad
Diff against target: 67 lines (+34/-3)
2 files modified
lib/lp/code/browser/branch.py (+5/-3)
lib/lp/code/browser/tests/test_branch.py (+29/-0)
To merge this branch: bzr merge lp:~thumper/launchpad/branch-push-permission
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle 2010-02-22 Approve on 2010-02-22
Review via email: mp+19834@code.launchpad.net

Commit Message

Use launchpad.Edit to determine on the branch-index.pt template whether the user can upload to the branch.

To post a comment you must log in.
Tim Penhey (thumper) wrote :

Change the code that controls the "bzr push" display on the branch page to use the launchpad.Edit permission rather than checking ownership of the branch.

Michael Hudson-Doyle (mwhudson) wrote :

Maybe a test for whether an admin can upload would make sense?

Otherwise, nice.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/browser/branch.py'
2--- lib/lp/code/browser/branch.py 2010-02-01 03:49:23 +0000
3+++ lib/lp/code/browser/branch.py 2010-02-22 01:15:27 +0000
4@@ -425,11 +425,13 @@
5 linkdata = BranchContextMenu(self.context).edit()
6 return '%s/%s' % (canonical_url(self.context), linkdata.target)
7
8+ @property
9 def user_can_upload(self):
10 """Whether the user can upload to this branch."""
11- return (self.user is not None and
12- self.user.inTeam(self.context.owner) and
13- self.context.branch_type == BranchType.HOSTED)
14+ branch = self.context
15+ if branch.branch_type != BranchType.HOSTED:
16+ return False
17+ return check_permission('launchpad.Edit', branch)
18
19 def user_can_download(self):
20 """Whether the user can download this branch."""
21
22=== modified file 'lib/lp/code/browser/tests/test_branch.py'
23--- lib/lp/code/browser/tests/test_branch.py 2010-01-07 11:54:06 +0000
24+++ lib/lp/code/browser/tests/test_branch.py 2010-02-22 01:15:27 +0000
25@@ -33,6 +33,7 @@
26 from lp.code.interfaces.branchlookup import IBranchLookup
27 from lp.testing import (
28 login, login_person, logout, ANONYMOUS, TestCaseWithFactory)
29+from lp.testing.views import create_initialized_view
30 from canonical.launchpad.webapp.servers import LaunchpadTestRequest
31 from canonical.testing import (
32 DatabaseFunctionalLayer, LaunchpadFunctionalLayer)
33@@ -232,6 +233,34 @@
34 view.initialize()
35 self.assertEqual(list(view.translations_sources()), [trunk])
36
37+ def test_user_can_upload(self):
38+ # A user can upload if they have edit permissions.
39+ branch = self.factory.makeAnyBranch()
40+ view = create_initialized_view(branch, '+index')
41+ login_person(branch.owner)
42+ self.assertTrue(view.user_can_upload)
43+
44+ def test_user_can_upload_admins_can(self):
45+ # Admins can upload to any hosted branch.
46+ branch = self.factory.makeAnyBranch()
47+ view = create_initialized_view(branch, '+index')
48+ login('admin@canonical.com')
49+ self.assertTrue(view.user_can_upload)
50+
51+ def test_user_can_upload_non_owner(self):
52+ # Someone not associated with the branch cannot upload
53+ branch = self.factory.makeAnyBranch()
54+ view = create_initialized_view(branch, '+index')
55+ login_person(self.factory.makePerson())
56+ self.assertFalse(view.user_can_upload)
57+
58+ def test_user_can_upload_mirrored(self):
59+ # Even the owner of a mirrored branch can't upload.
60+ branch = self.factory.makeAnyBranch(branch_type=BranchType.MIRRORED)
61+ view = create_initialized_view(branch, '+index')
62+ login_person(branch.owner)
63+ self.assertFalse(view.user_can_upload)
64+
65
66 class TestBranchAddView(TestCaseWithFactory):
67 """Test the BranchAddView view."""