← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/person-product-privacy into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/person-product-privacy into lp:launchpad.

Commit message:
Make PersonProduct implement IPrivacy (and IInformationType), so that the privacy banner works.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/person-product-privacy/+merge/324693
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/person-product-privacy into lp:launchpad.
=== modified file 'lib/lp/registry/interfaces/personproduct.py'
--- lib/lp/registry/interfaces/personproduct.py	2013-01-07 02:40:55 +0000
+++ lib/lp/registry/interfaces/personproduct.py	2017-05-26 17:23:18 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2017 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """A person's view on a product."""
@@ -13,6 +13,8 @@
 from zope.interface import Interface
 from zope.schema import TextLine
 
+from lp.app.interfaces.informationtype import IInformationType
+from lp.app.interfaces.launchpad import IPrivacy
 from lp.code.interfaces.hasbranches import (
     IHasBranches,
     IHasMergeProposals,
@@ -21,7 +23,8 @@
 from lp.registry.interfaces.product import IProduct
 
 
-class IPersonProduct(IHasMergeProposals, IHasBranches):
+class IPersonProduct(IHasMergeProposals, IHasBranches, IPrivacy,
+                     IInformationType):
     """A person's view on a product."""
 
     person = Reference(IPerson)

=== modified file 'lib/lp/registry/model/personproduct.py'
--- lib/lp/registry/model/personproduct.py	2015-07-08 16:05:11 +0000
+++ lib/lp/registry/model/personproduct.py	2017-05-26 17:23:18 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2017 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """A person's view on a product."""
@@ -45,3 +45,11 @@
 
     def __ne__(self, other):
         return not self == other
+
+    @property
+    def private(self):
+        return self.person.private or self.product.private
+
+    @property
+    def information_type(self):
+        return self.product.information_type

=== modified file 'lib/lp/registry/tests/test_personproduct.py'
--- lib/lp/registry/tests/test_personproduct.py	2012-09-24 15:58:53 +0000
+++ lib/lp/registry/tests/test_personproduct.py	2017-05-26 17:23:18 +0000
@@ -1,14 +1,21 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2017 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test the Person/Product non-database class."""
 
 __metaclass__ = type
 
+from lp.app.enums import InformationType
+from lp.app.interfaces.informationtype import IInformationType
+from lp.app.interfaces.launchpad import IPrivacy
+from lp.registry.enums import PersonVisibility
 from lp.registry.model.personproduct import PersonProduct
 from lp.services.webapp.interfaces import IBreadcrumb
 from lp.services.webapp.publisher import canonical_url
-from lp.testing import TestCaseWithFactory
+from lp.testing import (
+    TestCaseWithFactory,
+    verifyObject,
+    )
 from lp.testing.layers import DatabaseFunctionalLayer
 
 
@@ -34,3 +41,34 @@
         pp = self._makePersonProduct()
         breadcrumb = IBreadcrumb(pp, None)
         self.assertEqual(canonical_url(pp.product), breadcrumb.url)
+
+    def test_implements_IInformationType(self):
+        pp = self._makePersonProduct()
+        verifyObject(IInformationType, pp)
+
+    def test_implements_IPrivacy(self):
+        pp = self._makePersonProduct()
+        verifyObject(IPrivacy, pp)
+
+    def test_private_person(self):
+        # A person product is private if its person (really team) is.
+        team = self.factory.makeTeam(visibility=PersonVisibility.PRIVATE)
+        product = self.factory.makeProduct()
+        pp = PersonProduct(team, product)
+        self.assertTrue(pp.private)
+        self.assertEqual(InformationType.PUBLIC, pp.information_type)
+
+    def test_private_product(self):
+        # A person product is private if its product is.
+        person = self.factory.makePerson()
+        product = self.factory.makeProduct(
+            information_type=InformationType.PROPRIETARY)
+        pp = PersonProduct(person, product)
+        self.assertTrue(pp.private)
+        self.assertEqual(InformationType.PROPRIETARY, pp.information_type)
+
+    def test_public(self):
+        # A person product is public if both its person and product are.
+        pp = self._makePersonProduct()
+        self.assertFalse(pp.private)
+        self.assertEqual(InformationType.PUBLIC, pp.information_type)


Follow ups