Merge lp:~blr/launchpad/bug-1474592-check-branch-accessibility into lp:launchpad

Proposed by Kit Randel
Status: Merged
Merged at revision: 17631
Proposed branch: lp:~blr/launchpad/bug-1474592-check-branch-accessibility
Merge into: lp:launchpad
Diff against target: 125 lines (+54/-17)
4 files modified
lib/lp/registry/browser/product.py (+12/-14)
lib/lp/registry/browser/productseries.py (+2/-1)
lib/lp/registry/browser/tests/test_product.py (+19/-1)
lib/lp/registry/browser/tests/test_productseries_views.py (+21/-1)
To merge this branch: bzr merge lp:~blr/launchpad/bug-1474592-check-branch-accessibility
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+264787@code.launchpad.net

Commit message

Ensure logged in user has launchpad.View permissions on branch/repo before rendering golang-import meta.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)
Revision history for this message
Kit Randel (blr) wrote :

Inline comment/self review.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/browser/product.py'
2--- lib/lp/registry/browser/product.py 2015-07-09 20:06:17 +0000
3+++ lib/lp/registry/browser/product.py 2015-07-15 05:08:58 +0000
4@@ -1030,24 +1030,22 @@
5 if self.context.vcs == VCSType.GIT:
6 repo = getUtility(IGitRepositorySet).getDefaultRepository(
7 self.context)
8- if repo:
9+ if check_permission('launchpad.View', repo):
10 return "{hostname}/{product} git {git_https_url}".format(
11 hostname=config.vhost.mainsite.hostname,
12 product=self.context.name,
13 git_https_url=repo.git_https_url)
14- else:
15- return None
16- elif (self.context.vcs == VCSType.BZR and
17- self.context.development_focus.branch):
18- return (
19- "{hostname}/{product} bzr "
20- "{root_url}{branch}").format(
21- hostname=config.vhost.mainsite.hostname,
22- root_url=allvhosts.configs['mainsite'].rooturl,
23- product=self.context.name,
24- branch=self.context.development_focus.branch.unique_name)
25- else:
26- return None
27+ elif self.context.vcs == VCSType.BZR:
28+ branch = self.context.development_focus.branch
29+ if check_permission('launchpad.View', branch):
30+ return (
31+ "{hostname}/{product} bzr "
32+ "{root_url}{branch}").format(
33+ hostname=config.vhost.mainsite.hostname,
34+ root_url=allvhosts.configs['mainsite'].rooturl,
35+ product=self.context.name,
36+ branch=branch.unique_name)
37+ return None
38
39 def browserLanguages(self):
40 return browser_languages(self.request)
41
42=== modified file 'lib/lp/registry/browser/productseries.py'
43--- lib/lp/registry/browser/productseries.py 2015-07-08 16:05:11 +0000
44+++ lib/lp/registry/browser/productseries.py 2015-07-15 05:08:58 +0000
45@@ -385,7 +385,8 @@
46 """Meta string for golang remote import path.
47 See: https://golang.org/cmd/go/#hdr-Remote_import_paths
48 """
49- if self.context.product.vcs == VCSType.BZR and self.context.branch:
50+ if (self.context.product.vcs == VCSType.BZR and
51+ self.user_branch_visible):
52 return (
53 "{hostname}/{product}/{series} bzr {root_url}{branch}").format(
54 hostname=config.vhost.mainsite.hostname,
55
56=== modified file 'lib/lp/registry/browser/tests/test_product.py'
57--- lib/lp/registry/browser/tests/test_product.py 2015-07-07 22:33:29 +0000
58+++ lib/lp/registry/browser/tests/test_product.py 2015-07-15 05:08:58 +0000
59@@ -24,7 +24,6 @@
60 from lp.app.browser.lazrjs import vocabulary_to_choice_edit_items
61 from lp.app.enums import (
62 InformationType,
63- PROPRIETARY_INFORMATION_TYPES,
64 ServiceUsage,
65 )
66 from lp.code.interfaces.gitrepository import IGitRepositorySet
67@@ -369,6 +368,25 @@
68 repo.target.vcs = VCSType.GIT
69 self.assertIsNone(view.golang_import_spec)
70
71+ def test_golang_meta_no_permissions(self):
72+ # ensure golang meta import path is not rendered if user does
73+ # not have launchpad.View permissions on branch.
74+ simple_user = self.factory.makePerson()
75+ owner = self.factory.makePerson()
76+ product = self.factory.makeProduct(owner=owner)
77+ branch = self.factory.makeBranch(
78+ owner=owner, information_type=InformationType.PRIVATESECURITY)
79+
80+ with person_logged_in(owner):
81+ product.development_focus.branch = branch
82+ product.vcs = VCSType.BZR
83+ view = create_initialized_view(product, '+index')
84+ self.assertIsNot(None, view.golang_import_spec)
85+
86+ with person_logged_in(simple_user):
87+ view = create_initialized_view(product, '+index')
88+ self.assertIsNone(view.golang_import_spec)
89+
90 def test_show_programming_languages_without_languages(self):
91 # show_programming_languages is false when there are no programming
92 # languages set.
93
94=== modified file 'lib/lp/registry/browser/tests/test_productseries_views.py'
95--- lib/lp/registry/browser/tests/test_productseries_views.py 2015-07-07 04:20:30 +0000
96+++ lib/lp/registry/browser/tests/test_productseries_views.py 2015-07-15 05:08:58 +0000
97@@ -70,7 +70,27 @@
98 with person_logged_in(series.product.owner):
99 series.product.vcs = VCSType.BZR
100
101- self.assertEqual(None, view.golang_import_spec)
102+ self.assertIsNone(view.golang_import_spec)
103+
104+ def test_golang_meta_no_permissions(self):
105+ # ensure golang meta import path is not rendered if user does
106+ # not have launchpad.View permissions on branch.
107+ owner = self.factory.makePerson()
108+ simple_user = self.factory.makePerson()
109+ product = self.factory.makeProduct(owner=owner)
110+ series = self.factory.makeProductSeries(owner=owner, product=product)
111+ branch = self.factory.makeBranch(
112+ owner=owner, information_type=InformationType.PRIVATESECURITY)
113+
114+ with person_logged_in(owner):
115+ series.branch = branch
116+ series.product.vcs = VCSType.BZR
117+ view = create_initialized_view(series, '+index')
118+ self.assertIsNot(None, view.golang_import_spec)
119+
120+ with person_logged_in(simple_user):
121+ view = create_initialized_view(series, '+index')
122+ self.assertIsNone(view.golang_import_spec)
123
124 def test_information_type_public(self):
125 # A ProductSeries view should include its information_type,