Code

c5c818ebb47f671dd6e49be3edd2dba79214c02d
[roundup.git] / roundup / templates / classic / 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 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.11 2002-01-14 22:21:38 richard Exp $
20 from roundup import roundupdb
22 def nosyreaction(db, cl, nodeid, oldvalues):
23     ''' A standard detector is provided that watches for additions to the
24         "messages" property.
25         
26         When a new message is added, the detector sends it to all the users on
27         the "nosy" list for the issue that are not already on the "recipients"
28         list of the message.
29         
30         Those users are then appended to the "recipients" property on the
31         message, so multiple copies of a message are never sent to the same
32         user.
33         
34         The journal recorded by the hyperdatabase on the "recipients" property
35         then provides a log of when the message was sent to whom. 
36     '''
37     messages = []
38     change_note = ''
39     if oldvalues is None:
40         # the action was a create, so use all the messages in the create
41         messages = cl.get(nodeid, 'messages')
42         change_note = cl.generateCreateNote(nodeid)
43     elif oldvalues.has_key('messages'):
44         # the action was a set (so adding new messages to an existing issue)
45         m = {}
46         for msgid in oldvalues['messages']:
47             m[msgid] = 1
48         messages = []
49         # figure which of the messages now on the issue weren't there before
50         for msgid in cl.get(nodeid, 'messages'):
51             if not m.has_key(msgid):
52                 messages.append(msgid)
53         if messages:
54             change_note = cl.generateChangeNote(nodeid, oldvalues)
55     if not messages:
56         return
58     # send a copy to the nosy list
59     for msgid in messages:
60         try:
61             cl.sendmessage(nodeid, msgid, change_note)
62         except roundupdb.MessageSendError, message:
63             raise roundupdb.DetectorError, message
65 def init(db):
66     db.issue.react('create', nosyreaction)
67     db.issue.react('set', nosyreaction)
69 #
70 #$Log: not supported by cvs2svn $
71 #Revision 1.10  2002/01/11 23:22:29  richard
72 # . #502437 ] rogue reactor and unittest
73 #   in short, the nosy reactor was modifying the nosy list. That code had
74 #   been there for a long time, and I suspsect it was there because we
75 #   weren't generating the nosy list correctly in other places of the code.
76 #   We're now doing that, so the nosy-modifying code can go away from the
77 #   nosy reactor.
78 #
79 #Revision 1.9  2001/12/15 19:24:39  rochecompaan
80 # . Modified cgi interface to change properties only once all changes are
81 #   collected, files created and messages generated.
82 # . Moved generation of change note to nosyreactors.
83 # . We now check for changes to "assignedto" to ensure it's added to the
84 #   nosy list.
85 #
86 #Revision 1.8  2001/12/05 14:26:44  rochecompaan
87 #Removed generation of change note from "sendmessage" in roundupdb.py.
88 #The change note is now generated when the message is created.
89 #
90 #Revision 1.7  2001/11/30 11:29:04  rochecompaan
91 #Property changes are now listed in emails generated by Roundup
92 #
93 #Revision 1.6  2001/11/26 22:55:56  richard
94 #Feature:
95 # . Added INSTANCE_NAME to configuration - used in web and email to identify
96 #   the instance.
97 # . Added EMAIL_SIGNATURE_POSITION to indicate where to place the roundup
98 #   signature info in e-mails.
99 # . Some more flexibility in the mail gateway and more error handling.
100 # . Login now takes you to the page you back to the were denied access to.
102 #Fixed:
103 # . Lots of bugs, thanks Roché and others on the devel mailing list!
105 #Revision 1.5  2001/11/12 22:01:07  richard
106 #Fixed issues with nosy reaction and author copies.
108 #Revision 1.4  2001/10/30 00:54:45  richard
109 #Features:
110 # . #467129 ] Lossage when username=e-mail-address
111 # . #473123 ] Change message generation for author
112 # . MailGW now moves 'resolved' to 'chatting' on receiving e-mail for an issue.
114 #Revision 1.3  2001/08/07 00:24:43  richard
115 #stupid typo
117 #Revision 1.2  2001/08/07 00:15:51  richard
118 #Added the copyright/license notice to (nearly) all files at request of
119 #Bizar Software.
121 #Revision 1.1  2001/07/23 23:29:10  richard
122 #Adding the classic template
124 #Revision 1.1  2001/07/23 03:50:47  anthonybaxter
125 #moved templates to proper location
127 #Revision 1.1  2001/07/22 12:09:32  richard
128 #Final commit of Grande Splite