~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/mail/commands.py

  • Committer: Jelmer Vernooij
  • Date: 2011-09-21 14:28:02 UTC
  • mfrom: (14006 devel)
  • mto: This revision was merged to the branch mainline in revision 14010.
  • Revision ID: jelmer@canonical.com-20110921142802-7ggkc204igsy532w
MergeĀ lp:launchpad

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
from lp.registry.interfaces.productseries import IProductSeries
58
58
from lp.registry.interfaces.projectgroup import IProjectGroup
59
59
from lp.registry.interfaces.sourcepackage import ISourcePackage
 
60
from lp.registry.interfaces.sourcepackagename import ISourcePackageName
60
61
from lp.services.mail.commands import (
61
62
    EditEmailCommand,
62
63
    EmailCommand,
127
128
            params = CreateBugParams(
128
129
                msg=message, title=message.title,
129
130
                owner=getUtility(ILaunchBag).user)
130
 
            return getUtility(IBugSet).createBugWithoutTarget(params)
 
131
            return params, None
131
132
        else:
132
133
            try:
133
134
                bugid = int(bugid)
181
182
                    error_templates=error_templates),
182
183
                stop_processing=True)
183
184
 
 
185
        if isinstance(context, CreateBugParams):
 
186
            if context.security_related:
 
187
                # BugSet.createBug() requires new security bugs to be private.
 
188
                private = True
 
189
            context.private = private
 
190
            return context, current_event
 
191
 
184
192
        # Snapshot.
185
193
        edited_fields = set()
186
194
        if IObjectModifiedEvent.providedBy(current_event):
230
238
                    error_templates=error_templates),
231
239
                stop_processing=True)
232
240
 
 
241
        if isinstance(context, CreateBugParams):
 
242
            context.security_related = security_related
 
243
            if security_related:
 
244
                # BugSet.createBug() requires new security bugs to be private.
 
245
                context.private = True
 
246
            return context, current_event
 
247
 
233
248
        # Take a snapshot.
234
249
        edited = False
235
250
        edited_fields = set()
241
256
                context, providing=providedBy(context))
242
257
 
243
258
        # Apply requested changes.
244
 
        user = getUtility(ILaunchBag).user
245
259
        if security_related:
 
260
            user = getUtility(ILaunchBag).user
246
261
            if context.setPrivate(True, user):
247
262
                edited = True
248
263
                edited_fields.add('private')
249
264
        if context.security_related != security_related:
250
 
            context.setSecurityRelated(security_related, user)
 
265
            context.setSecurityRelated(security_related)
251
266
            edited = True
252
267
            edited_fields.add('security_related')
253
268
 
287
302
                    'subscribe-too-many-arguments.txt',
288
303
                    error_templates=error_templates))
289
304
 
 
305
        if isinstance(bug, CreateBugParams):
 
306
            if len(bug.subscribers) == 0:
 
307
                bug.subscribers = [person]
 
308
            else:
 
309
                bug.subscribers.append(person)
 
310
            return bug, current_event
 
311
 
290
312
        if bug.isSubscribed(person):
291
313
            # but we still need to find the subscription
292
314
            for bugsubscription in bug.subscriptions:
308
330
 
309
331
    def execute(self, bug, current_event):
310
332
        """See IEmailCommand."""
 
333
        if isinstance(bug, CreateBugParams):
 
334
            # Return the input because there is not yet a bug to
 
335
            # unsubscribe too.
 
336
            return bug, current_event
 
337
 
311
338
        string_args = list(self.string_args)
312
339
        if len(string_args) == 1:
313
340
            person = get_person_or_team(string_args.pop())
359
386
                    'summary-too-many-arguments.txt',
360
387
                    error_templates=error_templates))
361
388
 
 
389
        if isinstance(bug, CreateBugParams):
 
390
            bug.title = self.string_args[0]
 
391
            return bug, current_event
 
392
 
362
393
        return EditEmailCommand.execute(self, bug, current_event)
363
394
 
364
395
    def convertArguments(self, context):
375
406
 
376
407
    def execute(self, context, current_event):
377
408
        """See IEmailCommand."""
 
409
        if isinstance(context, CreateBugParams):
 
410
            # No one intentially reports a duplicate bug. Bug email commands
 
411
            # support CreateBugParams, so in this case, just return.
 
412
            return context, current_event
378
413
        self._ensureNumberOfArguments()
379
414
        [bug_id] = self.string_args
380
415
 
421
456
        if cve is None:
422
457
            raise EmailProcessingError(
423
458
                'Launchpad can\'t find the CVE "%s".' % cve_sequence)
 
459
        if isinstance(bug, CreateBugParams):
 
460
            bug.cve = cve
 
461
            return bug, current_event
 
462
 
424
463
        bug.linkCVE(cve, getUtility(ILaunchBag).user)
425
464
        return bug, current_event
426
465
 
528
567
        assert rest, "This is the fallback for unexpected path components."
529
568
        raise BugTargetNotFound("Unexpected path components: %s" % rest)
530
569
 
531
 
    def execute(self, bug):
 
570
    def execute(self, bug, bug_event):
532
571
        """See IEmailCommand."""
533
572
        if bug is None:
534
573
            raise EmailProcessingError(
551
590
        except BugTargetNotFound, error:
552
591
            raise EmailProcessingError(unicode(error), stop_processing=True)
553
592
        event = None
 
593
 
 
594
        if isinstance(bug, CreateBugParams):
 
595
            # Enough information has been gathered to create a new bug.
 
596
            kwargs = {
 
597
                'product': IProduct(bug_target, None),
 
598
                'distribution': IDistribution(bug_target, None),
 
599
                'sourcepackagename': ISourcePackageName(bug_target, None),
 
600
                }
 
601
            bug.setBugTarget(**kwargs)
 
602
            bug, bug_event = getUtility(IBugSet).createBug(
 
603
                bug, notify_event=False)
 
604
            event = ObjectCreatedEvent(bug.bugtasks[0])
 
605
            # Continue because the bug_target may be a subordinate bugtask.
 
606
 
554
607
        bugtask = bug.getBugTask(bug_target)
555
608
        if (bugtask is None and
556
609
            IDistributionSourcePackage.providedBy(bug_target)):
568
621
            bugtask = self._create_bug_task(bug, bug_target)
569
622
            event = ObjectCreatedEvent(bugtask)
570
623
 
571
 
        return bugtask, event
 
624
        return bugtask, event, bug_event
572
625
 
573
626
    def _targetBug(self, user, bug, series, sourcepackagename=None):
574
627
        """Try to target the bug the given distroseries.
796
849
        """See `IEmailCommand`."""
797
850
        # Tags are always lowercase.
798
851
        string_args = [arg.lower() for arg in self.string_args]
799
 
        # Bug.tags returns a Zope List, which does not support Python list
800
 
        # operations so we need to convert it.
801
 
        tags = list(bug.tags)
802
 
 
803
 
        # XXX: DaveMurphy 2007-07-11: in the following loop we process each
804
 
        # tag in turn. Each tag that is either invalid or unassigned will
805
 
        # result in a mail to the submitter. This may result in several mails
806
 
        # for a single command. This will need to be addressed if that becomes
807
 
        # a problem.
808
 
 
 
852
        if bug.tags is None:
 
853
            tags = []
 
854
        else:
 
855
            tags = list(bug.tags)
809
856
        for arg in string_args:
810
857
            # Are we adding or removing a tag?
811
858
            if arg.startswith('-'):
832
879
                            tag=tag))
833
880
            else:
834
881
                tags.append(arg)
835
 
 
836
 
        # Duplicates are dealt with when the tags are stored in the DB (which
837
 
        # incidentally uses a set to achieve this). Since the code already
838
 
        # exists we don't duplicate it here.
839
 
 
840
 
        # Bug.tags expects to be given a Python list, so there is no need to
841
 
        # convert it back.
842
882
        bug.tags = tags
843
883
 
844
884
        return bug, current_event