"Fossies" - the Fresh Open Source Software Archive

Member "roundup-2.0.0/share/roundup/templates/jinja2/detectors/nosyreaction.py" (26 Aug 2019, 5431 Bytes) of package /linux/www/roundup-2.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "nosyreaction.py": 1.6.1_vs_2.0.0.

    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 
   19 from roundup import roundupdb, hyperdb
   20 
   21 def nosyreaction(db, cl, nodeid, oldvalues):
   22     ''' A standard detector is provided that watches for additions to the
   23         "messages" property.
   24         
   25         When a new message is added, the detector sends it to all the users on
   26         the "nosy" list for the issue that are not already on the "recipients"
   27         list of the message.
   28         
   29         Those users are then appended to the "recipients" property on the
   30         message, so multiple copies of a message are never sent to the same
   31         user.
   32         
   33         The journal recorded by the hyperdatabase on the "recipients" property
   34         then provides a log of when the message was sent to whom. 
   35     '''
   36     # send a copy of all new messages to the nosy list
   37     for msgid in determineNewMessages(cl, nodeid, oldvalues):
   38         try:
   39             cl.nosymessage(nodeid, msgid, oldvalues)
   40         except roundupdb.MessageSendError as message:
   41             raise roundupdb.DetectorError(message)
   42 
   43 def determineNewMessages(cl, nodeid, oldvalues):
   44     ''' Figure a list of the messages that are being added to the given
   45         node in this transaction.
   46     '''
   47     messages = []
   48     if oldvalues is None:
   49         # the action was a create, so use all the messages in the create
   50         messages = cl.get(nodeid, 'messages')
   51     elif 'messages' in oldvalues:
   52         # the action was a set (so adding new messages to an existing issue)
   53         m = {}
   54         for msgid in oldvalues['messages']:
   55             m[msgid] = 1
   56         messages = []
   57         # figure which of the messages now on the issue weren't there before
   58         for msgid in cl.get(nodeid, 'messages'):
   59             if msgid not in m:
   60                 messages.append(msgid)
   61     return messages
   62 
   63 def updatenosy(db, cl, nodeid, newvalues):
   64     '''Update the nosy list for changes to the assignedto
   65     '''
   66     # nodeid will be None if this is a new node
   67     current_nosy = set()
   68     if nodeid is None:
   69         ok = ('new', 'yes')
   70     else:
   71         ok = ('yes',)
   72         # old node, get the current values from the node if they haven't
   73         # changed
   74         if 'nosy' not in newvalues:
   75             nosy = cl.get(nodeid, 'nosy')
   76             for value in nosy:
   77                 current_nosy.add(value)
   78 
   79     # if the nosy list changed in this transaction, init from the new value
   80     if 'nosy' in newvalues:
   81         nosy = newvalues.get('nosy', [])
   82         for value in nosy:
   83             if not db.hasnode('user', value):
   84                 continue
   85             current_nosy.add(value)
   86 
   87     new_nosy = set(current_nosy)
   88 
   89     # add assignedto(s) to the nosy list
   90     if 'assignedto' in newvalues and newvalues['assignedto'] is not None:
   91         propdef = cl.getprops()
   92         if isinstance(propdef['assignedto'], hyperdb.Link):
   93             assignedto_ids = [newvalues['assignedto']]
   94         elif isinstance(propdef['assignedto'], hyperdb.Multilink):
   95             assignedto_ids = newvalues['assignedto']
   96         for assignedto_id in assignedto_ids:
   97             new_nosy.add(assignedto_id)
   98 
   99     # see if there's any new messages - if so, possibly add the author and
  100     # recipient to the nosy
  101     if 'messages' in newvalues:
  102         if nodeid is None:
  103             ok = ('new', 'yes')
  104             messages = newvalues['messages']
  105         else:
  106             ok = ('yes',)
  107             # figure which of the messages now on the issue weren't
  108             oldmessages = cl.get(nodeid, 'messages')
  109             messages = []
  110             for msgid in newvalues['messages']:
  111                 if msgid not in oldmessages:
  112                     messages.append(msgid)
  113 
  114         # configs for nosy modifications
  115         add_author = getattr(db.config, 'ADD_AUTHOR_TO_NOSY', 'new')
  116         add_recips = getattr(db.config, 'ADD_RECIPIENTS_TO_NOSY', 'new')
  117 
  118         # now for each new message:
  119         msg = db.msg
  120         for msgid in messages:
  121             if add_author in ok:
  122                 authid = msg.get(msgid, 'author')
  123                 new_nosy.add(authid)
  124 
  125             # add on the recipients of the message
  126             if add_recips in ok:
  127                 for recipient in msg.get(msgid, 'recipients'):
  128                     new_nosy.add(recipient)
  129 
  130     if current_nosy != new_nosy:
  131         # that's it, save off the new nosy list
  132         newvalues['nosy'] = list(new_nosy)
  133 
  134 def init(db):
  135     db.issue.react('create', nosyreaction)
  136     db.issue.react('set', nosyreaction)
  137     db.issue.audit('create', updatenosy)
  138     db.issue.audit('set', updatenosy)
  139 
  140 # vim: set filetype=python ts=4 sw=4 et si