← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Steve Kowalik has proposed merging lp:~stevenk/launchpad/bugs-information_type-mail into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #933766 in Launchpad itself: "Update bug to use information_visibility_policy"
  https://bugs.launchpad.net/launchpad/+bug/933766

For more details, see:
https://code.launchpad.net/~stevenk/launchpad/bugs-information_type-mail/+merge/104483

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.
-- 
https://code.launchpad.net/~stevenk/launchpad/bugs-information_type-mail/+merge/104483
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/bugs-information_type-mail into lp:launchpad.
=== modified file 'lib/lp/bugs/mail/commands.py'
--- lib/lp/bugs/mail/commands.py	2012-03-29 00:48:21 +0000
+++ lib/lp/bugs/mail/commands.py	2012-05-04 00:07:23 +0000
@@ -814,6 +814,31 @@
         return {self.name: dbitem}
 
 
+class InformationTypeEmailCommand(DBSchemaEditEmailCommand):
+    """Change the information type of a bug."""
+
+    implements(IBugEditEmailCommand)
+    dbschema = InformationType
+    RANK = 3
+
+    def convertArguments(self, context):
+        args = super(InformationTypeEmailCommand, self).convertArguments(
+            context)
+        return {'information_type': args['informationtype']}
+
+    def setAttributeValue(self, context, attr_name, attr_value):
+        """See EmailCommand."""
+        user = getUtility(ILaunchBag).user
+        if attr_value == InformationType.PROPRIETARY:
+            raise EmailProcessingError(
+                'Proprietary bugs are forbidden to be filed via the mail '
+                'interface.')
+        if isinstance(context, CreateBugParams):
+            context.information_type = attr_value
+        else:
+            context.transitionToInformationType(attr_value, user)
+
+
 class StatusEmailCommand(DBSchemaEditEmailCommand):
     """Changes a bug task's status."""
     dbschema = BugTaskStatus
@@ -901,6 +926,7 @@
 
     _commands = {
         'bug': BugEmailCommand,
+        'informationtype': InformationTypeEmailCommand,
         'private': PrivateEmailCommand,
         'security': SecurityEmailCommand,
         'summary': SummaryEmailCommand,

=== modified file 'lib/lp/bugs/mail/tests/test_commands.py'
--- lib/lp/bugs/mail/tests/test_commands.py	2012-04-03 06:14:09 +0000
+++ lib/lp/bugs/mail/tests/test_commands.py	2012-05-04 00:07:23 +0000
@@ -12,6 +12,7 @@
     BugEmailCommand,
     CVEEmailCommand,
     DuplicateEmailCommand,
+    InformationTypeEmailCommand,
     PrivateEmailCommand,
     SecurityEmailCommand,
     SubscribeEmailCommand,
@@ -412,6 +413,57 @@
         self.assertEqual(dummy_event, event)
 
 
+class InformationTypeEmailCommandTestCase(TestCaseWithFactory):
+
+    layer = DatabaseFunctionalLayer
+
+    def test_execute_bug_params(self):
+        user = self.factory.makePerson()
+        login_person(user)
+        bug_params = CreateBugParams(title='bug title', owner=user)
+        command = InformationTypeEmailCommand(
+            'informationtype', ['unembargoedsecurity'])
+        dummy_event = object()
+        params, event = command.execute(bug_params, dummy_event)
+        self.assertEqual(bug_params, params)
+        self.assertEqual(
+            InformationType.UNEMBARGOEDSECURITY, bug_params.information_type)
+        self.assertTrue(IObjectModifiedEvent.providedBy(event))
+
+    def test_execute_bug(self):
+        bug = self.factory.makeBug()
+        login_person(bug.owner)
+        command = InformationTypeEmailCommand(
+            'informationtype', ['embargoedsecurity'])
+        exec_bug, event = command.execute(bug, None)
+        self.assertEqual(bug, exec_bug)
+        self.assertEqual(
+            InformationType.EMBARGOEDSECURITY, bug.information_type)
+        self.assertTrue(IObjectModifiedEvent.providedBy(event))
+
+    def test_execute_bug_params_with_rubbish(self):
+        user = self.factory.makePerson()
+        login_person(user)
+        bug_params = CreateBugParams(title='bug title', owner=user)
+        command = InformationTypeEmailCommand(
+            'informationtype', ['rubbish'])
+        dummy_event = object()
+        self.assertRaises(
+            EmailProcessingError, command.execute, bug_params, dummy_event)
+
+    def test_execute_bug_params_with_proprietary(self):
+        user = self.factory.makePerson()
+        login_person(user)
+        bug_params = CreateBugParams(title='bug title', owner=user)
+        command = InformationTypeEmailCommand(
+            'informationtype', ['proprietary'])
+        dummy_event = object()
+        self.assertRaisesWithContent(
+            EmailProcessingError, 'Proprietary bugs are forbidden to be '
+            'filed via the mail interface.', command.execute, bug_params,
+            dummy_event)
+
+
 class SubscribeEmailCommandTestCase(TestCaseWithFactory):
 
     layer = DatabaseFunctionalLayer

=== modified file 'lib/lp/bugs/mail/tests/test_handler.py'
--- lib/lp/bugs/mail/tests/test_handler.py	2012-03-27 13:41:38 +0000
+++ lib/lp/bugs/mail/tests/test_handler.py	2012-05-04 00:07:23 +0000
@@ -28,6 +28,7 @@
     MaloneHandler,
     )
 from lp.bugs.model.bugnotification import BugNotification
+from lp.registry.enums import InformationType
 from lp.services.config import config
 from lp.services.identity.interfaces.emailaddress import EmailAddressStatus
 from lp.services.mail import stub
@@ -318,6 +319,23 @@
                 recipients.add(recipient.person)
         self.assertContentEqual([maintainer], recipients)
 
+    def test_information_type(self):
+        project = self.factory.makeProduct(name='fnord')
+        transaction.commit()
+        handler = MaloneHandler()
+        with person_logged_in(project.owner):
+            msg = self.factory.makeSignedMessage(
+                body='unsecure\n informationtype userdata\n affects fnord',
+                subject='unsecure code',
+                to_address='new@xxxxxxxxxxxxxxxxxx')
+            handler.process(msg, msg['To'])
+        notification = self.getLatestBugNotification()
+        bug = notification.bug
+        self.assertEqual('unsecure code', bug.title)
+        self.assertEqual(InformationType.USERDATA, bug.information_type)
+        self.assertEqual(1, len(bug.bugtasks))
+        self.assertEqual(project, bug.bugtasks[0].target)
+
 
 class BugTaskCommandGroupTestCase(TestCase):
 


Follow ups