Code

b3030435a491db0a27eb71acf67e13cbbc37da05
[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 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
66 def init(db):
67     db.issue.react('create', nosyreaction)
68     db.issue.react('set', nosyreaction)
70 #
71 #$Log: not supported by cvs2svn $
72 #Revision 1.10  2002/01/11 23:22:29  richard
73 # . #502437 ] rogue reactor and unittest
74 #   in short, the nosy reactor was modifying the nosy list. That code had
75 #   been there for a long time, and I suspsect it was there because we
76 #   weren't generating the nosy list correctly in other places of the code.
77 #   We're now doing that, so the nosy-modifying code can go away from the
78 #   nosy reactor.
79 #
80 #Revision 1.9  2001/12/15 19:24:39  rochecompaan
81 # . Modified cgi interface to change properties only once all changes are
82 #   collected, files created and messages generated.
83 # . Moved generation of change note to nosyreactors.
84 # . We now check for changes to "assignedto" to ensure it's added to the
85 #   nosy list.
86 #
87 #Revision 1.8  2001/12/05 14:26:44  rochecompaan
88 #Removed generation of change note from "sendmessage" in roundupdb.py.
89 #The change note is now generated when the message is created.
90 #
91 #Revision 1.7  2001/11/30 11:29:04  rochecompaan
92 #Property changes are now listed in emails generated by Roundup
93 #
94 #Revision 1.6  2001/11/26 22:55:56  richard
95 #Feature:
96 # . Added INSTANCE_NAME to configuration - used in web and email to identify
97 #   the instance.
98 # . Added EMAIL_SIGNATURE_POSITION to indicate where to place the roundup
99 #   signature info in e-mails.
100 # . Some more flexibility in the mail gateway and more error handling.
101 # . Login now takes you to the page you back to the were denied access to.
103 #Fixed:
104 # . Lots of bugs, thanks Roché and others on the devel mailing list!
106 #Revision 1.5  2001/11/12 22:01:07  richard
107 #Fixed issues with nosy reaction and author copies.
109 #Revision 1.4  2001/10/30 00:54:45  richard
110 #Features:
111 # . #467129 ] Lossage when username=e-mail-address
112 # . #473123 ] Change message generation for author
113 # . MailGW now moves 'resolved' to 'chatting' on receiving e-mail for an issue.
115 #Revision 1.3  2001/08/07 00:24:43  richard
116 #stupid typo
118 #Revision 1.2  2001/08/07 00:15:51  richard
119 #Added the copyright/license notice to (nearly) all files at request of
120 #Bizar Software.
122 #Revision 1.1  2001/07/23 03:50:47  anthonybaxter
123 #moved templates to proper location
125 #Revision 1.1  2001/07/22 12:09:32  richard
126 #Final commit of Grande Splite