~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
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Interfaces for linking Specifications and Branches."""

__metaclass__ = type

__all__ = [
    "IHasLinkedBranches",
    "ISpecificationBranch",
    "ISpecificationBranchSet",
    ]

from lazr.restful.declarations import (
    call_with,
    export_as_webservice_entry,
    export_operation_as,
    export_write_operation,
    exported,
    operation_for_version,
    operation_parameters,
    operation_returns_entry,
    REQUEST_USER,
    )
from lazr.restful.fields import (
    CollectionField,
    Reference,
    )
from zope.interface import Interface

from canonical.launchpad import _
from lp.code.interfaces.branch import IBranch
from lp.code.interfaces.branchtarget import IHasBranchTarget


class IHasLinkedBranches(Interface):
    """A interface for handling branch linkages."""

    linked_branches = exported(
        CollectionField(
            title=_('MultiJoin of the bugs which are dups of this one'),
            value_type=Reference(schema=IBranch),
            readonly=True))

    @call_with(registrant=REQUEST_USER)
    @operation_parameters(
        branch=Reference(schema=IBranch))
    @export_write_operation()
    @operation_for_version('beta')
    def linkBranch(branch, registrant):
        """Associate a branch with this bug.

        :param branch: The branch being linked to.
        :param registrant: The user linking the branch.
        """

    @call_with(user=REQUEST_USER)
    @operation_parameters(
        branch=Reference(schema=IBranch))
    @export_write_operation()
    @operation_for_version('beta')
    def unlinkBranch(branch, user):
        """Unlink a branch from this bug.

        :param branch: The branch being unlinked from.
        :param user: The user unlinking the branch.
        """