"Fossies" - the Fresh Open Source Software Archive

Member "roundup-2.0.0/share/roundup/templates/jinja2/detectors/statusauditor.py" (7 Nov 2019, 4705 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 "statusauditor.py": 1.6.1_vs_2.0.0.

    1 # Copyright (c) 2002 ekit.com Inc (http://www.ekit-inc.com/)
    2 #
    3 # Permission is hereby granted, free of charge, to any person obtaining a copy
    4 # of this software and associated documentation files (the "Software"), to deal
    5 # in the Software without restriction, including without limitation the rights
    6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    7 # copies of the Software, and to permit persons to whom the Software is
    8 # furnished to do so, subject to the following conditions:
    9 #
   10 #   The above copyright notice and this permission notice shall be included in
   11 #   all copies or substantial portions of the Software.
   12 #
   13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
   19 # SOFTWARE.
   20 #
   21 
   22 from roundup.configuration import BooleanOption, InvalidOptionError
   23 
   24 def chatty(db, cl, nodeid, newvalues):
   25     ''' If the issue is currently 'resolved', 'done-cbb' or None,
   26         then set it to 'chatting'. If issue is 'unread' and
   27         chatting_requires_two_users is true, set state
   28         to 'chatting' if the person adding the new message is not
   29         the same as the person who created the issue. This allows
   30         somebody to submit multiple emails describing the problem
   31         without changing it to 'chatting'. 'chatting' should
   32         indicate at least two people are 'chatting'.
   33     '''
   34     # If set to true, change state from 'unread' to 'chatting' only
   35     # if the author of the update is not the person who created the
   36     # first message (and thus the issue). If false (default ini file
   37     # setting) set 'chatting' when the second message is received.
   38     try:
   39         chatting_requires_two_users = BooleanOption(None,
   40                         "detector::Statusauditor",
   41                         "CHATTING_REQUIRES_TWO_USERS").str2value(
   42         db.config.detectors[
   43         'STATUSAUDITOR_CHATTING_REQUIRES_TWO_USERS' ]
   44     )
   45     except InvalidOptionError:
   46         raise InvalidOptionError("Option STATUSAUDITOR_CHATTING_REQUIRES_TWO_USERS not found in detectors/config.ini. Contact tracker admin to fix.")
   47         
   48     # don't fire if there's no new message (ie. chat)
   49     if 'messages' not in newvalues:
   50         return
   51     if newvalues['messages'] == cl.get(nodeid, 'messages'):
   52         return
   53 
   54     # get the chatting state ID
   55     try:
   56         chatting_id = db.status.lookup('chatting')
   57     except KeyError:
   58         # no chatting state, ignore all this stuff
   59         return
   60 
   61     # get the current value
   62     current_status = cl.get(nodeid, 'status')
   63 
   64     # see if there's an explicit change in this transaction
   65     if 'status' in newvalues:
   66         # yep, skip
   67         return
   68 
   69     # determine the id of 'unread', 'resolved' and 'chatting'
   70     fromstates = []
   71     for state in 'unread resolved done-cbb'.split():
   72         try:
   73             fromstates.append(db.status.lookup(state))
   74         except KeyError:
   75             pass
   76 
   77     unread = fromstates[0] # grab the 'unread' state which is first
   78 
   79     # ok, there's no explicit change, so check if we are in a state that
   80     # should be changed. First see if we should set 'chatting' based on
   81     # who opened the issue.
   82     if current_status == unread and chatting_requires_two_users:
   83         # find creator of issue and compare to currentuser making
   84         # update. If the creator is same as initial author don't
   85         # change to 'chatting'.
   86         issue_creator = cl.get(nodeid, 'creator')
   87         if issue_creator == db.getuid():
   88             # person is chatting with themselves, don't set 'chatting'
   89             return
   90 
   91     # Current author is not the initiator of the issue so
   92     # we are 'chatting'.
   93     if current_status in fromstates + [None]:
   94         # yep, we're now chatting
   95         newvalues['status'] = chatting_id
   96 
   97 
   98 def presetunread(db, cl, nodeid, newvalues):
   99     ''' Make sure the status is set on new issues
  100     '''
  101     if 'status' in newvalues and newvalues['status']:
  102         return
  103 
  104     # get the unread state ID
  105     try:
  106         unread_id = db.status.lookup('unread')
  107     except KeyError:
  108         # no unread state, ignore all this stuff
  109         return
  110 
  111     # ok, do it
  112     newvalues['status'] = unread_id
  113 
  114 
  115 def init(db):
  116     # fire before changes are made
  117     db.issue.audit('set', chatty)
  118     db.issue.audit('create', presetunread)
  119 
  120 # vim: set filetype=python ts=4 sw=4 et si