~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/model/persontransferjob.py

[rs=buildbot-poller] automatic merge from stable. Revisions: 13569,
        13570 included.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    )
46
46
from canonical.launchpad.mailnotification import MailWrapper
47
47
from canonical.launchpad.webapp import canonical_url
 
48
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
48
49
from lp.registry.enum import PersonTransferJobType
49
50
from lp.registry.interfaces.person import (
50
51
    IPerson,
345
346
    class_job_type = PersonTransferJobType.MERGE
346
347
 
347
348
    @classmethod
348
 
    def create(cls, from_person, to_person, reviewer=None):
 
349
    def create(cls, from_person, to_person, reviewer=None, delete=False):
349
350
        """See `IPersonMergeJobSource`."""
350
 
        if from_person.is_merge_pending or to_person.is_merge_pending:
 
351
        if (from_person.is_merge_pending or 
 
352
            (not delete and to_person.is_merge_pending)):
351
353
            return None
352
354
        if from_person.is_team:
353
355
            metadata = {'reviewer': reviewer.id}
354
356
        else:
355
357
            metadata = {}
 
358
        metadata['delete'] = bool(delete)
 
359
        if metadata['delete']:
 
360
            # Ideally not needed, but the DB column is not-null at the moment
 
361
            # and this minor bit of friction isn't worth changing that over.
 
362
            to_person = getUtility(ILaunchpadCelebrities).registry_experts
356
363
        return super(PersonMergeJob, cls).create(
357
364
            minor_person=from_person, major_person=to_person,
358
365
            metadata=metadata)
412
419
        to_person_name = self.to_person.name
413
420
 
414
421
        from canonical.launchpad.scripts import log
415
 
        log.debug(
416
 
            "%s is about to merge ~%s into ~%s", self.log_name,
417
 
            from_person_name, to_person_name)
418
 
        getUtility(IPersonSet).merge(
419
 
            from_person=self.from_person, to_person=self.to_person,
420
 
            reviewer=self.reviewer)
421
 
 
422
 
        log.debug(
423
 
            "%s has merged ~%s into ~%s", self.log_name,
424
 
            from_person_name, to_person_name)
 
422
        personset = getUtility(IPersonSet)
 
423
        if self.metadata['delete']:
 
424
            log.debug(
 
425
                "%s is about to delete ~%s", self.log_name,
 
426
                from_person_name)
 
427
            personset.delete(
 
428
                from_person=self.from_person,
 
429
                reviewer=self.reviewer)
 
430
            log.debug(
 
431
                "%s has deleted ~%s", self.log_name,
 
432
                from_person_name)
 
433
        else:
 
434
            log.debug(
 
435
                "%s is about to merge ~%s into ~%s", self.log_name,
 
436
                from_person_name, to_person_name)
 
437
            personset.merge(
 
438
                from_person=self.from_person, to_person=self.to_person,
 
439
                reviewer=self.reviewer)
 
440
            log.debug(
 
441
                "%s has merged ~%s into ~%s", self.log_name,
 
442
                from_person_name, to_person_name)
425
443
 
426
444
    def __repr__(self):
427
445
        return (