1
1
= IStructuralSubscriptionTarget =
3
Structural subscriptions allow users to subscribe to notifications about
4
new items and changes to existing items for a Launchpad structure such as
5
Product, ProjectGroup, Distribution, Milestone and series.
7
>>> from canonical.launchpad.interfaces import (
8
... IStructuralSubscriptionTarget)
9
>>> from canonical.launchpad.webapp.testing import verifyObject
10
>>> verifyObject(IStructuralSubscriptionTarget, target)
13
== Bug Subscriptions ==
15
Bug subscriptions are structural subscriptions to notifications about
18
>>> target.bug_subscriptions
21
First, we try to create a new subscription.
4
Let's subscribe ubuntu-team.
23
6
>>> from canonical.launchpad.interfaces import IPersonSet
24
7
>>> personset = getUtility(IPersonSet)
8
>>> ubuntu_team = personset.getByName("ubuntu-team")
25
9
>>> no_priv = personset.getByName("no-priv")
27
Only authenticated users can create subscriptions.
29
>>> target.addBugSubscription(no_priv, no_priv)
30
Traceback (most recent call last):
34
Let's login then to add a subscription:
10
>>> foobar = personset.getByName("name16")
36
11
>>> from canonical.launchpad.ftests import login
37
12
>>> login("foo.bar@canonical.com")
39
>>> target.addBugSubscription(no_priv, no_priv)
40
<StructuralSubscription ...>
41
>>> [sub.subscriber.name for sub in target.bug_subscriptions]
44
Trying to add a subscription to a target when that person
45
or team is already subscribed to that target will return
46
the existing subscription.
48
>>> target.addBugSubscription(no_priv, no_priv)
49
<StructuralSubscription ...>
51
People can only be subscribed by themselves, and only the team admins may
54
no-priv, who has no relationship to ubuntu-team, cannot subscribe it.
56
>>> ubuntu_team = personset.getByName("ubuntu-team")
57
>>> target.addBugSubscription(ubuntu_team, no_priv)
58
Traceback (most recent call last):
60
UserCannotSubscribePerson: no-priv does not have permission to subscribe ubuntu-team.
62
But kamion, an admin of the team, can.
64
>>> kamion = personset.getByName("kamion")
65
>>> target.addBugSubscription(ubuntu_team, kamion)
66
<StructuralSubscription ...>
68
>>> sorted([sub.subscriber.name for sub in target.bug_subscriptions])
69
[u'no-priv', u'ubuntu-team']
71
foobar, a Launchpad administrator, can as well.
73
>>> foobar = personset.getByName("name16")
74
>>> target.addBugSubscription(ubuntu_team, foobar)
75
<StructuralSubscription ...>
77
A non-admin cannot subscribe a person other than themselves.
79
>>> target.addBugSubscription(kamion, no_priv)
80
Traceback (most recent call last):
82
UserCannotSubscribePerson: no-priv does not have permission to subscribe kamion.
83
>>> sorted([sub.subscriber.name for sub in target.bug_subscriptions])
84
[u'no-priv', u'ubuntu-team']
86
But again, an admin can.
88
>>> target.addBugSubscription(kamion, foobar)
89
<StructuralSubscription ...>
90
>>> sorted([sub.subscriber.name for sub in target.bug_subscriptions])
91
[u'kamion', u'no-priv', u'ubuntu-team']
93
To remove a bug subscription, use
94
IStructuralSubscriptionTarget.removeBugSubscription:
96
>>> target.removeBugSubscription(no_priv, no_priv)
97
>>> sorted([sub.subscriber.name for sub in target.bug_subscriptions])
98
[u'kamion', u'ubuntu-team']
100
The subscription rules apply to unsubscription as well.
102
An unprivileged user cannot unsubscribe a team.
104
>>> target.removeBugSubscription(ubuntu_team, no_priv)
105
Traceback (most recent call last):
107
UserCannotSubscribePerson: no-priv does not have permission to unsubscribe ubuntu-team.
108
>>> sorted([sub.subscriber.name for sub in target.bug_subscriptions])
109
[u'kamion', u'ubuntu-team']
111
But a team admin can.
113
>>> target.removeBugSubscription(ubuntu_team, kamion)
114
>>> sorted([sub.subscriber.name for sub in target.bug_subscriptions])
117
An unprivileged user also cannot unsubscribe another user.
119
>>> target.removeBugSubscription(kamion, no_priv)
120
Traceback (most recent call last):
122
UserCannotSubscribePerson: no-priv does not have permission to unsubscribe kamion.
123
>>> sorted([sub.subscriber.name for sub in target.bug_subscriptions])
126
But the user themselves can.
128
>>> target.removeBugSubscription(kamion, kamion)
129
>>> sorted([sub.subscriber.name for sub in target.bug_subscriptions])
132
Trying to remove a subscription that doesn't exist on a target raises a
133
DeleteSubscriptionError.
135
>>> target.removeBugSubscription(foobar, foobar)
136
Traceback (most recent call last):
138
DeleteSubscriptionError: ...
140
Let's subscribe ubuntu-team again.
142
13
>>> target.addBugSubscription(ubuntu_team, foobar)
143
14
<StructuralSubscription ...>