← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~twom/launchpad:gdbr-add-bzr-branches into launchpad:master

 

Tom Wardill has proposed merging ~twom/launchpad:gdbr-add-bzr-branches into launchpad:master.

Commit message:
Add bzr branch output to GDPR data retrieval

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~twom/launchpad/+git/launchpad/+merge/405703
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:gdbr-add-bzr-branches into launchpad:master.
diff --git a/lib/lp/registry/model/person.py b/lib/lp/registry/model/person.py
index edac8e9..dbadb17 100644
--- a/lib/lp/registry/model/person.py
+++ b/lib/lp/registry/model/person.py
@@ -44,6 +44,7 @@ from lazr.restful.utils import (
     smartquote,
     )
 import pytz
+from requests import PreparedRequest
 import six
 from sqlobject import (
     BoolCol,
@@ -4084,13 +4085,33 @@ class PersonSet:
             return {"status": "no data held"}
 
         account = email_results.one()[1]
-        # This is only an 'account' in terms of the end user view,
-        # it does not refer to an `IAccount`.
-        return_data = {"status": "account only; no other data"}
+        return_data = {}
         return_data["person"] = canonical_url(account)
         # Get the data behind the overview screen
         overview = self.getUserOverview(account)
         return_data.update(overview)
+
+        # bzr branches
+        branches = account.getBranches()
+        if not branches.is_empty():
+            search_url = canonical_url(
+                account, rootsite='code', view_name='+branches')
+            req = PreparedRequest()
+            req.prepare_url(search_url, {
+                "field.category": "OWNED",
+                "field.category-empty-marker": "1",
+                "field.lifecycle": "ALL",
+                "field.lifecycle-empty-marker": "1",
+                "field.sort_by": "most recently changed first",
+                "field.sort_by-empty-marker": "1"})
+            return_data['branches'] = req.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:
+            return_data["status"] = "account with data"
+        else:
+            return_data["status"] = "account only; no other data"
         return return_data
 
     def getUserOverview(self, person):
diff --git a/lib/lp/registry/tests/test_personset.py b/lib/lp/registry/tests/test_personset.py
index 3c64306..8b6bafb 100644
--- a/lib/lp/registry/tests/test_personset.py
+++ b/lib/lp/registry/tests/test_personset.py
@@ -7,6 +7,8 @@ __metaclass__ = type
 
 
 from testtools.matchers import (
+    Contains,
+    ContainsDict,
     Equals,
     GreaterThan,
     LessThan,
@@ -1222,6 +1224,18 @@ class TestGDPRUserRetrieval(TestCaseWithFactory):
             "person": canonical_url(person)},
             result)
 
+    def test_account_data_branches(self):
+        person = self.factory.makePerson(email="test@xxxxxxxxxxx")
+        self.factory.makeBranch(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)),
+            "branches": Contains(
+                canonical_url(
+                    person, rootsite="code", view_name="+branches"))}))
+
     def test_getUserOverview(self):
         ppa = self.factory.makeArchive(owner=self.user)
 

Follow ups