launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #27581
[Merge] ~jugmac00/launchpad:add-username-for-oauth-generation-notification into launchpad:master
jugmac00 has proposed merging ~jugmac00/launchpad:add-username-for-oauth-generation-notification into launchpad:master.
Commit message:
Add username to OAuth generation notification
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #1939050 in Launchpad itself: "OAuth token generation email missing username"
https://bugs.launchpad.net/launchpad/+bug/1939050
For more details, see:
https://code.launchpad.net/~jugmac00/launchpad/+git/launchpad/+merge/409917
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~jugmac00/launchpad:add-username-for-oauth-generation-notification into launchpad:master.
diff --git a/lib/lp/services/oauth/model.py b/lib/lp/services/oauth/model.py
index 469cbad..ffe6b00 100644
--- a/lib/lp/services/oauth/model.py
+++ b/lib/lp/services/oauth/model.py
@@ -394,9 +394,13 @@ class OAuthRequestToken(OAuthBase, StormBase):
# We want to notify the user that this oauth token has been generated
# for them for security reasons.
+ subject = (
+ "OAuth token generated for user %s in Launchpad"
+ % self.person.name
+ )
self.person.security_field_changed(
- "OAuth token generated in Launchpad",
- "A new OAuth token consumer was enabled in Launchpad.")
+ subject, "A new OAuth token consumer was enabled in Launchpad."
+ )
self._getStore().remove(self)
return access_token, secret
diff --git a/lib/lp/services/oauth/tests/test_tokens.py b/lib/lp/services/oauth/tests/test_tokens.py
index c683786..635e1f2 100644
--- a/lib/lp/services/oauth/tests/test_tokens.py
+++ b/lib/lp/services/oauth/tests/test_tokens.py
@@ -38,6 +38,7 @@ from lp.testing import (
verifyObject,
)
from lp.testing.layers import DatabaseFunctionalLayer
+from lp.testing.mail_helpers import pop_notifications
class TestOAuth(TestCaseWithFactory):
@@ -379,6 +380,18 @@ class TestAccessTokens(TestOAuth):
access_token.date_expires = self.a_long_time_ago
self.assertEqual(person.oauth_access_tokens.count(), 0)
+ def test_email_notification_message_for_generated_tokens(self):
+ token = self.factory.makeOAuthRequestToken(
+ reviewed_by=self.person,
+ )
+ token.createAccessToken()
+ notifications = pop_notifications()
+
+ self.assertEqual(
+ notifications[0]['subject'],
+ 'OAuth token generated for user person-name-100018 in Launchpad'
+ )
+
class TestHelperFunctions(TestOAuth):