Merge lp:~cjwatson/launchpad/mail-handle-me into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 17737
Proposed branch: lp:~cjwatson/launchpad/mail-handle-me
Merge into: lp:launchpad
Diff against target: 74 lines (+25/-2)
3 files modified
lib/lp/bugs/tests/bugs-emailinterface.txt (+8/-0)
lib/lp/services/mail/helpers.py (+5/-0)
lib/lp/services/mail/tests/test_helpers.py (+12/-2)
To merge this branch: bzr merge lp:~cjwatson/launchpad/mail-handle-me
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+270853@code.launchpad.net

Commit message

Treat "me" in person-or-team contexts in mail handlers as the current user.

Description of the change

Treat "me" in person-or-team contexts in mail handlers as the current user.

"me" is already reserved on production by +nameblacklist, so this is safe from clashes.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/tests/bugs-emailinterface.txt'
2--- lib/lp/bugs/tests/bugs-emailinterface.txt 2015-07-21 09:04:01 +0000
3+++ lib/lp/bugs/tests/bugs-emailinterface.txt 2015-09-11 16:35:55 +0000
4@@ -1197,6 +1197,14 @@
5 >>> debian_task.assignee is None
6 True
7
8+Also like the web UI, we can assign a bug to "me", the current user.
9+
10+ >>> submit_commands(
11+ ... bug_four, 'affects debian',
12+ ... 'assignee me')
13+ >>> debian_task.assignee.name
14+ u'name12'
15+
16 To set which source package the bug affects, we use:
17
18 >>> submit_commands(bug_four, 'affects debian/mozilla-firefox')
19
20=== modified file 'lib/lp/services/mail/helpers.py'
21--- lib/lp/services/mail/helpers.py 2015-07-10 15:30:28 +0000
22+++ lib/lp/services/mail/helpers.py 2015-09-11 16:35:55 +0000
23@@ -161,6 +161,11 @@
24 """
25 # Avoid circular import problems.
26 from lp.registry.vocabularies import ValidPersonOrTeamVocabulary
27+
28+ # "me" is a special case meaning the sender of the email.
29+ if person_name_or_email == "me":
30+ return getUtility(ILaunchBag).user
31+
32 valid_person_vocabulary = ValidPersonOrTeamVocabulary()
33 try:
34 person_term = valid_person_vocabulary.getTermByToken(
35
36=== modified file 'lib/lp/services/mail/tests/test_helpers.py'
37--- lib/lp/services/mail/tests/test_helpers.py 2012-09-27 20:45:31 +0000
38+++ lib/lp/services/mail/tests/test_helpers.py 2015-09-11 16:35:55 +0000
39@@ -1,4 +1,4 @@
40-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
41+# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
42 # GNU Affero General Public License version 3 (see the file LICENSE).
43
44 __metaclass__ = type
45@@ -7,12 +7,16 @@
46 import time
47 import unittest
48
49+from zope.component import getUtility
50 from zope.interface import (
51 directlyProvidedBy,
52 directlyProvides,
53 )
54
55-from lp.registry.interfaces.person import PersonVisibility
56+from lp.registry.interfaces.person import (
57+ IPersonSet,
58+ PersonVisibility,
59+ )
60 from lp.services.mail.helpers import (
61 ensure_not_weakly_authenticated,
62 ensure_sane_signature_timestamp,
63@@ -239,6 +243,12 @@
64 self.assertEqual(
65 team, get_person_or_team('fooix-devs@lists.example.com'))
66
67+ def test_me(self):
68+ # The special case of "me" refers to the logged-in user, that is,
69+ # the user who sent the email being processed.
70+ me = getUtility(IPersonSet).getByEmail('test@canonical.com')
71+ self.assertEqual(me, get_person_or_team('me'))
72+
73
74 class Testget_contact_email_addresses(TestCaseWithFactory):
75