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

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: 22677a14202fab15523c16fbec2eeab8ed8a673b
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:gdbr-add-bzr-branches
Merge into: launchpad:master
Diff against target: 89 lines (+45/-3)
2 files modified
lib/lp/registry/model/person.py (+31/-3)
lib/lp/registry/tests/test_personset.py (+14/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Cristian Gonzalez (community) Approve
Review via email: mp+405703@code.launchpad.net

Commit message

Add bzr branch output to GDPR data retrieval

To post a comment you must log in.
Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Little refactor suggested.

Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Looks good!

review: Approve
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/registry/model/person.py b/lib/lp/registry/model/person.py
2index edac8e9..1602f4b 100644
3--- a/lib/lp/registry/model/person.py
4+++ b/lib/lp/registry/model/person.py
5@@ -44,6 +44,7 @@ from lazr.restful.utils import (
6 smartquote,
7 )
8 import pytz
9+from requests import PreparedRequest
10 import six
11 from sqlobject import (
12 BoolCol,
13@@ -4084,15 +4085,42 @@ class PersonSet:
14 return {"status": "no data held"}
15
16 account = email_results.one()[1]
17- # This is only an 'account' in terms of the end user view,
18- # it does not refer to an `IAccount`.
19- return_data = {"status": "account only; no other data"}
20+ return_data = {}
21 return_data["person"] = canonical_url(account)
22 # Get the data behind the overview screen
23 overview = self.getUserOverview(account)
24 return_data.update(overview)
25+
26+ # bzr branches
27+ branches_url = self._checkForBranchData(account)
28+ if branches_url:
29+ return_data["branches"] = branches_url
30+ # This is only an 'account' in terms of the end user view,
31+ # it does not refer to an `IAccount`.
32+ if len(return_data.keys()) > 1:
33+ return_data["status"] = "account with data"
34+ else:
35+ return_data["status"] = "account only; no other data"
36 return return_data
37
38+ def _checkForBranchData(self, account):
39+ """Check if bzr branches exist for a given person."""
40+ branches = account.getBranches()
41+ if branches.is_empty():
42+ return None
43+ search_url = canonical_url(
44+ account, rootsite='code', view_name='+branches')
45+ req = PreparedRequest()
46+ req.prepare_url(search_url, {
47+ "field.category": "OWNED",
48+ "field.category-empty-marker": "1",
49+ "field.lifecycle": "ALL",
50+ "field.lifecycle-empty-marker": "1",
51+ "field.sort_by": "most recently changed first",
52+ "field.sort_by-empty-marker": "1"})
53+ return req.url
54+
55+
56 def getUserOverview(self, person):
57 """See `IPersonSet`."""
58 overview = {}
59diff --git a/lib/lp/registry/tests/test_personset.py b/lib/lp/registry/tests/test_personset.py
60index 3c64306..8b6bafb 100644
61--- a/lib/lp/registry/tests/test_personset.py
62+++ b/lib/lp/registry/tests/test_personset.py
63@@ -7,6 +7,8 @@ __metaclass__ = type
64
65
66 from testtools.matchers import (
67+ Contains,
68+ ContainsDict,
69 Equals,
70 GreaterThan,
71 LessThan,
72@@ -1222,6 +1224,18 @@ class TestGDPRUserRetrieval(TestCaseWithFactory):
73 "person": canonical_url(person)},
74 result)
75
76+ def test_account_data_branches(self):
77+ person = self.factory.makePerson(email="test@example.com")
78+ self.factory.makeBranch(owner=person)
79+ with admin_logged_in():
80+ result = self.person_set.getUserData(u"test@example.com")
81+ self.assertThat(result, ContainsDict({
82+ "status": Equals("account with data"),
83+ "person": Equals(canonical_url(person)),
84+ "branches": Contains(
85+ canonical_url(
86+ person, rootsite="code", view_name="+branches"))}))
87+
88 def test_getUserOverview(self):
89 ppa = self.factory.makeArchive(owner=self.user)
90

Subscribers

People subscribed via source and target branches

to status/vote changes: