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
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
# pylint: disable-msg=E0211,E0213
"""Bug subscription interfaces."""
__metaclass__ = type
__all__ = [
'IBugSubscription',
]
from lazr.lifecycle.snapshot import doNotSnapshot
from lazr.restful.declarations import (
call_with,
export_as_webservice_entry,
export_read_operation,
exported,
operation_for_version,
REQUEST_USER,
)
from lazr.restful.fields import Reference
from zope.interface import (
Attribute,
Interface,
)
from zope.schema import (
Choice,
Datetime,
Int,
)
from lp import _
from lp.services.webservice.apihelpers import patch_reference_property
from lp.bugs.enum import BugNotificationLevel
from lp.services.fields import PersonChoice
class IBugSubscription(Interface):
"""The relationship between a person and a bug."""
export_as_webservice_entry(publish_web_link=False, as_of="beta")
id = Int(title=_('ID'), readonly=True, required=True)
person = exported(PersonChoice(
title=_('Person'), required=True, vocabulary='ValidPersonOrTeam',
readonly=True, description=_("The person's Launchpad ID or "
"e-mail address.")), as_of="beta")
bug = exported(Reference(
Interface, title=_("Bug"), required=True, readonly=True), as_of="beta")
# We mark this as doNotSnapshot() because it's a magically-generated
# Storm attribute and it causes Snapshot to break.
bugID = doNotSnapshot(Int(title=u"The bug id.", readonly=True))
bug_notification_level = exported(
Choice(
title=_("Bug notification level"), required=True,
vocabulary=BugNotificationLevel,
default=BugNotificationLevel.COMMENTS,
description=_(
"The volume and type of bug notifications "
"this subscription will generate."),
),
as_of="devel")
date_created = exported(
Datetime(title=_('Date subscribed'), required=True, readonly=True),
as_of="beta")
subscribed_by = exported(
PersonChoice(
title=_('Subscribed by'), required=True,
vocabulary='ValidPersonOrTeam', readonly=True,
description=_("The person who created this subscription.")),
as_of="beta")
display_subscribed_by = Attribute(
"`subscribed_by` formatted for display.")
display_duplicate_subscribed_by = Attribute(
"duplicate bug `subscribed_by` formatted for display.")
@call_with(user=REQUEST_USER)
@export_read_operation()
@operation_for_version("beta")
def canBeUnsubscribedByUser(user):
"""Can the user unsubscribe the subscriber from the bug?"""
# In order to avoid circular dependencies, we only import
# IBug (which itself imports IBugSubscription) here, and assign it as
# the value type for the `bug` reference.
from lp.bugs.interfaces.bug import IBug
patch_reference_property(IBugSubscription, 'bug', IBug)
|