Code

17fc2b70e6d8ac40a20cfd4980b055f5b09ece76
[roundup.git] / roundup / templates / extended / detectors / nosyreaction.py
1 #
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
3 # This module is free software, and you may redistribute it and/or modify
4 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form.
6 #
7 # IN NO EVENT SHALL THE BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
10 # POSSIBILITY OF SUCH DAMAGE.
11 #
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17
18 #$Id: nosyreaction.py,v 1.2 2001-08-07 00:15:51 richard Exp $
20 def nosyreaction(db, cl, nodeid, oldvalues):
21     ''' A standard detector is provided that watches for additions to the
22         "messages" property.
23         
24         When a new message is added, the detector sends it to all the users on
25         the "nosy" list for the issue that are not already on the "recipients"
26         list of the message.
27         
28         Those users are then appended to the "recipients" property on the
29         message, so multiple copies of a message are never sent to the same
30         user.
31         
32         The journal recorded by the hyperdatabase on the "recipients" property
33         then provides a log of when the message was sent to whom. 
34     '''
35     messages = []
36     if oldvalues is None:
37         # the action was a create, so use all the messages in the create
38         messages = cl.get(nodeid, 'messages')
39     elif oldvalues.has_key('messages'):
40         # the action was a set (so adding new messages to an existing issue)
41         m = {}
42         for msgid in oldvalues['messages']:
43             m[msgid] = 1
44         messages = []
45         # figure which of the messages now on the issue weren't there before
46         for msgid in cl.get(nodeid, 'messages'):
47             if not m.has_key(msgid):
48                 messages.append(msgid)
49     if not messages:
50         return
52     # send a copy to the nosy list
53     for msgid in messages:
54         cl.sendmessage(nodeid, msgid)
56     # update the nosy list with the recipients from the new messages
57     nosy = cl.get(nodeid, 'nosy')
58     n = {}
59     for nosyid in nosy: n[nosyid] = 1
60     change = 0
61     # but don't add admin to the nosy list
62     for msgid in messages:
63         for recipid in db.msg.get(msgid, 'recipients'):
64             if recipid != '1' and not n.has_key(recipid):
65                 change = 1
66                 nosy.append(recipid)
67         authid = db.msg.get(msgid, 'author')
68         if authid != '1' and not n.has_key(authid):
69             change = 1
70             nosy.append(authid)
71     if change:
72         cl.set(nodeid, nosy=nosy)
75 def init(db):
76     db.issue.react('create', nosyreaction)
77     db.issue.react('set', nosyreaction)
79 #
80 #$Log: not supported by cvs2svn $
81 #Revision 1.1  2001/07/23 03:50:47  anthonybaxter
82 #moved templates to proper location
83 #
84 #Revision 1.1  2001/07/22 12:09:32  richard
85 #Final commit of Grande Splite
86 #
87 #