Merge ~jugmac00/launchpad:add-username-for-oauth-generation-notification into launchpad:master

Proposed by Jürgen Gmach
Status: Merged
Approved by: Jürgen Gmach
Approved revision: 3abd52da35f3f717b39eeadf1db2b8665a1bd169
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~jugmac00/launchpad:add-username-for-oauth-generation-notification
Merge into: launchpad:master
Diff against target: 49 lines (+18/-2)
2 files modified
lib/lp/services/oauth/model.py (+5/-2)
lib/lp/services/oauth/tests/test_tokens.py (+13/-0)
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Colin Watson (community) Approve
Review via email: mp+409917@code.launchpad.net

Commit message

Add username to OAuth generation notification

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

Looks good, little comment about the test.

review: Needs Fixing
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
Colin Watson (cjwatson) :
Revision history for this message
Jürgen Gmach (jugmac00) wrote :

Thank you for the review! I applied all the suggested changes.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/services/oauth/model.py b/lib/lp/services/oauth/model.py
2index 469cbad..c7b44ad 100644
3--- a/lib/lp/services/oauth/model.py
4+++ b/lib/lp/services/oauth/model.py
5@@ -394,9 +394,12 @@ class OAuthRequestToken(OAuthBase, StormBase):
6
7 # We want to notify the user that this oauth token has been generated
8 # for them for security reasons.
9+ subject = (
10+ 'OAuth token generated for %s in Launchpad' % self.person.name
11+ )
12 self.person.security_field_changed(
13- "OAuth token generated in Launchpad",
14- "A new OAuth token consumer was enabled in Launchpad.")
15+ subject, 'A new OAuth token consumer was enabled in Launchpad.'
16+ )
17
18 self._getStore().remove(self)
19 return access_token, secret
20diff --git a/lib/lp/services/oauth/tests/test_tokens.py b/lib/lp/services/oauth/tests/test_tokens.py
21index c683786..d36f125 100644
22--- a/lib/lp/services/oauth/tests/test_tokens.py
23+++ b/lib/lp/services/oauth/tests/test_tokens.py
24@@ -38,6 +38,7 @@ from lp.testing import (
25 verifyObject,
26 )
27 from lp.testing.layers import DatabaseFunctionalLayer
28+from lp.testing.mail_helpers import pop_notifications
29
30
31 class TestOAuth(TestCaseWithFactory):
32@@ -379,6 +380,18 @@ class TestAccessTokens(TestOAuth):
33 access_token.date_expires = self.a_long_time_ago
34 self.assertEqual(person.oauth_access_tokens.count(), 0)
35
36+ def test_email_notification_message_for_generated_tokens(self):
37+ token = self.factory.makeOAuthRequestToken(
38+ reviewed_by=self.person,
39+ )
40+ token.createAccessToken()
41+ notifications = pop_notifications()
42+
43+ expected = (
44+ 'OAuth token generated for %s in Launchpad' % self.person.name
45+ )
46+ self.assertEqual(expected, notifications[0]['subject'])
47+
48
49 class TestHelperFunctions(TestOAuth):
50

Subscribers

People subscribed via source and target branches

to status/vote changes: