← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/git-ref-privacy-banner into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/git-ref-privacy-banner into lp:launchpad.

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

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1457553 in Launchpad itself: "Refs in private Git repositories have no privacy banner"
  https://bugs.launchpad.net/launchpad/+bug/1457553

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/git-ref-privacy-banner/+merge/259803

Make GitRef implement IPrivacy (and IInformationType), so that the privacy banner works.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/git-ref-privacy-banner into lp:launchpad.
=== modified file 'lib/lp/code/interfaces/gitref.py'
--- lib/lp/code/interfaces/gitref.py	2015-05-13 16:56:06 +0000
+++ lib/lp/code/interfaces/gitref.py	2015-05-21 16:48:38 +0000
@@ -39,6 +39,8 @@
     )
 
 from lp import _
+from lp.app.interfaces.informationtype import IInformationType
+from lp.app.interfaces.launchpad import IPrivacy
 from lp.code.enums import (
     BranchMergeProposalStatus,
     GitObjectType,
@@ -48,7 +50,7 @@
 from lp.services.webapp.interfaces import ITableBatchNavigator
 
 
-class IGitRef(IHasMergeProposals):
+class IGitRef(IHasMergeProposals, IPrivacy, IInformationType):
     """A reference in a Git repository."""
 
     # XXX cjwatson 2015-01-19 bug=760849: "beta" is a lie to get WADL
@@ -135,6 +137,12 @@
         "The type of information contained in the repository containing this "
         "reference.")
 
+    private = Bool(
+        title=_("Private"), required=False, readonly=True,
+        description=_(
+            "The repository containing this reference is visible only to its "
+            "subscribers."))
+
     def visibleByUser(user):
         """Can the specified user see the repository containing this
         reference?"""

=== modified file 'lib/lp/code/model/gitref.py'
--- lib/lp/code/model/gitref.py	2015-05-13 16:56:06 +0000
+++ lib/lp/code/model/gitref.py	2015-05-21 16:48:38 +0000
@@ -106,6 +106,11 @@
         """See `IGitRef`."""
         return self.repository.information_type
 
+    @property
+    def private(self):
+        """See `IGitRef`."""
+        return self.repository.private
+
     def visibleByUser(self, user):
         """See `IGitRef`."""
         return self.repository.visibleByUser(user)

=== modified file 'lib/lp/code/model/tests/test_gitref.py'
--- lib/lp/code/model/tests/test_gitref.py	2015-05-14 13:57:51 +0000
+++ lib/lp/code/model/tests/test_gitref.py	2015-05-21 16:48:38 +0000
@@ -9,12 +9,16 @@
 
 from testtools.matchers import EndsWith
 
+from lp.app.enums import InformationType
+from lp.app.interfaces.informationtype import IInformationType
+from lp.app.interfaces.launchpad import IPrivacy
 from lp.services.webapp.interfaces import OAuthPermission
 from lp.testing import (
     ANONYMOUS,
     api_url,
     person_logged_in,
     TestCaseWithFactory,
+    verifyObject,
     )
 from lp.testing.layers import DatabaseFunctionalLayer
 from lp.testing.pages import webservice_for_person
@@ -37,6 +41,20 @@
         bmp = self.factory.makeBranchMergeProposalForGit(target_ref=target_ref)
         self.assertEqual([bmp], list(target_ref.getMergeProposals()))
 
+    def test_implements_IInformationType(self):
+        [ref] = self.factory.makeGitRefs()
+        verifyObject(IInformationType, ref)
+
+    def test_implements_IPrivacy(self):
+        [ref] = self.factory.makeGitRefs()
+        verifyObject(IPrivacy, ref)
+
+    def test_refs_in_private_repositories_are_private(self):
+        [ref] = self.factory.makeGitRefs(
+            information_type=InformationType.USERDATA)
+        self.assertTrue(ref.private)
+        self.assertEqual(InformationType.USERDATA, ref.information_type)
+
 
 class TestGitRefWebservice(TestCaseWithFactory):
     """Tests for the webservice."""


Follow ups