11347.14.19
by Gavin Panella
Fix copyright dates. |
1 |
# Copyright 2010 Canonical Ltd. This software is licensed under the
|
11347.14.5
by Gavin Panella
Move notify_bugtask_edited to lp.bugs. |
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
3 |
||
4 |
__metaclass__ = type |
|
5 |
__all__ = [ |
|
6 |
'notify_bugtask_edited', |
|
7 |
'update_security_contact_subscriptions', |
|
8 |
]
|
|
9 |
||
10 |
||
11 |
from lp.bugs.adapters.bugdelta import BugDelta |
|
11347.14.15
by Gavin Panella
Fix import. |
12 |
from lp.bugs.subscribers.bug import ( |
11347.14.18
by Gavin Panella
Reformat imports. |
13 |
add_bug_change_notifications, |
14 |
send_bug_details_to_new_bug_subscribers, |
|
15 |
)
|
|
11347.14.5
by Gavin Panella
Move notify_bugtask_edited to lp.bugs. |
16 |
from lp.registry.interfaces.person import IPerson |
13479.2.4
by William Grant
And the bug supervisor subscriber thingy. |
17 |
from lp.registry.interfaces.product import IProduct |
14606.3.1
by William Grant
Merge canonical.database into lp.services.database. |
18 |
from lp.services.database.sqlbase import block_implicit_flushes |
19 |
from lp.services.webapp.publisher import canonical_url |
|
11347.14.5
by Gavin Panella
Move notify_bugtask_edited to lp.bugs. |
20 |
|
21 |
||
22 |
@block_implicit_flushes
|
|
23 |
def update_security_contact_subscriptions(event): |
|
24 |
"""Subscribe the new security contact when a bugtask's product changes.
|
|
25 |
||
26 |
Only subscribes the new security contact if the bug was marked a
|
|
27 |
security issue originally.
|
|
28 |
||
29 |
No change is made for private bugs.
|
|
30 |
"""
|
|
31 |
if event.object.bug.private: |
|
32 |
return
|
|
33 |
||
13479.2.4
by William Grant
And the bug supervisor subscriber thingy. |
34 |
if not IProduct.providedBy(event.object.target): |
11347.14.5
by Gavin Panella
Move notify_bugtask_edited to lp.bugs. |
35 |
return
|
36 |
||
37 |
bugtask_before_modification = event.object_before_modification |
|
38 |
bugtask_after_modification = event.object |
|
39 |
||
40 |
if (bugtask_before_modification.product != |
|
41 |
bugtask_after_modification.product): |
|
42 |
new_product = bugtask_after_modification.product |
|
43 |
if (bugtask_before_modification.bug.security_related and |
|
44 |
new_product.security_contact): |
|
45 |
bugtask_after_modification.bug.subscribe( |
|
46 |
new_product.security_contact, IPerson(event.user)) |
|
47 |
||
48 |
||
49 |
@block_implicit_flushes
|
|
50 |
def notify_bugtask_edited(modified_bugtask, event): |
|
51 |
"""Notify CC'd subscribers of this bug that something has changed
|
|
52 |
on this task.
|
|
53 |
||
54 |
modified_bugtask must be an IBugTask. event must be an
|
|
55 |
IObjectModifiedEvent.
|
|
56 |
"""
|
|
12607.6.2
by Ian Booth
Rework implementation |
57 |
bugtask_delta = event.object.getDelta(event.object_before_modification) |
11347.14.5
by Gavin Panella
Move notify_bugtask_edited to lp.bugs. |
58 |
bug_delta = BugDelta( |
12607.6.2
by Ian Booth
Rework implementation |
59 |
bug=event.object.bug, |
60 |
bugurl=canonical_url(event.object.bug), |
|
11347.14.5
by Gavin Panella
Move notify_bugtask_edited to lp.bugs. |
61 |
bugtask_deltas=bugtask_delta, |
62 |
user=IPerson(event.user)) |
|
63 |
||
64 |
event_creator = IPerson(event.user) |
|
12607.6.2
by Ian Booth
Rework implementation |
65 |
previous_subscribers = event.object_before_modification.bug_subscribers |
11347.14.5
by Gavin Panella
Move notify_bugtask_edited to lp.bugs. |
66 |
current_subscribers = event.object.bug_subscribers |
67 |
prev_subs_set = set(previous_subscribers) |
|
68 |
cur_subs_set = set(current_subscribers) |
|
69 |
new_subs = cur_subs_set.difference(prev_subs_set) |
|
70 |
||
71 |
add_bug_change_notifications( |
|
12607.6.2
by Ian Booth
Rework implementation |
72 |
bug_delta, old_bugtask=event.object_before_modification, |
11347.14.5
by Gavin Panella
Move notify_bugtask_edited to lp.bugs. |
73 |
new_subscribers=new_subs) |
74 |
||
11347.14.6
by Gavin Panella
Move notify_bug_subscription_added. |
75 |
send_bug_details_to_new_bug_subscribers( |
12607.6.2
by Ian Booth
Rework implementation |
76 |
event.object.bug, previous_subscribers, current_subscribers, |
11347.14.5
by Gavin Panella
Move notify_bugtask_edited to lp.bugs. |
77 |
event_creator=event_creator) |
78 |
||
79 |
update_security_contact_subscriptions(event) |