launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #27301
[Merge] ~twom/launchpad:gdbpr-add-gpg-key-info into launchpad:master
Tom Wardill has proposed merging ~twom/launchpad:gdbpr-add-gpg-key-info into launchpad:master.
Commit message:
Add PGP/GPG key info to GDPR endpoint
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~twom/launchpad/+git/launchpad/+merge/406092
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:gdbpr-add-gpg-key-info into launchpad:master.
diff --git a/lib/lp/registry/model/person.py b/lib/lp/registry/model/person.py
index f9d911e..4c8d4be 100644
--- a/lib/lp/registry/model/person.py
+++ b/lib/lp/registry/model/person.py
@@ -4123,6 +4123,9 @@ class PersonSet:
questions_url = self._checkForAnswers(account)
if questions_url:
return_data["answers"] = questions_url
+ gpg_keys_url = self._checkForGPGKeys(account)
+ if gpg_keys_url:
+ return_data["openpgp-keys"] = gpg_keys_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:
@@ -4224,6 +4227,22 @@ class PersonSet:
req.prepare_url(answers_url, query_arguments)
return req.url
+ def _checkForGPGKeys(self, account):
+ """Check if we have GPG keys for the given Person."""
+ # We return the keyserver url, not an LP url
+ urls = []
+ keyserver_url = "https://keyserver.ubuntu.com/pks/lookup"
+ keys = account.gpg_keys + account.inactive_gpg_keys
+ for key in keys:
+ req = PreparedRequest()
+ query_arguments = {
+ "fingerprint": "on",
+ "op": "index",
+ "search": "0x{}".format(key.fingerprint)}
+ req.prepare_url(keyserver_url, query_arguments)
+ urls.append(req.url)
+ return urls
+
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 9c7d308..1ac2229 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 (
GreaterThan,
LessThan,
MatchesDict,
+ MatchesListwise,
)
import transaction
from zope.component import getUtility
@@ -1356,6 +1357,29 @@ class TestGDPRUserRetrieval(TestCaseWithFactory):
canonical_url(
person, rootsite="answers"))}))
+ def test_account_data_gpg_keys(self):
+ person = self.factory.makePerson(email="test@xxxxxxxxxxx")
+ with admin_logged_in():
+ self.factory.makeGPGKey(person)
+ result = self.person_set.getUserData(u"test@xxxxxxxxxxx")
+ self.assertThat(result, ContainsDict({
+ "status": Equals("account with data"),
+ "person": Equals(canonical_url(person)),
+ "openpgp-keys": MatchesListwise([
+ Contains("https://keyserver.ubuntu.com")])}))
+
+ def test_account_data_gpg_keys_inactive(self):
+ person = self.factory.makePerson(email="test@xxxxxxxxxxx")
+ with admin_logged_in():
+ key = self.factory.makeGPGKey(person)
+ key.active = False
+ result = self.person_set.getUserData(u"test@xxxxxxxxxxx")
+ self.assertThat(result, ContainsDict({
+ "status": Equals("account with data"),
+ "person": Equals(canonical_url(person)),
+ "openpgp-keys": MatchesListwise([
+ Contains("https://keyserver.ubuntu.com")])}))
+
def test_getUserOverview(self):
ppa = self.factory.makeArchive(owner=self.user)