← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Ian Booth has proposed merging lp:~wallyworld/launchpad/file-private-bug-1004702 into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~wallyworld/launchpad/file-private-bug-1004702/+merge/107704

== 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
-- 
https://code.launchpad.net/~wallyworld/launchpad/file-private-bug-1004702/+merge/107704
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wallyworld/launchpad/file-private-bug-1004702 into lp:launchpad.
=== modified file 'lib/lp/bugs/browser/bugtarget.py'
--- lib/lp/bugs/browser/bugtarget.py	2012-05-25 14:38:42 +0000
+++ lib/lp/bugs/browser/bugtarget.py	2012-05-29 03:24:19 +0000
@@ -288,7 +288,7 @@
         if self.show_information_type_in_ui:
             information_type_field = copy_field(
                 IBug['information_type'], readonly=False,
-                vocabulary=InformationTypeVocabulary())
+                vocabulary=InformationTypeVocabulary(self.context))
             self.form_fields = self.form_fields.omit('information_type')
             self.form_fields += Fields(information_type_field)
         else:

=== modified file 'lib/lp/bugs/browser/tests/test_bugtarget_filebug.py'
--- lib/lp/bugs/browser/tests/test_bugtarget_filebug.py	2012-05-27 23:04:28 +0000
+++ lib/lp/bugs/browser/tests/test_bugtarget_filebug.py	2012-05-29 03:24:19 +0000
@@ -25,6 +25,7 @@
 from lp.registry.enums import (
     InformationType,
     PRIVATE_INFORMATION_TYPES,
+    PUBLIC_INFORMATION_TYPES,
     )
 from lp.services.features.testing import FeatureFixture
 from lp.services.webapp.servers import LaunchpadTestRequest
@@ -392,9 +393,9 @@
         bug = self.filebug_via_view(private_bugs=True)
         self.assertEqual(InformationType.USERDATA, bug.information_type)
 
-    def test_filebug_information_type_vocabulary(self):
+    def test_filebug_information_type_vocabulary_userdata_private(self):
         # The vocabulary for information_type when filing a bug is created
-        # correctly.
+        # correctly when 'User Data' is to be replaced by 'Private'.
         feature_flags = {
             'disclosure.show_information_type_in_ui.enabled': 'on',
             'disclosure.proprietary_information_type.disabled': 'on',
@@ -407,8 +408,41 @@
                 html = view.render()
                 soup = BeautifulSoup(html)
         self.assertEqual(u'Private', soup.find('label', text="Private"))
-        self.assertIs(None, soup.find('label', text="User Data"))
-        self.assertIs(None, soup.find('label', text="Proprietary"))
+        self.assertIsNone(soup.find('label', text="User Data"))
+        self.assertIsNone(soup.find('label', text="Proprietary"))
+
+    def test_filebug_information_type_vocabulary(self):
+        # The vocabulary for information_type when filing a bug is created
+        # correctly.
+        feature_flags = {
+            'disclosure.show_information_type_in_ui.enabled': 'on'}
+        product = self.factory.makeProduct(official_malone=True)
+        with FeatureFixture(feature_flags):
+            with person_logged_in(product.owner):
+                view = create_initialized_view(
+                    product, '+filebug', principal=product.owner)
+                html = view.render()
+                soup = BeautifulSoup(html)
+        for info_type in InformationType:
+            self.assertIsNotNone(soup.find('label', text=info_type.title))
+
+    def test_filebug_information_type_vocabulary_private_projects(self):
+        # The vocabulary for information_type when filing a bug only has
+        # private info types for private bug projects.
+        feature_flags = {
+            'disclosure.show_information_type_in_ui.enabled': 'on'}
+        product = self.factory.makeProduct(
+            official_malone=True, private_bugs=True)
+        with FeatureFixture(feature_flags):
+            with person_logged_in(product.owner):
+                view = create_initialized_view(
+                    product, '+filebug', principal=product.owner)
+                html = view.render()
+                soup = BeautifulSoup(html)
+        for info_type in PRIVATE_INFORMATION_TYPES:
+            self.assertIsNotNone(soup.find('label', text=info_type.title))
+        for info_type in PUBLIC_INFORMATION_TYPES:
+            self.assertIsNone(soup.find('label', text=info_type.title))
 
 
 class TestFileBugSourcePackage(TestCaseWithFactory):

=== modified file 'lib/lp/registry/tests/test_information_type_vocabulary.py'
--- lib/lp/registry/tests/test_information_type_vocabulary.py	2012-05-16 23:56:08 +0000
+++ lib/lp/registry/tests/test_information_type_vocabulary.py	2012-05-29 03:24:19 +0000
@@ -8,17 +8,41 @@
 
 from testtools.matchers import MatchesStructure
 
-from lp.registry.enums import InformationType
+from lp.registry.enums import (
+    InformationType,
+    PRIVATE_INFORMATION_TYPES,
+    PUBLIC_INFORMATION_TYPES,
+    )
 from lp.registry.vocabularies import InformationTypeVocabulary
 from lp.services.features.testing import FeatureFixture
-from lp.testing import TestCase
+from lp.testing import TestCaseWithFactory
 from lp.testing.layers import DatabaseFunctionalLayer
 
 
-class TestInformationTypeVocabulary(TestCase):
+class TestInformationTypeVocabulary(TestCaseWithFactory):
 
     layer = DatabaseFunctionalLayer
 
+    def test_vocabulary_items(self):
+        vocab = InformationTypeVocabulary()
+        for info_type in InformationType:
+            self.assertIn(info_type.value, vocab)
+
+    def test_vocabulary_items_project(self):
+        # The vocab has all info types for a project without private_bugs set.
+        vocab = InformationTypeVocabulary()
+        for info_type in InformationType:
+            self.assertIn(info_type.value, vocab)
+
+    def test_vocabulary_items_private_bugs_project(self):
+        # The vocab has private info types for a project with private_bugs set.
+        product = self.factory.makeProduct(private_bugs=True)
+        vocab = InformationTypeVocabulary(product)
+        for info_type in PRIVATE_INFORMATION_TYPES:
+            self.assertIn(info_type, vocab)
+        for info_type in PUBLIC_INFORMATION_TYPES:
+            self.assertNotIn(info_type, vocab)
+
     def test_getTermByToken(self):
         vocab = InformationTypeVocabulary()
         self.assertThat(

=== modified file 'lib/lp/registry/vocabularies.py'
--- lib/lp/registry/vocabularies.py	2012-05-13 23:59:55 +0000
+++ lib/lp/registry/vocabularies.py	2012-05-29 03:24:19 +0000
@@ -2231,10 +2231,8 @@
 
     implements(IEnumeratedType)
 
-    def __init__(self):
+    def __init__(self, context=None):
         types = [
-            InformationType.PUBLIC,
-            InformationType.UNEMBARGOEDSECURITY,
             InformationType.EMBARGOEDSECURITY,
             InformationType.USERDATA]
         proprietary_disabled = bool(getFeatureFlag(
@@ -2243,6 +2241,12 @@
             'disclosure.display_userdata_as_private.enabled'))
         if not proprietary_disabled:
             types.append(InformationType.PROPRIETARY)
+        if (context is None or
+            not IProduct.providedBy(context) or
+            not context.private_bugs):
+            types.insert(0, InformationType.UNEMBARGOEDSECURITY)
+            types.insert(0, InformationType.PUBLIC)
+
         terms = []
         for type in types:
             title = type.title

=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py	2012-05-25 01:48:31 +0000
+++ lib/lp/testing/factory.py	2012-05-29 03:24:19 +0000
@@ -947,7 +947,7 @@
         self, name=None, project=None, displayname=None,
         licenses=None, owner=None, registrant=None,
         title=None, summary=None, official_malone=None,
-        translations_usage=None, bug_supervisor=None,
+        translations_usage=None, bug_supervisor=None, private_bugs=False,
         driver=None, security_contact=None, icon=None):
         """Create and return a new, arbitrary Product."""
         if owner is None:
@@ -989,6 +989,8 @@
             naked_product.driver = driver
         if security_contact is not None:
             naked_product.security_contact = security_contact
+        if private_bugs:
+            naked_product.private_bugs = private_bugs
         return product
 
     def makeProductSeries(self, product=None, name=None, owner=None,


Follow ups