~launchpad-pqm/launchpad/devel

7675.845.1 by Edwin Grubbs
Added classes.
1
# Copyright 2010 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
7675.845.11 by Edwin Grubbs
Addressed review comments.
4
"""Interface for the Jobs system to change memberships or merge persons."""
7675.845.1 by Edwin Grubbs
Added classes.
5
6
__metaclass__ = type
7
__all__ = [
7675.845.9 by Edwin Grubbs
Refactored and renamed AddMemberNotificationJob to MembershipNotificationJob.
8
    'IMembershipNotificationJob',
9
    'IMembershipNotificationJobSource',
12394.1.2 by Gavin Panella
Get PersonMergeJob up and running.
10
    'IPersonMergeJob',
11
    'IPersonMergeJobSource',
7675.845.3 by Edwin Grubbs
Renamed MembershipJob to PersonTransferJob.
12
    'IPersonTransferJob',
13
    'IPersonTransferJobSource',
7675.845.1 by Edwin Grubbs
Added classes.
14
    ]
15
7675.845.11 by Edwin Grubbs
Addressed review comments.
16
from zope.interface import Attribute
7675.845.1 by Edwin Grubbs
Added classes.
17
from zope.schema import (
18
    Int,
19
    Object,
20
    )
21
14600.1.12 by Curtis Hovey
Move i18n to lp.
22
from lp import _
7675.845.1 by Edwin Grubbs
Added classes.
23
from lp.services.fields import PublicPersonChoice
24
from lp.services.job.interfaces.job import (
25
    IJob,
26
    IJobSource,
7675.845.6 by Edwin Grubbs
More of the test is working.
27
    IRunnableJob,
7675.845.1 by Edwin Grubbs
Added classes.
28
    )
29
30
7675.845.6 by Edwin Grubbs
More of the test is working.
31
class IPersonTransferJob(IRunnableJob):
7675.845.3 by Edwin Grubbs
Renamed MembershipJob to PersonTransferJob.
32
    """A Job related to team membership or a person merge."""
7675.845.1 by Edwin Grubbs
Added classes.
33
34
    id = Int(
35
        title=_('DB ID'), required=True, readonly=True,
36
        description=_("The tracking number for this job."))
37
38
    job = Object(
39
        title=_('The common Job attributes'),
40
        schema=IJob,
41
        required=True)
42
7675.845.3 by Edwin Grubbs
Renamed MembershipJob to PersonTransferJob.
43
    minor_person = PublicPersonChoice(
44
        title=_('The person being added to the major person/team'),
45
        vocabulary='ValidPersonOrTeam',
7675.845.1 by Edwin Grubbs
Added classes.
46
        required=True)
47
7675.845.3 by Edwin Grubbs
Renamed MembershipJob to PersonTransferJob.
48
    major_person = PublicPersonChoice(
49
        title=_('The person or team receiving the minor person'),
7675.845.1 by Edwin Grubbs
Added classes.
50
        vocabulary='ValidPersonOrTeam',
51
        required=True)
52
53
    metadata = Attribute('A dict of data about the job.')
54
55
7675.845.3 by Edwin Grubbs
Renamed MembershipJob to PersonTransferJob.
56
class IPersonTransferJobSource(IJobSource):
57
    """An interface for acquiring IPersonTransferJobs."""
7675.845.1 by Edwin Grubbs
Added classes.
58
7675.845.4 by Edwin Grubbs
Most of refactoring complete.
59
    def create(minor_person, major_person, metadata):
7675.845.3 by Edwin Grubbs
Renamed MembershipJob to PersonTransferJob.
60
        """Create a new IPersonTransferJob."""
7675.845.4 by Edwin Grubbs
Most of refactoring complete.
61
62
7675.845.9 by Edwin Grubbs
Refactored and renamed AddMemberNotificationJob to MembershipNotificationJob.
63
class IMembershipNotificationJob(IPersonTransferJob):
7675.845.4 by Edwin Grubbs
Most of refactoring complete.
64
    """A Job to notify new members of a team of that change."""
65
7675.845.23 by Edwin Grubbs
Addressed more review comments.
66
    member = PublicPersonChoice(
67
        title=_('Alias for minor_person attribute'),
68
        vocabulary='ValidPersonOrTeam',
69
        required=True)
70
71
    team = PublicPersonChoice(
72
        title=_('Alias for major_person attribute'),
73
        vocabulary='ValidPersonOrTeam',
74
        required=True)
75
7675.845.4 by Edwin Grubbs
Most of refactoring complete.
76
7675.845.9 by Edwin Grubbs
Refactored and renamed AddMemberNotificationJob to MembershipNotificationJob.
77
class IMembershipNotificationJobSource(IJobSource):
78
    """An interface for acquiring IMembershipNotificationJobs."""
7675.845.4 by Edwin Grubbs
Most of refactoring complete.
79
80
    def create(member, team, reviewer, old_status, new_status,
81
               last_change_comment=None):
7675.845.9 by Edwin Grubbs
Refactored and renamed AddMemberNotificationJob to MembershipNotificationJob.
82
        """Create a new IMembershipNotificationJob."""
12394.1.2 by Gavin Panella
Get PersonMergeJob up and running.
83
84
85
class IPersonMergeJob(IPersonTransferJob):
86
    """A Job that merges one person or team into another."""
87
88
    from_person = PublicPersonChoice(
89
        title=_('Alias for minor_person attribute'),
90
        vocabulary='ValidPersonOrTeam',
91
        required=True)
92
93
    to_person = PublicPersonChoice(
94
        title=_('Alias for major_person attribute'),
95
        vocabulary='ValidPersonOrTeam',
96
        required=True)
97
12589.6.2 by Curtis Hovey
Merged getErrorRecipients changes from base branch.
98
    def getErrorRecipients(self):
99
        """See `BaseRunnableJob`."""
100
12394.1.2 by Gavin Panella
Get PersonMergeJob up and running.
101
102
class IPersonMergeJobSource(IJobSource):
12651.1.7 by Curtis Hovey
Added review kwarg to PersonMergeJobSource.create() and a property to access it.
103
    """An interface for acquiring IPersonMergeJobs."""
12394.1.2 by Gavin Panella
Get PersonMergeJob up and running.
104
13555.6.1 by Robert Collins
Refactor team deletes to let the model code know that a delete is requested.
105
    def create(from_person, to_person, reviewer=None, delete=False):
12651.1.13 by Curtis Hovey
Corrected comments and documentation.
106
        """Create a new IPersonMergeJob.
12589.4.6 by Curtis Hovey
Pushed the guard to prevent multiple pending merges for a person to the utility.
107
108
        None is returned if either the from_person or to_person are already
12651.1.12 by Curtis Hovey
Fixed spelling and use common identifiers.
109
        in a pending merge. The review keyword argument is required if
12651.1.7 by Curtis Hovey
Added review kwarg to PersonMergeJobSource.create() and a property to access it.
110
        the from_person and to_person are teams.
111
12651.1.12 by Curtis Hovey
Fixed spelling and use common identifiers.
112
        :param from_person: An IPerson or ITeam that is a duplicate.
12651.1.7 by Curtis Hovey
Added review kwarg to PersonMergeJobSource.create() and a property to access it.
113
        :param to_person: An IPerson or ITeam that is a master.
12760.1.7 by Curtis Hovey
Updated the merge() and merge_async() to accept a reviewer arg.
114
        :param reviewer: An IPerson who approved ITeam merger.
13555.6.1 by Robert Collins
Refactor team deletes to let the model code know that a delete is requested.
115
        :param delete: The merge is really a deletion.
12589.4.6 by Curtis Hovey
Pushed the guard to prevent multiple pending merges for a person to the utility.
116
        """
12599.4.2 by Leonard Richardson
Merge from trunk.
117
12589.4.2 by Curtis Hovey
Added any_person bool arg to IPersonMergeSource.find() so that a user
118
    def find(from_person=None, to_person=None, any_person=False):
12394.1.13 by Gavin Panella
JobStatus.SUSPENDED also counts as a pending job.
119
        """Finds pending merge jobs.
12394.1.7 by Gavin Panella
New method IPersonMergeJobSource.find().
120
121
        :param from_person: Match jobs on `from_person`, or `None` to ignore
122
            `from_person`.
123
        :param to_person: Match jobs on `to_person`, or `None` to ignore
124
            `from_person`.
12589.4.2 by Curtis Hovey
Added any_person bool arg to IPersonMergeSource.find() so that a user
125
        :param any_person: Match jobs on the `to_person` or the `from_person`
126
            when both `to_person` and `from_person` are not None.
12394.1.7 by Gavin Panella
New method IPersonMergeJobSource.find().
127
        :return: A `ResultSet` yielding `IPersonMergeJob`.
128
129
        If both `from_person` and `to_person` is supplied, only jobs where
12589.4.2 by Curtis Hovey
Added any_person bool arg to IPersonMergeSource.find() so that a user
130
        both match are returned by default. When any_person is True and
131
        `from_person` and `to_person` are supplied, jobs with either person
132
        specified are returned.
12394.1.7 by Gavin Panella
New method IPersonMergeJobSource.find().
133
        """