Code

Removed generation of change note from "sendmessage" in roundupdb.py.
[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.8 2001-12-05 14:26:44 rochecompaan 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     if oldvalues is None:
39         # the action was a create, so use all the messages in the create
40         messages = cl.get(nodeid, 'messages')
41     elif oldvalues.has_key('messages'):
42         # the action was a set (so adding new messages to an existing issue)
43         m = {}
44         for msgid in oldvalues['messages']:
45             m[msgid] = 1
46         messages = []
47         # figure which of the messages now on the issue weren't there before
48         for msgid in cl.get(nodeid, 'messages'):
49             if not m.has_key(msgid):
50                 messages.append(msgid)
51     if not messages:
52         return
54     # send a copy to the nosy list
55     for msgid in messages:
56         try:
57             cl.sendmessage(nodeid, msgid)
58         except roundupdb.MessageSendError, message:
59             raise roundupdb.DetectorError, message
61     # update the nosy list with the recipients from the new messages
62     nosy = cl.get(nodeid, 'nosy')
63     n = {}
64     for nosyid in nosy: n[nosyid] = 1
65     change = 0
66     # but don't add admin or the anonymous user to the nosy list
67     for msgid in messages:
68         for recipid in db.msg.get(msgid, 'recipients'):
69             if recipid == '1': continue
70             if n.has_key(recipid): continue
71             if db.user.get(recipid, 'username') == 'anonymous': continue
72             change = 1
73             nosy.append(recipid)
74         authid = db.msg.get(msgid, 'author')
75         if authid == '1': continue
76         if n.has_key(authid): continue
77         if db.user.get(authid, 'username') == 'anonymous': continue
78         change = 1
79         # append the author only after issue creation
80         if oldvalues is None:
81             nosy.append(authid)
82     if change:
83         cl.set(nodeid, nosy=nosy)
86 def init(db):
87     db.issue.react('create', nosyreaction)
88     db.issue.react('set', nosyreaction)
90 #
91 #$Log: not supported by cvs2svn $
92 #Revision 1.7  2001/11/30 11:29:04  rochecompaan
93 #Property changes are now listed in emails generated by Roundup
94 #
95 #Revision 1.6  2001/11/26 22:55:56  richard
96 #Feature:
97 # . Added INSTANCE_NAME to configuration - used in web and email to identify
98 #   the instance.
99 # . Added EMAIL_SIGNATURE_POSITION to indicate where to place the roundup
100 #   signature info in e-mails.
101 # . Some more flexibility in the mail gateway and more error handling.
102 # . Login now takes you to the page you back to the were denied access to.
104 #Fixed:
105 # . Lots of bugs, thanks Roché and others on the devel mailing list!
107 #Revision 1.5  2001/11/12 22:01:07  richard
108 #Fixed issues with nosy reaction and author copies.
110 #Revision 1.4  2001/10/30 00:54:45  richard
111 #Features:
112 # . #467129 ] Lossage when username=e-mail-address
113 # . #473123 ] Change message generation for author
114 # . MailGW now moves 'resolved' to 'chatting' on receiving e-mail for an issue.
116 #Revision 1.3  2001/08/07 00:24:43  richard
117 #stupid typo
119 #Revision 1.2  2001/08/07 00:15:51  richard
120 #Added the copyright/license notice to (nearly) all files at request of
121 #Bizar Software.
123 #Revision 1.1  2001/07/23 23:29:10  richard
124 #Adding the classic template
126 #Revision 1.1  2001/07/23 03:50:47  anthonybaxter
127 #moved templates to proper location
129 #Revision 1.1  2001/07/22 12:09:32  richard
130 #Final commit of Grande Splite