Merge ~twom/launchpad:gdbpr-add-gpg-key-info into launchpad:master

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: cfcd47acd2831c20e7d70bf73ef13ae549f9e7ac
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:gdbpr-add-gpg-key-info
Merge into: launchpad:master
Diff against target: 78 lines (+43/-0)
2 files modified
lib/lp/registry/model/person.py (+19/-0)
lib/lp/registry/tests/test_personset.py (+24/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+406092@code.launchpad.net

Commit message

Add PGP/GPG key info to GDPR endpoint

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/lib/lp/registry/model/person.py b/lib/lp/registry/model/person.py
index c669daf..70a7933 100644
--- a/lib/lp/registry/model/person.py
+++ b/lib/lp/registry/model/person.py
@@ -4127,6 +4127,9 @@ class PersonSet:
4127 if not account.sshkeys.is_empty():4127 if not account.sshkeys.is_empty():
4128 return_data["sshkeys"] = canonical_url(4128 return_data["sshkeys"] = canonical_url(
4129 account, view_name="+sshkeys")4129 account, view_name="+sshkeys")
4130 gpg_keys_urls = self._checkForGPGKeys(account)
4131 if gpg_keys_urls:
4132 return_data["openpgp-keys"] = gpg_keys_urls
4130 # This is only an 'account' in terms of the end user view,4133 # This is only an 'account' in terms of the end user view,
4131 # it does not refer to an `IAccount`.4134 # it does not refer to an `IAccount`.
4132 if len(return_data.keys()) > 1:4135 if len(return_data.keys()) > 1:
@@ -4228,6 +4231,22 @@ class PersonSet:
4228 req.prepare_url(answers_url, query_arguments)4231 req.prepare_url(answers_url, query_arguments)
4229 return req.url4232 return req.url
42304233
4234 def _checkForGPGKeys(self, account):
4235 """Check if we have GPG keys for the given Person."""
4236 # We return the keyserver url, not an LP url
4237 urls = []
4238 keyserver_url = "https://keyserver.ubuntu.com/pks/lookup"
4239 keys = account.gpg_keys + account.inactive_gpg_keys
4240 for key in keys:
4241 req = PreparedRequest()
4242 query_arguments = {
4243 "fingerprint": "on",
4244 "op": "index",
4245 "search": "0x{}".format(key.fingerprint)}
4246 req.prepare_url(keyserver_url, query_arguments)
4247 urls.append(req.url)
4248 return urls
4249
4231 def getUserOverview(self, person):4250 def getUserOverview(self, person):
4232 """See `IPersonSet`."""4251 """See `IPersonSet`."""
4233 overview = {}4252 overview = {}
diff --git a/lib/lp/registry/tests/test_personset.py b/lib/lp/registry/tests/test_personset.py
index cee7182..9bf188f 100644
--- a/lib/lp/registry/tests/test_personset.py
+++ b/lib/lp/registry/tests/test_personset.py
@@ -13,6 +13,7 @@ from testtools.matchers import (
13 GreaterThan,13 GreaterThan,
14 LessThan,14 LessThan,
15 MatchesDict,15 MatchesDict,
16 MatchesListwise,
16 )17 )
17import transaction18import transaction
18from zope.component import getUtility19from zope.component import getUtility
@@ -1367,6 +1368,29 @@ class TestGDPRUserRetrieval(TestCaseWithFactory):
1367 "sshkeys": canonical_url(person, view_name="+sshkeys")1368 "sshkeys": canonical_url(person, view_name="+sshkeys")
1368 }, result)1369 }, result)
13691370
1371 def test_account_data_gpg_keys(self):
1372 person = self.factory.makePerson(email="test@example.com")
1373 with admin_logged_in():
1374 self.factory.makeGPGKey(person)
1375 result = self.person_set.getUserData(u"test@example.com")
1376 self.assertThat(result, ContainsDict({
1377 "status": Equals("account with data"),
1378 "person": Equals(canonical_url(person)),
1379 "openpgp-keys": MatchesListwise([
1380 Contains("https://keyserver.ubuntu.com")])}))
1381
1382 def test_account_data_gpg_keys_inactive(self):
1383 person = self.factory.makePerson(email="test@example.com")
1384 with admin_logged_in():
1385 key = self.factory.makeGPGKey(person)
1386 key.active = False
1387 result = self.person_set.getUserData(u"test@example.com")
1388 self.assertThat(result, ContainsDict({
1389 "status": Equals("account with data"),
1390 "person": Equals(canonical_url(person)),
1391 "openpgp-keys": MatchesListwise([
1392 Contains("https://keyserver.ubuntu.com")])}))
1393
1370 def test_getUserOverview(self):1394 def test_getUserOverview(self):
1371 ppa = self.factory.makeArchive(owner=self.user)1395 ppa = self.factory.makeArchive(owner=self.user)
13721396

Subscribers

People subscribed via source and target branches

to status/vote changes: