← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~twom/launchpad:gdpr-add-bug-information into launchpad:master

 

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

Commit message:
Add bug url to GDPR output

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~twom/launchpad/+git/launchpad/+merge/405832
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:gdpr-add-bug-information into launchpad:master.
diff --git a/lib/lp/registry/model/person.py b/lib/lp/registry/model/person.py
index ca46ede..50d34d7 100644
--- a/lib/lp/registry/model/person.py
+++ b/lib/lp/registry/model/person.py
@@ -136,7 +136,10 @@ from lp.blueprints.model.specificationsearch import (
     )
 from lp.blueprints.model.specificationworkitem import SpecificationWorkItem
 from lp.bugs.interfaces.bugtarget import IBugTarget
-from lp.bugs.interfaces.bugtask import IBugTaskSet
+from lp.bugs.interfaces.bugtask import (
+    BugTaskStatus,
+    IBugTaskSet,
+    )
 from lp.bugs.interfaces.bugtasksearch import (
     BugTaskSearchParams,
     get_person_bugtasks_search_params,
@@ -4100,6 +4103,10 @@ class PersonSet:
         git_url = self._checkForGitRepositoryData(account)
         if git_url:
             return_data["git-repositories"] = git_url
+        # bugs
+        bug_url = self._checkForBugs(account)
+        if bug_url:
+            return_data["bugs"] = bug_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:
@@ -4132,6 +4139,33 @@ class PersonSet:
             return None
         return canonical_url(account, rootsite='code', view_name='+git')
 
+    def _checkForBugs(self, account):
+        """Check if related bug data exists for a given person."""
+        search_params = BugTaskSearchParams(user=account)
+        if account.searchTasks(search_params).is_empty():
+            return None
+        req = PreparedRequest()
+        bugs_url = canonical_url(account, rootsite="bugs")
+        query_arguments = {
+            "field.searchtext": "",
+            "orderby": "-importance",
+            "field.omit_dupes.used": ""
+        }
+        status_list = []
+        for status in BugTaskStatus:
+            if status.token == "INCOMPLETE":
+                # This isn't a UI value anymore, so add the correct variants
+                status_list.append("INCOMPLETE_WITHOUT_RESPONSE")
+                status_list.append("INCOMPLETE_WITH_RESPONSE")
+            elif status.token == "UNKNOWN":
+                # This isn't valid in the UI list
+                continue
+            else:
+                status_list.append(status.token)
+        query_arguments["field.status:list"] = status_list
+        req.prepare_url(bugs_url, query_arguments)
+        return req.url
+
     def getUserOverview(self, person):
         """See `IPersonSet`."""
         overview = {}
diff --git a/lib/lp/registry/tests/test_personset.py b/lib/lp/registry/tests/test_personset.py
index 04f28cb..99c8332 100644
--- a/lib/lp/registry/tests/test_personset.py
+++ b/lib/lp/registry/tests/test_personset.py
@@ -1261,6 +1261,19 @@ class TestGDPRUserRetrieval(TestCaseWithFactory):
             "person": canonical_url(person)},
             result)
 
+    def test_account_data_bugs(self):
+        person = self.factory.makePerson(email="test@xxxxxxxxxxx")
+        self.factory.makeBug(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)),
+            "bugs": Contains(
+                canonical_url(
+                    person, rootsite="bugs"))}))
+        self.assertIn("field.searchtext", result["bugs"])
+
     def test_getUserOverview(self):
         ppa = self.factory.makeArchive(owner=self.user)