← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~stevenk/launchpad/information_type-vocab into lp:launchpad

 

Steve Kowalik has proposed merging lp:~stevenk/launchpad/information_type-vocab into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #933766 in Launchpad itself: "Update bug to use information_visibility_policy"
  https://bugs.launchpad.net/launchpad/+bug/933766

For more details, see:
https://code.launchpad.net/~stevenk/launchpad/information_type-vocab/+merge/101486

Add a vocabulary for the InformationType enum. I have added two feature flags, one that changes User Data to display as Private, and the other that hides Proprietary. I have pulled in some code into BugView which is tested, but not used yet to make later branches a little smaller.

This branch isn't testable on it's own, it is just setting up plumbing for the upcoming UI branches.
-- 
https://code.launchpad.net/~stevenk/launchpad/information_type-vocab/+merge/101486
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/information_type-vocab into lp:launchpad.
=== modified file 'lib/lp/bugs/browser/bug.py'
--- lib/lp/bugs/browser/bug.py	2012-04-03 06:14:09 +0000
+++ lib/lp/bugs/browser/bug.py	2012-04-11 05:09:21 +0000
@@ -95,7 +95,12 @@
 from lp.bugs.model.structuralsubscription import (
     get_structural_subscriptions_for_bug,
     )
-from lp.registry.enums import InformationType
+from lp.registry.enums import (
+    InformationType,
+    PRIVATE_INFORMATION_TYPES,
+    )
+from lp.registry.vocabularies import InformationTypeVocabulary
+from lp.services.features import getFeatureFlag
 from lp.services.fields import DuplicateBug
 from lp.services.librarian.browser import ProxiedLibraryFileAlias
 from lp.services.mail.mailwrapper import MailWrapper
@@ -548,6 +553,17 @@
     all the pages off IBugTask instead of IBug.
     """
 
+    def initialize(self):
+        super(BugView, self).initialize()
+        cache = IJSONRequestCache(self.request)
+        cache.objects['information_types'] = [
+            {'value': term.value, 'description': term.description,
+            'name': term.title} for term in InformationTypeVocabulary()]
+        cache.objects['private_types'] = [
+            type.value for type in PRIVATE_INFORMATION_TYPES]
+        cache.objects['initial_information_type'] = (
+            IBug(self.context).information_type.value)
+
     @cachedproperty
     def page_description(self):
         return IBug(self.context).description
@@ -596,6 +612,16 @@
         return ProxiedLibraryFileAlias(
             attachment.libraryfile, attachment).http_url
 
+    @property
+    def information_type(self):
+        title = self.context.information_type.title
+        show_userdata_as_private = bool(getFeatureFlag(
+            'disclosure.display_userdata_as_private.enabled'))
+        if (
+            self.context.information_type == InformationType.USERDATA and
+            show_userdata_as_private):
+            return 'Private'
+        return title
 
 class BugActivity(BugView):
 

=== modified file 'lib/lp/bugs/browser/tests/test_bugview.py'
--- lib/lp/bugs/browser/tests/test_bugview.py	2012-01-01 02:58:52 +0000
+++ lib/lp/bugs/browser/tests/test_bugview.py	2012-04-11 05:09:21 +0000
@@ -1,4 +1,4 @@
-# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# Copyright 2010-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -6,6 +6,8 @@
 from zope.security.proxy import removeSecurityProxy
 
 from lp.bugs.browser.bug import BugView
+from lp.registry.enums import InformationType
+from lp.services.features.testing import FeatureFixture
 from lp.services.webapp.servers import LaunchpadTestRequest
 from lp.testing import (
     login,
@@ -54,3 +56,18 @@
             ['patch'],
             [attachment['attachment'].title
              for attachment in self.view.patches])
+
+    def test_information_type(self):
+        self.bug.transitionToInformationType(
+            InformationType.USERDATA, self.bug.owner)
+        self.assertEqual(
+            self.bug.information_type.title, self.view.information_type)
+        
+    def test_information_type_feature_flag(self):
+        self.bug.transitionToInformationType(
+            InformationType.USERDATA, self.bug.owner)
+        feature_flag = {
+            'disclosure.display_userdata_as_private.enabled': 'on'}
+        with FeatureFixture(feature_flag):
+            view = BugView(self.bug, LaunchpadTestRequest())
+            self.assertEqual('Private', view.information_type)

=== added file 'lib/lp/registry/tests/test_information_type_vocabulary.py'
--- lib/lp/registry/tests/test_information_type_vocabulary.py	1970-01-01 00:00:00 +0000
+++ lib/lp/registry/tests/test_information_type_vocabulary.py	2012-04-11 05:09:21 +0000
@@ -0,0 +1,62 @@
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Test the Distribution Source Package vocabulary."""
+
+__metaclass__ = type
+
+
+from lp.registry.enums import InformationType
+from lp.registry.vocabularies import InformationTypeVocabulary
+from lp.services.features.testing import FeatureFixture
+from lp.testing import TestCase
+from lp.testing.layers import DatabaseFunctionalLayer
+
+
+class TestInformationTypeVocabulary(TestCase):
+
+    layer = DatabaseFunctionalLayer
+
+    def test_getTermByToken(self):
+        vocab = InformationTypeVocabulary()
+        term = vocab.getTermByToken('PUBLIC')
+        self.assertEqual(InformationType.PUBLIC, term.value)
+        self.assertEqual('PUBLIC', term.token)
+        self.assertEqual('Public', term.title)
+        self.assertEqual(
+            InformationType.PUBLIC.description, term.description)
+
+    def test_proprietary_disabled(self):
+        feature_flag = {
+            'disclosure.proprietary_information_type.disabled': 'on'}
+        with FeatureFixture(feature_flag):
+            vocab = InformationTypeVocabulary()
+            self.assertRaises(
+                LookupError, vocab.getTermByToken, 'PROPRIETARY')
+
+    def test_proprietary_enabled(self):
+        vocab = InformationTypeVocabulary()
+        term = vocab.getTermByToken('PROPRIETARY')
+        self.assertEqual('Proprietary', term.title)
+
+    def test_display_userdata_as_private(self):
+        feature_flag = {
+            'disclosure.display_userdata_as_private.enabled': 'on'}
+        with FeatureFixture(feature_flag):
+            vocab = InformationTypeVocabulary()
+            term = vocab.getTermByToken('USERDATA')
+            self.assertEqual('Private', term.title)
+            self.assertEqual(
+                "Only users with permission to see the project's artifacts "
+                "containing\nprivate information can see this "
+                "information.\n",
+                term.description)
+
+    def test_userdata(self):
+        vocab = InformationTypeVocabulary()
+        term = vocab.getTermByToken('USERDATA')
+        self.assertEqual('User Data', term.title)
+        self.assertEqual(
+            "Only users with permission to see the project's artifacts "
+            "containing\nuser data can see this information.\n",
+            term.description)

=== modified file 'lib/lp/registry/vocabularies.py'
--- lib/lp/registry/vocabularies.py	2012-03-27 21:34:58 +0000
+++ lib/lp/registry/vocabularies.py	2012-04-11 05:09:21 +0000
@@ -39,6 +39,7 @@
     'FeaturedProjectVocabulary',
     'FilteredDistroSeriesVocabulary',
     'FilteredProductSeriesVocabulary',
+    'InformationTypeVocabulary',
     'KarmaCategoryVocabulary',
     'MilestoneVocabulary',
     'NewPillarShareeVocabulary',
@@ -102,6 +103,7 @@
 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
 from lp.blueprints.interfaces.specification import ISpecification
 from lp.bugs.interfaces.bugtask import IBugTask
+from lp.registry.enums import InformationType
 from lp.registry.interfaces.accesspolicy import IAccessPolicySource
 from lp.registry.interfaces.distribution import (
     IDistribution,
@@ -172,6 +174,7 @@
     SQLBase,
     sqlvalues,
     )
+from lp.services.features import getFeatureFlag
 from lp.services.helpers import (
     ensure_unicode,
     shortlist,
@@ -2220,3 +2223,31 @@
             SQL('DistributionSourcePackage.id = SearchableDSP.id'))
 
         return CountableIterator(dsps.count(), dsps, self.toTerm)
+
+
+class InformationTypeVocabulary(SimpleVocabulary):
+
+    def __init__(self):
+        types = [
+            InformationType.PUBLIC,
+            InformationType.UNEMBARGOEDSECURITY,
+            InformationType.EMBARGOEDSECURITY,
+            InformationType.USERDATA]
+        proprietary_disabled = bool(getFeatureFlag(
+            'disclosure.proprietary_information_type.disabled'))
+        show_userdata_as_private = bool(getFeatureFlag(
+            'disclosure.display_userdata_as_private.enabled'))
+        if not proprietary_disabled:
+            types.append(InformationType.PROPRIETARY)
+        terms = []
+        for type in types:
+            title = type.title
+            description = type.description
+            if type == InformationType.USERDATA and show_userdata_as_private:
+                title = 'Private'
+                description = (
+                    description.replace('user data', 'private information'))
+            term = SimpleTerm(type, type.name, title)
+            term.description = description
+            terms.append(term)
+        super(InformationTypeVocabulary, self).__init__(terms)

=== modified file 'lib/lp/registry/vocabularies.zcml'
--- lib/lp/registry/vocabularies.zcml	2012-03-27 04:06:21 +0000
+++ lib/lp/registry/vocabularies.zcml	2012-04-11 05:09:21 +0000
@@ -1,4 +1,4 @@
-<!-- Copyright 2009 Canonical Ltd.  This software is licensed under the
+<!-- Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
      GNU Affero General Public License version 3 (see the file LICENSE).
 -->
 
@@ -536,4 +536,10 @@
             permission="zope.Public"
             attributes="name title description"/>
     </class>
+    <class
+        class="lp.registry.vocabularies.InformationTypeVocabulary">
+        <require
+            permission="zope.Public"
+            attributes="name title description"/>
+    </class>
 </configure>

=== modified file 'lib/lp/services/features/flags.py'
--- lib/lp/services/features/flags.py	2012-04-09 14:17:07 +0000
+++ lib/lp/services/features/flags.py	2012-04-11 05:09:21 +0000
@@ -315,12 +315,27 @@
      '',
      '',
      ''),
+<<<<<<< TREE
     ('registry.upcoming_work_view.enabled',
      'boolean',
      ('If true, the new upcoming work view of teams is available.'),
      '',
      '',
      ''),
+=======
+    ('disclosure.proprietary_information_type.disabled',
+     'boolean',
+     'If true, disables the PROPRIETARY information_type for bugs.',
+     '',
+     '',
+     ''),
+    ('disclosure.display_userdata_as_private.enabled',
+     'boolean',
+     'If true, displays the USERDATA information_type as Private.',
+     '',
+     '',
+     ''),
+>>>>>>> MERGE-SOURCE
     ])
 
 # The set of all flag names that are documented.