Merge lp:~adeuring/launchpad/product-lp-limitedview-branch-view into lp:launchpad

Proposed by Abel Deuring
Status: Merged
Approved by: Abel Deuring
Approved revision: no longer in the source branch.
Merged at revision: 16273
Proposed branch: lp:~adeuring/launchpad/product-lp-limitedview-branch-view
Merge into: lp:launchpad
Diff against target: 148 lines (+56/-14)
4 files modified
lib/lp/blueprints/browser/tests/test_specification.py (+20/-0)
lib/lp/code/browser/tests/test_branch.py (+22/-0)
lib/lp/registry/interfaces/product.py (+12/-12)
lib/lp/registry/tests/test_product.py (+2/-2)
To merge this branch: bzr merge lp:~adeuring/launchpad/product-lp-limitedview-branch-view
Reviewer Review Type Date Requested Status
Richard Harding (community) Approve
Review via email: mp+134315@code.launchpad.net

Commit message

tests to ensure that users with an artifacts grant for branches and specifications related to aprivate projects can access the LP pages for these branches/specs. IHasIcon moved from IProductView to IProductLimitedView

Description of the change

This branch adds tests to show that users having only an artifact
grant for blueprint or a branch related to a private product can
access the related LP pages.

The test for the branch failed at first because access to IProduct.icon
is required, so I made IHasIcon a base class of IProductLimitedView
instead of IProductView.

tests:

./bin/test blueprints -vvt test_view_for_user_with_artifact_grant
./bin/test code -vvt test_view_for_user_with_artifact_grant

no lint

To post a comment you must log in.
Revision history for this message
Richard Harding (rharding) wrote :

#64 typo: Unaut[h]orized

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/blueprints/browser/tests/test_specification.py'
2--- lib/lp/blueprints/browser/tests/test_specification.py 2012-11-13 15:20:28 +0000
3+++ lib/lp/blueprints/browser/tests/test_specification.py 2012-11-14 15:47:23 +0000
4@@ -184,6 +184,26 @@
5 extract_text(html), DocTestMatches(
6 "... Registered by Some Person ... ago ..."))
7
8+ def test_view_for_user_with_artifact_grant(self):
9+ # Users with an artifact grant for a specification related to a
10+ # private product can view the specification page.
11+ owner = self.factory.makePerson()
12+ user = self.factory.makePerson()
13+ product = self.factory.makeProduct(
14+ owner=owner,
15+ information_type=InformationType.PROPRIETARY)
16+ with person_logged_in(owner):
17+ spec = self.factory.makeSpecification(
18+ product=product, owner=owner,
19+ information_type=InformationType.PROPRIETARY)
20+ getUtility(IService, 'sharing').ensureAccessGrants(
21+ [user], owner, specifications=[spec])
22+ with person_logged_in(user):
23+ view = create_initialized_view(
24+ spec, name='+index', principal=user, rootsite='blueprints')
25+ # Calling render() does not raise any exceptions.
26+ self.assertIn(spec.name, view.render())
27+
28
29 def set_blueprint_information_type(test_case, enabled):
30 value = 'true' if enabled else ''
31
32=== modified file 'lib/lp/code/browser/tests/test_branch.py'
33--- lib/lp/code/browser/tests/test_branch.py 2012-10-31 00:54:33 +0000
34+++ lib/lp/code/browser/tests/test_branch.py 2012-11-14 15:47:23 +0000
35@@ -17,6 +17,7 @@
36 from lp.app.enums import InformationType
37 from lp.app.interfaces.headings import IRootContext
38 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
39+from lp.app.interfaces.services import IService
40 from lp.bugs.interfaces.bugtask import (
41 BugTaskStatus,
42 UNRESOLVED_BUGTASK_STATUSES,
43@@ -519,6 +520,27 @@
44 self.assertEqual(linked_bug_urls[0], links[3]['href'])
45 self.assertEqual(linked_bug_urls[1], links[4]['href'])
46
47+ def test_view_for_user_with_artifact_grant(self):
48+ # Users with an artifact grant for a branch related to a private
49+ # product can view the main branch page.
50+ owner = self.factory.makePerson()
51+ user = self.factory.makePerson()
52+ product = self.factory.makeProduct(
53+ owner=owner,
54+ information_type=InformationType.PROPRIETARY)
55+ with person_logged_in(owner):
56+ product_name = product.name
57+ branch = self.factory.makeBranch(
58+ product=product, owner=owner,
59+ information_type=InformationType.PROPRIETARY)
60+ getUtility(IService, 'sharing').ensureAccessGrants(
61+ [user], owner, branches=[branch])
62+ with person_logged_in(user):
63+ url = canonical_url(branch)
64+ # The main check: No Unauthorized error should be raised.
65+ browser = self.getUserBrowser(url, user=user)
66+ self.assertIn(product_name, browser.contents)
67+
68
69 class TestBranchViewPrivateArtifacts(BrowserTestCase):
70 """ Tests that branches with private team artifacts can be viewed.
71
72=== modified file 'lib/lp/registry/interfaces/product.py'
73--- lib/lp/registry/interfaces/product.py 2012-11-12 23:03:24 +0000
74+++ lib/lp/registry/interfaces/product.py 2012-11-14 15:47:23 +0000
75@@ -428,7 +428,7 @@
76 """True if the given user has access to this product."""
77
78
79-class IProductLimitedView(IHasLogo, IHasOwner, ILaunchpadUsage):
80+class IProductLimitedView(IHasIcon, IHasLogo, IHasOwner, ILaunchpadUsage):
81 """Attributes that must be visible for person with artifact grants
82 on bugs, branches or specifications for the product.
83 """
84@@ -440,6 +440,16 @@
85 paragraph.""")),
86 exported_as='display_name')
87
88+ icon = exported(
89+ IconImageUpload(
90+ title=_("Icon"), required=False,
91+ default_image_resource='/@@/product',
92+ description=_(
93+ "A small image of exactly 14x14 pixels and at most 5kb in "
94+ "size, that can be used to identify this project. The icon "
95+ "will be displayed next to the project name everywhere in "
96+ "Launchpad that we refer to the project and link to it.")))
97+
98 logo = exported(
99 LogoImageUpload(
100 title=_("Logo"), required=False,
101@@ -491,7 +501,7 @@
102
103 class IProductView(
104 ICanGetMilestonesDirectly, IHasAppointedDriver, IHasBranches,
105- IHasDrivers, IHasExternalBugTracker, IHasIcon,
106+ IHasDrivers, IHasExternalBugTracker,
107 IHasMergeProposals, IHasMilestones, IHasExpirableBugs,
108 IHasMugshot, IHasSprints, IHasTranslationImports,
109 ITranslationPolicy, IKarmaContext, IMakesAnnouncements,
110@@ -613,16 +623,6 @@
111 "be displayed for all the world to see. It is NOT a wiki "
112 "so you cannot undo changes."))
113
114- icon = exported(
115- IconImageUpload(
116- title=_("Icon"), required=False,
117- default_image_resource='/@@/product',
118- description=_(
119- "A small image of exactly 14x14 pixels and at most 5kb in "
120- "size, that can be used to identify this project. The icon "
121- "will be displayed next to the project name everywhere in "
122- "Launchpad that we refer to the project and link to it.")))
123-
124 mugshot = exported(
125 MugshotImageUpload(
126 title=_("Brand"), required=False,
127
128=== modified file 'lib/lp/registry/tests/test_product.py'
129--- lib/lp/registry/tests/test_product.py 2012-11-12 23:03:24 +0000
130+++ lib/lp/registry/tests/test_product.py 2012-11-14 15:47:23 +0000
131@@ -553,7 +553,7 @@
132 'userCanView',)),
133 'launchpad.LimitedView': set((
134 'bugtargetdisplayname', 'displayname', 'enable_bug_expiration',
135- 'logo', 'name', 'official_answers', 'official_anything',
136+ 'icon', 'logo', 'name', 'official_answers', 'official_anything',
137 'official_blueprints', 'official_codehosting', 'official_malone',
138 'owner', 'parent_subscription_target', 'project', 'title', )),
139 'launchpad.View': set((
140@@ -595,7 +595,7 @@
141 'getVersionSortedSeries',
142 'has_current_commercial_subscription',
143 'has_custom_language_codes', 'has_milestones', 'homepage_content',
144- 'homepageurl', 'icon', 'invitesTranslationEdits',
145+ 'homepageurl', 'invitesTranslationEdits',
146 'invitesTranslationSuggestions',
147 'license_info', 'license_status', 'licenses', 'milestones',
148 'mugshot', 'name_with_project', 'newCodeImport',