Merge lp:~jcsackett/launchpad/affects-before-bug-email into lp:launchpad

Proposed by j.c.sackett
Status: Merged
Approved by: j.c.sackett
Approved revision: no longer in the source branch.
Merged at revision: 12684
Proposed branch: lp:~jcsackett/launchpad/affects-before-bug-email
Merge into: lp:launchpad
Diff against target: 115 lines (+64/-11)
3 files modified
lib/canonical/launchpad/mail/commands.py (+10/-0)
lib/canonical/launchpad/mail/errortemplates/command-with-no-bug.txt (+8/-0)
lib/lp/bugs/tests/bugs-emailinterface.txt (+46/-11)
To merge this branch: bzr merge lp:~jcsackett/launchpad/affects-before-bug-email
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+55184@code.launchpad.net

Commit message

[r=benji][bug=83426] Adds error handling for edit emails that specify changes without specifying bugs

Description of the change

Summary
=======
Emails sent to edit@ without specifying a bug cause an oops; this branch adds apporpriate error handling to the handler for that instance.

Proposed Fix
============
Capture emails that specify commands without a bug; halt processing and send a message to the user explaining the problem with their email.

Implementation
==============
lib/canonical/launchpad/mail/commands.py
lib/canonical/launchpad/mail/errortemplates/command-with-no-bug.txt
-------------------------------------------------------------------
Added error handling for commands issued with no associated bug.

lib/lp/bugs/tests/bug-emailinterface.txt
----------------------------------------
Added example case for testing.

Tests
=====
bin/test -vvct bug-emailinterface.txt

Demo & QA
=========
Send an email that invokes "affects" or "summary" without specifying a bug. No OOPs should result, and you should receive an email that explains you screwed up and how to fix it.

Lint
====
make lint output:

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/canonical/launchpad/mail/commands.py
  lib/canonical/launchpad/mail/errortemplates/command-with-no-bug.txt
  lib/lp/bugs/tests/bugs-emailinterface.txt

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

Looks good.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/mail/commands.py'
2--- lib/canonical/launchpad/mail/commands.py 2011-03-23 16:28:51 +0000
3+++ lib/canonical/launchpad/mail/commands.py 2011-03-28 17:34:49 +0000
4@@ -423,6 +423,11 @@
5
6 def execute(self, bug, current_event):
7 """See IEmailCommand."""
8+ if bug is None:
9+ raise EmailProcessingError(
10+ get_error_message('command-with-no-bug.txt'),
11+ stop_processing=True)
12+
13 # Do a manual control of the number of arguments, in order to
14 # provide a better error message than the default one.
15 if len(self.string_args) > 1:
16@@ -612,6 +617,11 @@
17
18 def execute(self, bug):
19 """See IEmailCommand."""
20+ if bug is None:
21+ raise EmailProcessingError(
22+ get_error_message('command-with-no-bug.txt'),
23+ stop_processing=True)
24+
25 string_args = list(self.string_args)
26 try:
27 path = string_args.pop(0)
28
29=== added file 'lib/canonical/launchpad/mail/errortemplates/command-with-no-bug.txt'
30--- lib/canonical/launchpad/mail/errortemplates/command-with-no-bug.txt 1970-01-01 00:00:00 +0000
31+++ lib/canonical/launchpad/mail/errortemplates/command-with-no-bug.txt 2011-03-28 17:34:49 +0000
32@@ -0,0 +1,8 @@
33+The message you sent included commands to modify a bug,
34+but no bug was specified. Please supply a bug before the command
35+to modify it.
36+
37+For example:
38+
39+ bug 4
40+ summary "This is a new summary"
41
42=== modified file 'lib/lp/bugs/tests/bugs-emailinterface.txt'
43--- lib/lp/bugs/tests/bugs-emailinterface.txt 2011-03-23 16:28:51 +0000
44+++ lib/lp/bugs/tests/bugs-emailinterface.txt 2011-03-28 17:34:49 +0000
45@@ -331,6 +331,52 @@
46 >>> print bug_five.title
47 Nicer summary
48
49+The email handler requires that a bug be specified to be changed. If no
50+bug is specified, no edits occur and a message is sent to the user telling
51+them what happened.
52+
53+ >>> edit_mail = """From: test@canonical.com
54+ ... To: edit@malone-domain
55+ ... Date: Fri Jun 17 10:10:23 BST 2005
56+ ... Subject: Not important
57+ ...
58+ ... summary "Even nicer summary"
59+ ... """
60+
61+ >>> process_email(edit_mail)
62+ >>> commit()
63+
64+This time, neither bug four or five were updated.
65+
66+ >>> print bug_four.title
67+ Changed summary
68+ >>> print bug_five.title
69+ Nicer summary
70+
71+And the person sending the email has received an error message.
72+
73+ >>> def print_latest_email():
74+ ... commit()
75+ ... if not stub.test_emails:
76+ ... raise AssertionError("No emails queued!")
77+ ... from_addr, to_addrs, raw_message = stub.test_emails[-1]
78+ ... sent_msg = email.message_from_string(raw_message)
79+ ... error_mail, original_mail = sent_msg.get_payload()
80+ ... print "Subject: %s" % sent_msg['Subject']
81+ ... print "To: %s" % ', '.join(to_addrs)
82+ ... print
83+ ... print error_mail.get_payload(decode=True)
84+
85+ >>> print_latest_email()
86+ Subject: Submit Request Failure
87+ To: test@canonical.com
88+ <BLANKLINE>
89+ ...
90+ The message you sent included commands to modify a bug,
91+ but no bug was specified. Please supply a bug before the command
92+ to modify it.
93+ <BLANKLINE>
94+ ...
95
96 GPG signing and adding comments
97 -------------------------------
98@@ -397,17 +443,6 @@
99 And an error message was sent to the Sample Person, telling him what's
100 wrong.
101
102- >>> def print_latest_email():
103- ... commit()
104- ... if not stub.test_emails:
105- ... raise AssertionError("No emails queued!")
106- ... from_addr, to_addrs, raw_message = stub.test_emails[-1]
107- ... sent_msg = email.message_from_string(raw_message)
108- ... error_mail, original_mail = sent_msg.get_payload()
109- ... print "Subject: %s" % sent_msg['Subject']
110- ... print "To: %s" % ', '.join(to_addrs)
111- ... print
112- ... print error_mail.get_payload(decode=True)
113 >>> print_latest_email()
114 Subject: Submit Request Failure
115 To: test@canonical.com