← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~twom/launchpad:gdpr-add-git-info into launchpad:master

 

Tom Wardill has proposed merging ~twom/launchpad:gdpr-add-git-info into launchpad:master.

Commit message:
Add git repository output to GDPR endpoint

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~twom/launchpad/+git/launchpad/+merge/405742
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:gdpr-add-git-info into launchpad:master.
diff --git a/lib/lp/registry/model/person.py b/lib/lp/registry/model/person.py
index 1602f4b..198e283 100644
--- a/lib/lp/registry/model/person.py
+++ b/lib/lp/registry/model/person.py
@@ -4095,6 +4095,10 @@ class PersonSet:
         branches_url = self._checkForBranchData(account)
         if branches_url:
             return_data["branches"] = branches_url
+        # Git repositories
+        git_url = self._checkForGitRepositoryData(account)
+        if git_url:
+            return_data["git-repositories"] = git_url
         # This is only an 'account' in terms of the end user view,
         # it does not refer to an `IAccount`.
         if len(return_data.keys()) > 1:
@@ -4120,6 +4124,13 @@ class PersonSet:
             "field.sort_by-empty-marker": "1"})
         return req.url
 
+    def _checkForGitRepositoryData(self, account):
+        """Check if git repositories exist for a given person."""
+        from lp.code.interfaces.gitrepository import IGitRepositorySet
+        repositories = getUtility(IGitRepositorySet).getRepositories(account)
+        if repositories.is_empty():
+            return None
+        return canonical_url(account, rootsite='code', view_name='+git')
 
     def getUserOverview(self, person):
         """See `IPersonSet`."""
diff --git a/lib/lp/registry/tests/test_personset.py b/lib/lp/registry/tests/test_personset.py
index 8b6bafb..dff05bb 100644
--- a/lib/lp/registry/tests/test_personset.py
+++ b/lib/lp/registry/tests/test_personset.py
@@ -1236,6 +1236,30 @@ class TestGDPRUserRetrieval(TestCaseWithFactory):
                 canonical_url(
                     person, rootsite="code", view_name="+branches"))}))
 
+    def test_account_data_repositories(self):
+        person = self.factory.makePerson(email="test@xxxxxxxxxxx")
+        self.factory.makeGitRepository(owner=person)
+        with admin_logged_in():
+            result = self.person_set.getUserData(u"test@xxxxxxxxxxx")
+        self.assertThat(result, ContainsDict({
+            "status": Equals("account with data"),
+            "person": Equals(canonical_url(person)),
+            "git-repositories": Equals(
+                canonical_url(
+                    person, rootsite="code", view_name="+git"))}))
+
+    def test_account_data_repositories_other_owners(self):
+        # Check that we only report on repositories that
+        # we care about
+        person = self.factory.makePerson(email="test@xxxxxxxxxxx")
+        other_person = self.factory.makePerson(email="other@xxxxxxxxxxx")
+        self.factory.makeGitRepository(owner=other_person)
+        with admin_logged_in():
+            result = self.person_set.getUserData(u"test@xxxxxxxxxxx")
+        self.assertThat(result, ContainsDict({
+            "status": Equals("account with data"),
+            "person": Equals(canonical_url(person))}))
+
     def test_getUserOverview(self):
         ppa = self.factory.makeArchive(owner=self.user)