Merge lp:~wallyworld/launchpad/file-private-bug-1004702 into lp:launchpad

Proposed by Ian Booth
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 15324
Proposed branch: lp:~wallyworld/launchpad/file-private-bug-1004702
Merge into: lp:launchpad
Diff against target: 180 lines (+76/-12)
5 files modified
lib/lp/bugs/browser/bugtarget.py (+1/-1)
lib/lp/bugs/browser/tests/test_bugtarget_filebug.py (+38/-4)
lib/lp/registry/tests/test_information_type_vocabulary.py (+27/-3)
lib/lp/registry/vocabularies.py (+7/-3)
lib/lp/testing/factory.py (+3/-1)
To merge this branch: bzr merge lp:~wallyworld/launchpad/file-private-bug-1004702
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+107704@code.launchpad.net

Commit message

When filing bugs, do not show public info types for private bug projects.

Description of the change

== Implementation ==

Add a context to the InformationTypeVocabulary and restrict the vocab items if the context is for a private bugs project.

== Tests ==

Add tests for the vocab and also for the view.
bin/test -vvct test_bugtarget_filebug -t test_information_type_vocabulary

== Lint ==

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/bugs/browser/bugtarget.py
  lib/lp/bugs/browser/tests/test_bugtarget_filebug.py
  lib/lp/registry/vocabularies.py
  lib/lp/registry/tests/test_information_type_vocabulary.py
  lib/lp/testing/factory.py

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/browser/bugtarget.py'
2--- lib/lp/bugs/browser/bugtarget.py 2012-05-25 14:38:42 +0000
3+++ lib/lp/bugs/browser/bugtarget.py 2012-05-29 03:24:19 +0000
4@@ -288,7 +288,7 @@
5 if self.show_information_type_in_ui:
6 information_type_field = copy_field(
7 IBug['information_type'], readonly=False,
8- vocabulary=InformationTypeVocabulary())
9+ vocabulary=InformationTypeVocabulary(self.context))
10 self.form_fields = self.form_fields.omit('information_type')
11 self.form_fields += Fields(information_type_field)
12 else:
13
14=== modified file 'lib/lp/bugs/browser/tests/test_bugtarget_filebug.py'
15--- lib/lp/bugs/browser/tests/test_bugtarget_filebug.py 2012-05-27 23:04:28 +0000
16+++ lib/lp/bugs/browser/tests/test_bugtarget_filebug.py 2012-05-29 03:24:19 +0000
17@@ -25,6 +25,7 @@
18 from lp.registry.enums import (
19 InformationType,
20 PRIVATE_INFORMATION_TYPES,
21+ PUBLIC_INFORMATION_TYPES,
22 )
23 from lp.services.features.testing import FeatureFixture
24 from lp.services.webapp.servers import LaunchpadTestRequest
25@@ -392,9 +393,9 @@
26 bug = self.filebug_via_view(private_bugs=True)
27 self.assertEqual(InformationType.USERDATA, bug.information_type)
28
29- def test_filebug_information_type_vocabulary(self):
30+ def test_filebug_information_type_vocabulary_userdata_private(self):
31 # The vocabulary for information_type when filing a bug is created
32- # correctly.
33+ # correctly when 'User Data' is to be replaced by 'Private'.
34 feature_flags = {
35 'disclosure.show_information_type_in_ui.enabled': 'on',
36 'disclosure.proprietary_information_type.disabled': 'on',
37@@ -407,8 +408,41 @@
38 html = view.render()
39 soup = BeautifulSoup(html)
40 self.assertEqual(u'Private', soup.find('label', text="Private"))
41- self.assertIs(None, soup.find('label', text="User Data"))
42- self.assertIs(None, soup.find('label', text="Proprietary"))
43+ self.assertIsNone(soup.find('label', text="User Data"))
44+ self.assertIsNone(soup.find('label', text="Proprietary"))
45+
46+ def test_filebug_information_type_vocabulary(self):
47+ # The vocabulary for information_type when filing a bug is created
48+ # correctly.
49+ feature_flags = {
50+ 'disclosure.show_information_type_in_ui.enabled': 'on'}
51+ product = self.factory.makeProduct(official_malone=True)
52+ with FeatureFixture(feature_flags):
53+ with person_logged_in(product.owner):
54+ view = create_initialized_view(
55+ product, '+filebug', principal=product.owner)
56+ html = view.render()
57+ soup = BeautifulSoup(html)
58+ for info_type in InformationType:
59+ self.assertIsNotNone(soup.find('label', text=info_type.title))
60+
61+ def test_filebug_information_type_vocabulary_private_projects(self):
62+ # The vocabulary for information_type when filing a bug only has
63+ # private info types for private bug projects.
64+ feature_flags = {
65+ 'disclosure.show_information_type_in_ui.enabled': 'on'}
66+ product = self.factory.makeProduct(
67+ official_malone=True, private_bugs=True)
68+ with FeatureFixture(feature_flags):
69+ with person_logged_in(product.owner):
70+ view = create_initialized_view(
71+ product, '+filebug', principal=product.owner)
72+ html = view.render()
73+ soup = BeautifulSoup(html)
74+ for info_type in PRIVATE_INFORMATION_TYPES:
75+ self.assertIsNotNone(soup.find('label', text=info_type.title))
76+ for info_type in PUBLIC_INFORMATION_TYPES:
77+ self.assertIsNone(soup.find('label', text=info_type.title))
78
79
80 class TestFileBugSourcePackage(TestCaseWithFactory):
81
82=== modified file 'lib/lp/registry/tests/test_information_type_vocabulary.py'
83--- lib/lp/registry/tests/test_information_type_vocabulary.py 2012-05-16 23:56:08 +0000
84+++ lib/lp/registry/tests/test_information_type_vocabulary.py 2012-05-29 03:24:19 +0000
85@@ -8,17 +8,41 @@
86
87 from testtools.matchers import MatchesStructure
88
89-from lp.registry.enums import InformationType
90+from lp.registry.enums import (
91+ InformationType,
92+ PRIVATE_INFORMATION_TYPES,
93+ PUBLIC_INFORMATION_TYPES,
94+ )
95 from lp.registry.vocabularies import InformationTypeVocabulary
96 from lp.services.features.testing import FeatureFixture
97-from lp.testing import TestCase
98+from lp.testing import TestCaseWithFactory
99 from lp.testing.layers import DatabaseFunctionalLayer
100
101
102-class TestInformationTypeVocabulary(TestCase):
103+class TestInformationTypeVocabulary(TestCaseWithFactory):
104
105 layer = DatabaseFunctionalLayer
106
107+ def test_vocabulary_items(self):
108+ vocab = InformationTypeVocabulary()
109+ for info_type in InformationType:
110+ self.assertIn(info_type.value, vocab)
111+
112+ def test_vocabulary_items_project(self):
113+ # The vocab has all info types for a project without private_bugs set.
114+ vocab = InformationTypeVocabulary()
115+ for info_type in InformationType:
116+ self.assertIn(info_type.value, vocab)
117+
118+ def test_vocabulary_items_private_bugs_project(self):
119+ # The vocab has private info types for a project with private_bugs set.
120+ product = self.factory.makeProduct(private_bugs=True)
121+ vocab = InformationTypeVocabulary(product)
122+ for info_type in PRIVATE_INFORMATION_TYPES:
123+ self.assertIn(info_type, vocab)
124+ for info_type in PUBLIC_INFORMATION_TYPES:
125+ self.assertNotIn(info_type, vocab)
126+
127 def test_getTermByToken(self):
128 vocab = InformationTypeVocabulary()
129 self.assertThat(
130
131=== modified file 'lib/lp/registry/vocabularies.py'
132--- lib/lp/registry/vocabularies.py 2012-05-13 23:59:55 +0000
133+++ lib/lp/registry/vocabularies.py 2012-05-29 03:24:19 +0000
134@@ -2231,10 +2231,8 @@
135
136 implements(IEnumeratedType)
137
138- def __init__(self):
139+ def __init__(self, context=None):
140 types = [
141- InformationType.PUBLIC,
142- InformationType.UNEMBARGOEDSECURITY,
143 InformationType.EMBARGOEDSECURITY,
144 InformationType.USERDATA]
145 proprietary_disabled = bool(getFeatureFlag(
146@@ -2243,6 +2241,12 @@
147 'disclosure.display_userdata_as_private.enabled'))
148 if not proprietary_disabled:
149 types.append(InformationType.PROPRIETARY)
150+ if (context is None or
151+ not IProduct.providedBy(context) or
152+ not context.private_bugs):
153+ types.insert(0, InformationType.UNEMBARGOEDSECURITY)
154+ types.insert(0, InformationType.PUBLIC)
155+
156 terms = []
157 for type in types:
158 title = type.title
159
160=== modified file 'lib/lp/testing/factory.py'
161--- lib/lp/testing/factory.py 2012-05-25 01:48:31 +0000
162+++ lib/lp/testing/factory.py 2012-05-29 03:24:19 +0000
163@@ -947,7 +947,7 @@
164 self, name=None, project=None, displayname=None,
165 licenses=None, owner=None, registrant=None,
166 title=None, summary=None, official_malone=None,
167- translations_usage=None, bug_supervisor=None,
168+ translations_usage=None, bug_supervisor=None, private_bugs=False,
169 driver=None, security_contact=None, icon=None):
170 """Create and return a new, arbitrary Product."""
171 if owner is None:
172@@ -989,6 +989,8 @@
173 naked_product.driver = driver
174 if security_contact is not None:
175 naked_product.security_contact = security_contact
176+ if private_bugs:
177+ naked_product.private_bugs = private_bugs
178 return product
179
180 def makeProductSeries(self, product=None, name=None, owner=None,