~launchpad-pqm/launchpad/devel

8687.15.15 by Karl Fogel
Add the copyright header block to files under lib/lp/bugs/.
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4983.1.1 by Curtis Hovey
Added lint exceptions to __init__.py and interface/*.py.
4
# pylint: disable-msg=E0211,E0213
2068 by Canonical.com Patch Queue Manager
[r=SteveA/trivial] import fascism, kill translationeffort, kill sshkey browser code, add __all__s to interfaces, other cleanings-up
5
6
"""Bug message interfaces."""
7
8
__metaclass__ = type
3644.1.15 by Brad Bollenbach
major refactoring of the bug comment/attachment code
9
__all__ = [
3644.1.19 by Brad Bollenbach
merge from rf, resolving conflicts
10
    'IBugComment',
3644.1.15 by Brad Bollenbach
major refactoring of the bug comment/attachment code
11
    'IBugMessage',
12
    'IBugMessageAddForm',
3644.1.19 by Brad Bollenbach
merge from rf, resolving conflicts
13
    'IBugMessageSet',
14
    ]
2068 by Canonical.com Patch Queue Manager
[r=SteveA/trivial] import fascism, kill translationeffort, kill sshkey browser code, add __all__s to interfaces, other cleanings-up
15
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
16
from zope.interface import (
17
    Attribute,
18
    Interface,
19
    )
20
from zope.schema import (
21
    Bool,
22
    Bytes,
23
    Int,
24
    Object,
25
    Text,
26
    TextLine,
27
    )
3644.1.15 by Brad Bollenbach
major refactoring of the bug comment/attachment code
28
14560.2.23 by Curtis Hovey
Moved IHasBug to its own module.
29
from lp.bugs.interfaces.hasbug import IHasBug
12442.2.9 by j.c.sackett
Ran import reformatter per review.
30
from lp.app.validators.attachment import attachment_size_constraint
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
31
from lp.bugs.interfaces.bug import IBug
32
from lp.bugs.interfaces.bugwatch import IBugWatch
7675.1107.1 by Robert Collins
Expose BugMessage.owner to storm.
33
from lp.registry.interfaces.person import IPerson
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
34
from lp.services.fields import Title
14550.1.1 by Steve Kowalik
Run format-imports over lib/lp and lib/canonical/launchpad
35
from lp.services.messages.interfaces.message import IMessage
3607.4.9 by Bjorn Tillenius
use BugComment instead of BugMessage.
36
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
37
3496.2.12 by Brad Bollenbach
last bits of IBug.date_last_updated
38
class IBugMessage(IHasBug):
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
39
    """A link between a bug and a message."""
40
5292.2.37 by Graham Binns
Altered attribute definitions in IBugMessage
41
    bug = Object(schema=IBug, title=u"The bug.")
12262.2.1 by Robert Collins
Add a garbo job to populate BugMessage.index, fixing bug 704446.
42
    # The index field is being populated in the DB; once complete it will be
43
    # made required. Whether to make it readonly or not is dependent on UI
44
    # considerations. If, once populated, it becomes read-write, we probably
45
    # want to ensure that only actions like bug import or spam hiding can
46
    # change it, rather than arbitrary API scripts.
47
    index = Int(title=u'The comment number', required=False, readonly=False,
48
        default=None)
8137.17.24 by Barry Warsaw
thread merge
49
    messageID = Int(title=u"The message id.", readonly=True)
5292.2.37 by Graham Binns
Altered attribute definitions in IBugMessage
50
    message = Object(schema=IMessage, title=u"The message.")
51
    bugwatch = Object(schema=IBugWatch,
52
        title=u"A bugwatch to which the message pertains.")
12376.1.2 by Robert Collins
Basic implementation in place, tests not updated.
53
    bugwatchID = Int(title=u'The bugwatch id.', readonly=True)
6002.8.4 by Bjorn Tillenius
add BugMessage.remote_comment_id and have the comment importer set it.
54
    remote_comment_id = TextLine(
6002.8.11 by Bjorn Tillenius
review comments
55
        title=u"The id this comment has in the bugwatch's bug tracker.")
7675.1107.1 by Robert Collins
Expose BugMessage.owner to storm.
56
    ownerID = Attribute("The ID of the owner mirrored from the message")
57
    owner = Object(schema=IPerson,
58
        title=u"The Message owner mirrored from the message.", readonly=True)
2396 by Canonical.com Patch Queue Manager
[r=spiv] launchpad support tracker
59
2070 by Canonical.com Patch Queue Manager
[r=salgado] FormattingBugNotifications implementation. requires some
60
61
class IBugMessageSet(Interface):
62
    """The set of all IBugMessages."""
63
64
    def createMessage(subject, bug, owner, content=None):
65
        """Create an IBugMessage.
66
67
        title -- a string
68
        bug -- an IBug
69
        owner -- an IPerson
70
        content -- a string
71
2454 by Canonical.com Patch Queue Manager
[r=stevea]. make bug notifictions concerning the same bug be part of the same email thread.
72
        The created message will have the bug's initial message as its
73
        parent.
74
2070 by Canonical.com Patch Queue Manager
[r=salgado] FormattingBugNotifications implementation. requires some
75
        Returns the created IBugMessage.
76
        """
77
78
    def get(bugmessageid):
79
        """Retrieve an IBugMessage by its ID."""
2226 by Canonical.com Patch Queue Manager
fixes to email interface. [r=jamesh]
80
81
    def getByBugAndMessage(bug, message):
82
        """Return the corresponding IBugMesssage.
83
84
        Return None if no such IBugMesssage exists.
85
        """
2396 by Canonical.com Patch Queue Manager
[r=spiv] launchpad support tracker
86
5796.3.1 by Bjorn Tillenius
quick hack
87
    def getImportedBugMessages(bug):
5796.3.5 by Bjorn Tillenius
add test and documentation for new method.
88
        """Return all the imported IBugMesssages for a bug.
89
90
        An IBugMesssage is considered imported if it's linked to a bug
91
        watch.
92
        """
5796.3.1 by Bjorn Tillenius
quick hack
93
3607.4.17 by Bjorn Tillenius
review comments.
94
3644.1.15 by Brad Bollenbach
major refactoring of the bug comment/attachment code
95
class IBugMessageAddForm(Interface):
96
    """Schema used to build the add form for bug comment/attachment."""
97
6318.1.1 by Tom Berger
require a subject when submitting bug comments, and add a workaround for submitting replies to remote bug comments without a subject
98
    subject = Title(title=u"Subject", required=True)
3644.1.15 by Brad Bollenbach
major refactoring of the bug comment/attachment code
99
    comment = Text(title=u"Comment", required=False)
100
    filecontent = Bytes(
101
        title=u"Attachment", required=False,
9004.1.2 by Andrea Corbellini
Update modules, test cases and configuration.
102
        constraint=attachment_size_constraint)
10104.4.1 by Abel Deuring
Fix for bug 172501: reject non-code patch attachements
103
    patch = Bool(
104
        title=u"This attachment contains a solution (patch) for this bug",
105
        required=False, default=False)
3644.1.20 by Brad Bollenbach
fix small bugs from merging
106
    attachment_description = Title(title=u'Description', required=False)
3644.1.15 by Brad Bollenbach
major refactoring of the bug comment/attachment code
107
    email_me = Bool(
108
        title=u"E-mail me about changes to this bug report",
109
        required=False, default=False)
6293.1.1 by Tom Berger
reply to remore bug comments ui
110
    bugwatch_id = Int(
111
        title=(u"Synchronize this comment with a remote bug "
112
               "tracker using the bug watch with this id."),
113
        required=False, default=None)
3644.1.19 by Brad Bollenbach
merge from rf, resolving conflicts
114
115
3607.4.9 by Bjorn Tillenius
use BugComment instead of BugMessage.
116
class IBugComment(IMessage):
117
    """A bug comment for displaying in the web UI."""
118
3607.4.11 by Bjorn Tillenius
define a canonical url for IBugComment and use it.
119
    bugtask = Attribute(
120
        """The bug task the comment belongs to.
121
122
        Comments are global to bugs, but the bug task is needed in order
123
        to construct the correct URL.
124
        """)
5292.4.15 by Graham Binns
Added can_be_shown and bugwatch attributes to the IBugComment interface.
125
    bugwatch = Attribute('The bugwatch to which the comment pertains.')
8137.17.24 by Barry Warsaw
thread merge
126
    show_for_admin = Bool(
127
        title=u'A hidden comment still displayed for admins.',
128
        readonly=True)
3504.1.51 by kiko
r=bradb Refactor fetching of bug comments to issue O(1) queries. Essentially inverts the way we build the bug comments, fetching all the chunks first, grouping them by message. Should be a major performance boost for the bug page.
129
    index = Int(title=u'The comment number', required=True, readonly=True)
130
    was_truncated = Bool(
131
        title=u'Whether the displayed text was truncated for display.',
132
        readonly=True)
3607.4.9 by Bjorn Tillenius
use BugComment instead of BugMessage.
133
    text_for_display = Text(
3504.1.51 by kiko
r=bradb Refactor fetching of bug comments to issue O(1) queries. Essentially inverts the way we build the bug comments, fetching all the chunks first, grouping them by message. Should be a major performance boost for the bug page.
134
        title=u'The comment text to be displayed in the UI.', readonly=True)
3847.2.52 by Mark Shuttleworth
Test fixes for new date presentation
135
    display_title = Attribute('Whether or not to show the title.')
6293.1.1 by Tom Berger
reply to remore bug comments ui
136
    synchronized = Attribute(
137
        'Has the comment been synchronized with a remote bug tracker?')
138
    add_comment_url = Attribute(
139
        'The URL for submitting replies to this comment.')
8128.8.12 by Graham Binns
Fixed a number of test failures by exposing BugComment.activity and .show_footer in the IBugComment interface.
140
    activity = Attribute(
141
        "A list of BugActivityItems associated with this comment.")
142
    show_footer = Attribute(
143
        "Whether or not to show a footer for the comment.")
10017.2.5 by Abel Deuring
added a missing interface declaation for Bucomment.patches.
144
    patches = Attribute(
145
        "Patches attched to this comment.")
9232.2.71 by Stuart Bishop
Add rendered_cache_time to IBugComment
146
    rendered_cache_time = Attribute(
147
        "How long we can cache the rendered comment for.")