~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Branch merge queue interfaces."""

__metaclass__ = type

__all__ = [
    'IBranchMergeQueue',
    'IBranchMergeQueueSource',
    'user_has_special_merge_queue_access',
    ]

from lazr.restful.declarations import (
    export_as_webservice_entry,
    export_write_operation,
    exported,
    mutator_for,
    operation_parameters,
    )
from lazr.restful.fields import (
    CollectionField,
    Reference,
    )
from zope.component import getUtility
from zope.interface import Interface
from zope.schema import (
    Datetime,
    Int,
    Text,
    TextLine,
    )

from canonical.launchpad import _
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
from lp.services.fields import (
    PersonChoice,
    PublicPersonChoice,
    )


class IBranchMergeQueue(Interface):
    """An interface for managing branch merges."""

    export_as_webservice_entry()

    id = Int(title=_('ID'), readonly=True, required=True)

    registrant = exported(
        PublicPersonChoice(
            title=_("The user that registered the branch."),
            required=True, readonly=True,
            vocabulary='ValidPersonOrTeam'))

    owner = exported(
        PersonChoice(
            title=_('Owner'),
            required=True, readonly=True,
            vocabulary='UserTeamsParticipationPlusSelf',
            description=_("The owner of the merge queue.")))

    name = exported(
        TextLine(
            title=_('Name'), required=True,
            description=_(
                "Keep very short, unique, and descriptive, because it will "
                "be used in URLs.  "
                "Examples: main, devel, release-1.0, gnome-vfs.")))

    description = exported(
        Text(
            title=_('Description'), required=False,
            description=_(
                'A short description of the purpose of this merge queue.')))

    configuration = exported(
        TextLine(
            title=_('Configuration'), required=False, readonly=True,
            description=_(
                "A JSON string of configuration values.")))

    date_created = exported(
        Datetime(
            title=_('Date Created'),
            required=True,
            readonly=True))

    branches = exported(
        CollectionField(
            title=_('Dependent Branches'),
            description=_(
                'A collection of branches that this queue manages.'),
            readonly=True,
            value_type=Reference(Interface)))

    @mutator_for(configuration)
    @operation_parameters(
        config=TextLine(title=_("A JSON string of configuration values.")))
    @export_write_operation()
    def setMergeQueueConfig(config):
        """Set the JSON string configuration of the merge queue.

        :param config: A JSON string of configuration values.
        """


class IBranchMergeQueueSource(Interface):

    def new(name, owner, registrant, description, configuration, branches):
        """Create a new IBranchMergeQueue object.

        :param name: The name of the branch merge queue.
        :param description: A description of queue.
        :param configuration: A JSON string of configuration values.
        :param owner: The owner of the queue.
        :param registrant: The registrant of the queue.
        :param branches: A list of branches to add to the queue.
        """


def user_has_special_merge_queue_access(user):
    """Admins and bazaar experts have special access.

    :param user: A 'Person' or None.
    """
    if user is None:
        return False
    celebs = getUtility(ILaunchpadCelebrities)
    return user.inTeam(celebs.admin)