"Fossies" - the Fresh Open Source Software Archive

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