Code

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