← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rharding/launchpad/limit_product_types_1066904 into lp:launchpad

 

Richard Harding has proposed merging lp:~rharding/launchpad/limit_product_types_1066904 into lp:launchpad.

Commit message:
Limit the information type widget vocabulary on project modifications.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1066904 in Launchpad itself: "editing project information type without JS shouldn't show invalid information types"
  https://bugs.launchpad.net/launchpad/+bug/1066904

For more details, see:
https://code.launchpad.net/~rharding/launchpad/limit_product_types_1066904/+merge/131368

= Summary =

The vocabulary of the information type isn't currently limited to the only
allowed information types.

This forces the information type to only be rendered as the three permitted.


== Implementation Notes ==

This just alters the widget to have a different set of vocabulary and adds a
test to make sure it's limited.


== Tests ==

registry/browser/test_product.py



-- 
https://code.launchpad.net/~rharding/launchpad/limit_product_types_1066904/+merge/131368
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rharding/launchpad/limit_product_types_1066904 into lp:launchpad.
=== modified file 'lib/lp/registry/browser/product.py'
--- lib/lp/registry/browser/product.py	2012-10-25 09:03:19 +0000
+++ lib/lp/registry/browser/product.py	2012-10-25 14:33:19 +0000
@@ -111,6 +111,7 @@
 from lp.app.interfaces.headings import IEditableContextTitle
 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
 from lp.app.utilities import json_dump_information_types
+from lp.app.vocabularies import InformationTypeVocabulary
 from lp.app.widgets.date import DateWidget
 from lp.app.widgets.itemswidgets import (
     CheckBoxMatrixWidget,
@@ -1392,7 +1393,11 @@
         ]
     custom_widget('licenses', LicenseWidget)
     custom_widget('license_info', GhostWidget)
-    custom_widget('information_type', LaunchpadRadioWidgetWithDescription)
+    custom_widget(
+        'information_type',
+        LaunchpadRadioWidgetWithDescription,
+        vocabulary=InformationTypeVocabulary(
+            types=PUBLIC_PROPRIETARY_INFORMATION_TYPES))
 
     @property
     def next_url(self):
@@ -1917,7 +1922,11 @@
     custom_widget('homepageurl', TextWidget, displayWidth=30)
     custom_widget('licenses', LicenseWidget)
     custom_widget('license_info', GhostWidget)
-    custom_widget('information_type', LaunchpadRadioWidgetWithDescription)
+    custom_widget(
+        'information_type',
+        LaunchpadRadioWidgetWithDescription,
+        vocabulary=InformationTypeVocabulary(
+            types=PUBLIC_PROPRIETARY_INFORMATION_TYPES))
 
     custom_widget(
         'owner', PersonPickerWidget, header="Select the maintainer",

=== modified file 'lib/lp/registry/browser/tests/test_product.py'
--- lib/lp/registry/browser/tests/test_product.py	2012-10-25 09:03:19 +0000
+++ lib/lp/registry/browser/tests/test_product.py	2012-10-25 14:33:19 +0000
@@ -487,6 +487,19 @@
             'field.license_info': license_info,
         }
 
+    def test_limited_information_types_allowed(self):
+        """Products can only be PUBLIC_PROPRIETARY_INFORMATION_TYPES"""
+        product = self.factory.makeProduct()
+        with FeatureFixture({u'disclosure.private_projects.enabled': u'on'}):
+            login_person(product.owner)
+            view = create_initialized_view(
+                product,
+                '+edit',
+                principal=product.owner)
+            info_types = [t.name for t in view.widgets['information_type'].vocabulary]
+            expected = ['PUBLIC', 'PROPRIETARY', 'EMBARGOED']
+            self.assertEqual(expected, info_types)
+
     def test_change_information_type_proprietary(self):
         product = self.factory.makeProduct(name='fnord')
         with FeatureFixture({u'disclosure.private_projects.enabled': u'on'}):


Follow ups