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

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: 47a7dd994e349b36c1ba6e5b59ed6e009e75353d
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:gdpr-add-git-info
Merge into: launchpad:master
Diff against target: 71 lines (+36/-0)
2 files modified
lib/lp/registry/model/person.py (+11/-0)
lib/lp/registry/tests/test_personset.py (+25/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Cristian Gonzalez (community) Approve
Review via email: mp+405742@code.launchpad.net

Commit message

Add git repository output to GDPR endpoint

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

Added a little comment, but as side from that looks ok.

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 1602f4b..ca46ede 100644
3--- a/lib/lp/registry/model/person.py
4+++ b/lib/lp/registry/model/person.py
5@@ -144,6 +144,7 @@ from lp.bugs.interfaces.bugtasksearch import (
6 from lp.bugs.model.bugtarget import HasBugsBase
7 from lp.bugs.model.structuralsubscription import StructuralSubscription
8 from lp.code.interfaces.branchcollection import IAllBranches
9+from lp.code.interfaces.gitcollection import IGitCollection
10 from lp.code.model.hasbranches import (
11 HasBranchesMixin,
12 HasMergeProposalsMixin,
13@@ -4095,6 +4096,10 @@ class PersonSet:
14 branches_url = self._checkForBranchData(account)
15 if branches_url:
16 return_data["branches"] = branches_url
17+ # Git repositories
18+ git_url = self._checkForGitRepositoryData(account)
19+ if git_url:
20+ return_data["git-repositories"] = git_url
21 # This is only an 'account' in terms of the end user view,
22 # it does not refer to an `IAccount`.
23 if len(return_data.keys()) > 1:
24@@ -4120,6 +4125,12 @@ class PersonSet:
25 "field.sort_by-empty-marker": "1"})
26 return req.url
27
28+ def _checkForGitRepositoryData(self, account):
29+ """Check if git repositories exist for a given person."""
30+ repositories = IGitCollection(account).visibleByUser(account)
31+ if repositories.is_empty():
32+ return None
33+ return canonical_url(account, rootsite='code', view_name='+git')
34
35 def getUserOverview(self, person):
36 """See `IPersonSet`."""
37diff --git a/lib/lp/registry/tests/test_personset.py b/lib/lp/registry/tests/test_personset.py
38index 8b6bafb..04f28cb 100644
39--- a/lib/lp/registry/tests/test_personset.py
40+++ b/lib/lp/registry/tests/test_personset.py
41@@ -1236,6 +1236,31 @@ class TestGDPRUserRetrieval(TestCaseWithFactory):
42 canonical_url(
43 person, rootsite="code", view_name="+branches"))}))
44
45+ def test_account_data_repositories(self):
46+ person = self.factory.makePerson(email="test@example.com")
47+ self.factory.makeGitRepository(owner=person)
48+ with admin_logged_in():
49+ result = self.person_set.getUserData(u"test@example.com")
50+ self.assertDictEqual({
51+ "status": "account with data",
52+ "person": canonical_url(person),
53+ "git-repositories": canonical_url(
54+ person, rootsite="code", view_name="+git")},
55+ result)
56+
57+ def test_account_data_repositories_other_owners(self):
58+ # Check that we only report on repositories that
59+ # we care about
60+ person = self.factory.makePerson(email="test@example.com")
61+ other_person = self.factory.makePerson(email="other@example.com")
62+ self.factory.makeGitRepository(owner=other_person)
63+ with admin_logged_in():
64+ result = self.person_set.getUserData(u"test@example.com")
65+ self.assertDictEqual({
66+ "status": "account only; no other data",
67+ "person": canonical_url(person)},
68+ result)
69+
70 def test_getUserOverview(self):
71 ppa = self.factory.makeArchive(owner=self.user)
72

Subscribers

People subscribed via source and target branches

to status/vote changes: