Merge lp:~wgrant/launchpad/more-branchnamespace into lp:launchpad

Proposed by William Grant
Status: Merged
Approved by: William Grant
Approved revision: no longer in the source branch.
Merged at revision: 15613
Proposed branch: lp:~wgrant/launchpad/more-branchnamespace
Merge into: lp:launchpad
Diff against target: 189 lines (+61/-40)
5 files modified
lib/lp/code/browser/branchlisting.py (+25/-6)
lib/lp/code/browser/tests/test_product.py (+13/-7)
lib/lp/code/interfaces/branchnamespace.py (+4/-6)
lib/lp/code/model/branchnamespace.py (+5/-8)
lib/lp/code/templates/product-branches.pt (+14/-13)
To merge this branch: bzr merge lp:~wgrant/launchpad/more-branchnamespace
Reviewer Review Type Date Requested Status
Ian Booth (community) Approve
Review via email: mp+114563@code.launchpad.net

Commit message

Dispose of BranchNamespace.areNewBranchesPrivate. It's replaced by getDefaultInformationType.

Description of the change

Dispose of BranchNamespace.areNewBranchesPrivate. It's replaced by getDefaultInformationType.

As a side-effect this now says "You can't create new branches" if you can't create new branches, rather than saying that branches will be public. The three states look like <http://people.canonical.com/~wgrant/launchpad/privacies.png>.

To post a comment you must log in.
Revision history for this message
Ian Booth (wallyworld) wrote :

Looks niiiice.

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/branchlisting.py'
2--- lib/lp/code/browser/branchlisting.py 2012-03-07 00:58:37 +0000
3+++ lib/lp/code/browser/branchlisting.py 2012-07-12 05:13:22 +0000
4@@ -99,6 +99,10 @@
5 ProductDownloadFileMixin,
6 SortSeriesMixin,
7 )
8+from lp.registry.enums import (
9+ InformationType,
10+ PRIVATE_INFORMATION_TYPES,
11+ )
12 from lp.registry.interfaces.person import (
13 IPerson,
14 IPersonSet,
15@@ -749,17 +753,32 @@
16 self.form_fields = form.Fields(*fields)
17 super(BranchListingView, self).setUpWidgets(context)
18
19- @property
20- def new_branches_are_private(self):
21- """Are new branches by the user private."""
22+ @cachedproperty
23+ def default_information_type(self):
24+ """The default information type for new branches."""
25 if self.user is None:
26- return False
27+ return None
28 target = IBranchTarget(self.context)
29 if target is None:
30 return False
31 namespace = target.getNamespace(self.user)
32- policy = IBranchNamespacePolicy(namespace)
33- return policy.areNewBranchesPrivate()
34+ return IBranchNamespacePolicy(namespace).getDefaultInformationType()
35+
36+ @property
37+ def default_information_type_title(self):
38+ """The title of the default information type for new branches."""
39+ information_type = self.default_information_type
40+ if information_type is None:
41+ return None
42+ if (information_type == InformationType.USERDATA and
43+ getFeatureFlag('disclosure.display_userdata_as_private.enabled')):
44+ return 'Private'
45+ return information_type.title
46+
47+ @property
48+ def default_information_type_is_private(self):
49+ """The title of the default information type for new branches."""
50+ return self.default_information_type in PRIVATE_INFORMATION_TYPES
51
52
53 class NoContextBranchListingView(BranchListingView):
54
55=== modified file 'lib/lp/code/browser/tests/test_product.py'
56--- lib/lp/code/browser/tests/test_product.py 2012-07-05 04:59:52 +0000
57+++ lib/lp/code/browser/tests/test_product.py 2012-07-12 05:13:22 +0000
58@@ -22,6 +22,7 @@
59 from lp.code.interfaces.revision import IRevisionSet
60 from lp.code.publisher import CodeLayer
61 from lp.registry.enums import InformationType
62+from lp.services.features.testing import FeatureFixture
63 from lp.services.webapp import canonical_url
64 from lp.testing import (
65 ANONYMOUS,
66@@ -360,11 +361,15 @@
67 product.development_focus.branch = branch
68 product.setBranchVisibilityTeamPolicy(
69 team, BranchVisibilityRule.PRIVATE)
70- view = create_initialized_view(
71- product, '+code-index', rootsite='code', principal=product.owner)
72- text = extract_text(find_tag_by_id(view.render(), 'privacy'))
73- expected = ("New branches you create for %(name)s are private "
74- "initially.*" % dict(name=product.displayname))
75+ with FeatureFixture(
76+ {'disclosure.display_userdata_as_private.enabled': 'true'}):
77+ view = create_initialized_view(
78+ product, '+code-index', rootsite='code',
79+ principal=product.owner)
80+ text = extract_text(find_tag_by_id(view.render(), 'privacy'))
81+ expected = (
82+ "New branches for %(name)s are Private.*"
83+ % dict(name=product.displayname))
84 self.assertTextMatchesExpressionIgnoreWhitespace(expected, text)
85
86 def test_is_public(self):
87@@ -374,8 +379,9 @@
88 product.development_focus.branch = branch
89 browser = self.getUserBrowser(canonical_url(product, rootsite='code'))
90 text = extract_text(find_tag_by_id(browser.contents, 'privacy'))
91- expected = ("New branches you create for %(name)s are public "
92- "initially.*" % dict(name=product.displayname))
93+ expected = (
94+ "New branches for %(name)s are Public.*"
95+ % dict(name=product.displayname))
96 self.assertTextMatchesExpressionIgnoreWhitespace(expected, text)
97
98
99
100=== modified file 'lib/lp/code/interfaces/branchnamespace.py'
101--- lib/lp/code/interfaces/branchnamespace.py 2012-07-11 22:16:47 +0000
102+++ lib/lp/code/interfaces/branchnamespace.py 2012-07-12 05:13:22 +0000
103@@ -116,12 +116,10 @@
104 :return: A sequence of `InformationType`s.
105 """
106
107- def areNewBranchesPrivate():
108- """Are new branches in this namespace private?
109-
110- No check is made about whether or not a user can create branches.
111-
112- :return: A Boolean value.
113+ def getDefaultInformationType():
114+ """Get the default information type for branches in this namespace.
115+
116+ :return: An `InformationType`.
117 """
118
119 def validateRegistrant(registrant):
120
121=== modified file 'lib/lp/code/model/branchnamespace.py'
122--- lib/lp/code/model/branchnamespace.py 2012-07-11 22:16:47 +0000
123+++ lib/lp/code/model/branchnamespace.py 2012-07-12 05:13:22 +0000
124@@ -110,12 +110,7 @@
125 distroseries = sourcepackage.distroseries
126 sourcepackagename = sourcepackage.sourcepackagename
127
128- # If branches can be private, make them private initially.
129- private = self.areNewBranchesPrivate()
130- if private:
131- information_type = InformationType.USERDATA
132- else:
133- information_type = InformationType.PUBLIC
134+ information_type = self.getDefaultInformationType()
135
136 branch = Branch(
137 registrant=registrant, name=name, owner=self.owner,
138@@ -268,9 +263,11 @@
139 """See `IBranchNamespace`."""
140 raise NotImplementedError
141
142- def areNewBranchesPrivate(self):
143+ def getDefaultInformationType(self):
144 """See `IBranchNamespace`."""
145- return InformationType.USERDATA in self.getAllowedInformationTypes()
146+ if InformationType.USERDATA in self.getAllowedInformationTypes():
147+ return InformationType.USERDATA
148+ return InformationType.PUBLIC
149
150 def getPrivacySubscriber(self):
151 """See `IBranchNamespace`."""
152
153=== modified file 'lib/lp/code/templates/product-branches.pt'
154--- lib/lp/code/templates/product-branches.pt 2012-03-10 13:48:37 +0000
155+++ lib/lp/code/templates/product-branches.pt 2012-07-12 05:13:22 +0000
156@@ -19,19 +19,20 @@
157 <div id="branch-portlet"
158 tal:condition="not: context/codehosting_usage/enumvalue:UNKNOWN">
159 <div id="privacy"
160- tal:define="are_private view/new_branches_are_private"
161- tal:attributes="class python: are_private and 'first portlet private' or 'first portlet public'">
162-
163- <p tal:condition="not:view/new_branches_are_private" id="privacy-text">
164- New branches you create for <tal:name replace="context/displayname"/>
165- are <strong>public</strong> initially.
166- </p>
167-
168- <p tal:condition="view/new_branches_are_private" id="privacy-text">
169- New branches you create for <tal:name replace="context/displayname"/>
170- are <strong>private</strong> initially.
171- </p>
172-
173+ tal:define="private_class python: 'private' if view.default_information_type_is_private else 'public'"
174+ tal:attributes="class string:first portlet ${private_class}">
175+ <span tal:condition="not: view/default_information_type"
176+ id="privacy-text">
177+ You can't create new branches for
178+ <tal:name replace="context/displayname"/>.
179+ </span>
180+
181+ <span tal:condition="view/default_information_type"
182+ tal:attributes="class string:sprite ${private_class}"
183+ id="privacy-text">
184+ New branches for <tal:name replace="context/displayname"/> are
185+ <strong tal:content="view/default_information_type_title" />.
186+ </span>
187 </div>
188
189 <div id="involvement" class="portlet"