Merge lp:~stevenk/launchpad/bugs-information_type-mail into lp:launchpad

Proposed by Steve Kowalik on 2012-05-03
Status: Merged
Approved by: William Grant on 2012-05-04
Approved revision: no longer in the source branch.
Merged at revision: 15201
Proposed branch: lp:~stevenk/launchpad/bugs-information_type-mail
Merge into: lp:launchpad
Diff against target: 148 lines (+96/-0)
3 files modified
lib/lp/bugs/mail/commands.py (+26/-0)
lib/lp/bugs/mail/tests/test_commands.py (+52/-0)
lib/lp/bugs/mail/tests/test_handler.py (+18/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/bugs-information_type-mail
Reviewer Review Type Date Requested Status
William Grant code 2012-05-03 Approve on 2012-05-04
Review via email: mp+104483@code.launchpad.net

Commit Message

Add support for an 'informationtype' mail command.

Description of the Change

Add support for an 'informationtype' mail command. I have not touched the existing private and security commands, or their tests. I have also not implemented warning of deprecation for either of them, since that requires a little more investigation.

As it stands, I accept the lowercased names of the InformationType enum, which is the same behaviour as 'status'. I have explicitly forbidden Proprietary for the moment, since the rules around when to allow it are still ... mushy.

To post a comment you must log in.
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/mail/commands.py'
2--- lib/lp/bugs/mail/commands.py 2012-03-29 00:48:21 +0000
3+++ lib/lp/bugs/mail/commands.py 2012-05-04 00:07:23 +0000
4@@ -814,6 +814,31 @@
5 return {self.name: dbitem}
6
7
8+class InformationTypeEmailCommand(DBSchemaEditEmailCommand):
9+ """Change the information type of a bug."""
10+
11+ implements(IBugEditEmailCommand)
12+ dbschema = InformationType
13+ RANK = 3
14+
15+ def convertArguments(self, context):
16+ args = super(InformationTypeEmailCommand, self).convertArguments(
17+ context)
18+ return {'information_type': args['informationtype']}
19+
20+ def setAttributeValue(self, context, attr_name, attr_value):
21+ """See EmailCommand."""
22+ user = getUtility(ILaunchBag).user
23+ if attr_value == InformationType.PROPRIETARY:
24+ raise EmailProcessingError(
25+ 'Proprietary bugs are forbidden to be filed via the mail '
26+ 'interface.')
27+ if isinstance(context, CreateBugParams):
28+ context.information_type = attr_value
29+ else:
30+ context.transitionToInformationType(attr_value, user)
31+
32+
33 class StatusEmailCommand(DBSchemaEditEmailCommand):
34 """Changes a bug task's status."""
35 dbschema = BugTaskStatus
36@@ -901,6 +926,7 @@
37
38 _commands = {
39 'bug': BugEmailCommand,
40+ 'informationtype': InformationTypeEmailCommand,
41 'private': PrivateEmailCommand,
42 'security': SecurityEmailCommand,
43 'summary': SummaryEmailCommand,
44
45=== modified file 'lib/lp/bugs/mail/tests/test_commands.py'
46--- lib/lp/bugs/mail/tests/test_commands.py 2012-04-03 06:14:09 +0000
47+++ lib/lp/bugs/mail/tests/test_commands.py 2012-05-04 00:07:23 +0000
48@@ -12,6 +12,7 @@
49 BugEmailCommand,
50 CVEEmailCommand,
51 DuplicateEmailCommand,
52+ InformationTypeEmailCommand,
53 PrivateEmailCommand,
54 SecurityEmailCommand,
55 SubscribeEmailCommand,
56@@ -412,6 +413,57 @@
57 self.assertEqual(dummy_event, event)
58
59
60+class InformationTypeEmailCommandTestCase(TestCaseWithFactory):
61+
62+ layer = DatabaseFunctionalLayer
63+
64+ def test_execute_bug_params(self):
65+ user = self.factory.makePerson()
66+ login_person(user)
67+ bug_params = CreateBugParams(title='bug title', owner=user)
68+ command = InformationTypeEmailCommand(
69+ 'informationtype', ['unembargoedsecurity'])
70+ dummy_event = object()
71+ params, event = command.execute(bug_params, dummy_event)
72+ self.assertEqual(bug_params, params)
73+ self.assertEqual(
74+ InformationType.UNEMBARGOEDSECURITY, bug_params.information_type)
75+ self.assertTrue(IObjectModifiedEvent.providedBy(event))
76+
77+ def test_execute_bug(self):
78+ bug = self.factory.makeBug()
79+ login_person(bug.owner)
80+ command = InformationTypeEmailCommand(
81+ 'informationtype', ['embargoedsecurity'])
82+ exec_bug, event = command.execute(bug, None)
83+ self.assertEqual(bug, exec_bug)
84+ self.assertEqual(
85+ InformationType.EMBARGOEDSECURITY, bug.information_type)
86+ self.assertTrue(IObjectModifiedEvent.providedBy(event))
87+
88+ def test_execute_bug_params_with_rubbish(self):
89+ user = self.factory.makePerson()
90+ login_person(user)
91+ bug_params = CreateBugParams(title='bug title', owner=user)
92+ command = InformationTypeEmailCommand(
93+ 'informationtype', ['rubbish'])
94+ dummy_event = object()
95+ self.assertRaises(
96+ EmailProcessingError, command.execute, bug_params, dummy_event)
97+
98+ def test_execute_bug_params_with_proprietary(self):
99+ user = self.factory.makePerson()
100+ login_person(user)
101+ bug_params = CreateBugParams(title='bug title', owner=user)
102+ command = InformationTypeEmailCommand(
103+ 'informationtype', ['proprietary'])
104+ dummy_event = object()
105+ self.assertRaisesWithContent(
106+ EmailProcessingError, 'Proprietary bugs are forbidden to be '
107+ 'filed via the mail interface.', command.execute, bug_params,
108+ dummy_event)
109+
110+
111 class SubscribeEmailCommandTestCase(TestCaseWithFactory):
112
113 layer = DatabaseFunctionalLayer
114
115=== modified file 'lib/lp/bugs/mail/tests/test_handler.py'
116--- lib/lp/bugs/mail/tests/test_handler.py 2012-03-27 13:41:38 +0000
117+++ lib/lp/bugs/mail/tests/test_handler.py 2012-05-04 00:07:23 +0000
118@@ -28,6 +28,7 @@
119 MaloneHandler,
120 )
121 from lp.bugs.model.bugnotification import BugNotification
122+from lp.registry.enums import InformationType
123 from lp.services.config import config
124 from lp.services.identity.interfaces.emailaddress import EmailAddressStatus
125 from lp.services.mail import stub
126@@ -318,6 +319,23 @@
127 recipients.add(recipient.person)
128 self.assertContentEqual([maintainer], recipients)
129
130+ def test_information_type(self):
131+ project = self.factory.makeProduct(name='fnord')
132+ transaction.commit()
133+ handler = MaloneHandler()
134+ with person_logged_in(project.owner):
135+ msg = self.factory.makeSignedMessage(
136+ body='unsecure\n informationtype userdata\n affects fnord',
137+ subject='unsecure code',
138+ to_address='new@bugs.launchpad.dev')
139+ handler.process(msg, msg['To'])
140+ notification = self.getLatestBugNotification()
141+ bug = notification.bug
142+ self.assertEqual('unsecure code', bug.title)
143+ self.assertEqual(InformationType.USERDATA, bug.information_type)
144+ self.assertEqual(1, len(bug.bugtasks))
145+ self.assertEqual(project, bug.bugtasks[0].target)
146+
147
148 class BugTaskCommandGroupTestCase(TestCase):
149