Edgewall Software

Ticket #454: 454-save-edit-history-r8561.patch

File 454-save-edit-history-r8561.patch, 6.2 KB (added by rblank, 2 years ago)

Save comment edit history in _comment{n} pseudo-fields.

  • trac/htdocs/css/ticket.css

    diff --git a/trac/htdocs/css/ticket.css b/trac/htdocs/css/ticket.css
    a b  
    8787} 
    8888.threading, #changelog .inlinebuttons { float: right; } 
    8989.threading { font-size: 85%; } 
     90#changelog .trac-lastedit { 
     91 margin-left: 1em; 
     92 color: #999; 
     93 font-size: 90%; 
     94} 
     95#changelog .trac-lastedit :link, #changelog .trac-lastedit :visited { color: inherit } 
    9096 
    9197#preview .changes, #changelog .changes { list-style: square; margin-left: 2em; padding: 0 } 
    9298#preview .comment, #changelog .comment { margin-left: 2em } 
  • trac/ticket/model.py

    diff --git a/trac/ticket/model.py b/trac/ticket/model.py
    a b  
    367367        for listener in TicketSystem(self.env).change_listeners: 
    368368            listener.ticket_deleted(self) 
    369369 
    370     def modify_comment(self, cnum, comment, db=None): 
     370    def modify_comment(self, cnum, author, comment, when=None, db=None): 
     371        scnum = str(cnum) 
     372        if when is None: 
     373            when = datetime.now(utc) 
     374        when_ts = to_timestamp(when) 
     375         
    371376        db, handle_ta = self._get_db_for_write(db) 
     377        like = db.like() 
    372378        cursor = db.cursor() 
    373         cursor.execute("UPDATE ticket_change SET newvalue=%%s " 
     379        cursor.execute("SELECT time,newvalue FROM ticket_change " 
    374380                       "WHERE ticket=%%s AND field='comment' " 
    375                        "  AND (oldvalue=%%s OR oldvalue %s)" 
    376                        % db.like(), 
    377                        (comment, self.id, str(cnum), 
    378                         '%.' + db.like_escape(str(cnum)))) 
     381                       "  AND (oldvalue=%%s OR oldvalue %s)" % like, 
     382                       (self.id, scnum, '%.' + db.like_escape(scnum))) 
     383        for (ts, old_comment) in cursor: 
     384            cursor.execute("SELECT COUNT(ticket) FROM ticket_change " 
     385                           "WHERE ticket=%%s AND time=%%s AND field %s" % like, 
     386                           (self.id, ts, db.like_escape('_comment') + '%')) 
     387            rev = cursor.fetchone()[0] 
     388            cursor.execute("INSERT INTO ticket_change " 
     389                           "(ticket,time,author,field,oldvalue,newvalue) " 
     390                           "VALUES (%s,%s,%s,%s,%s,%s)", 
     391                           (self.id, ts, author, '_comment%d' % rev, 
     392                            old_comment, str(when_ts))) 
     393            cursor.execute("UPDATE ticket_change SET newvalue=%s " 
     394                           "WHERE ticket=%s AND time=%s AND field='comment'", 
     395                           (comment, self.id, ts)) 
     396            break 
    379397        if handle_ta: 
    380398            db.commit()   
    381399 
  • trac/ticket/templates/ticket.html

    diff --git a/trac/ticket/templates/ticket.html b/trac/ticket/templates/ticket.html
    a b  
    216216          <h2>Change History</h2> 
    217217          <div id="changelog"> 
    218218            <py:for each="change in changes"> 
    219               <div class="change"> 
     219              <div class="change" py:with="show_editor = can_edit_comment and str(change.cnum) == cnum_edit"> 
    220220                <h3 class="change"> 
    221221                  <span class="threading" py:if="'cnum' in change" 
    222222                        py:with="change_replies = replies.get(str(change.cnum), [])"> 
     
    234234                  </span> 
    235235                  <i18n:msg params="date, author">Changed ${dateinfo(change.date)} ago by ${authorinfo(change.author)}</i18n:msg> 
    236236                </h3> 
    237                 <div py:if="not (can_edit_comment and str(change.cnum) == cnum_edit)" class="inlinebuttons"> 
     237                <div py:if="not show_editor" class="inlinebuttons"> 
    238238                  <form py:if="'cnum' in change and can_append"  
    239239                        method="get" action="#comment" class="inlinebuttons"> 
    240240                    <div> 
     
    251251                  </form>               
    252252                </div> 
    253253                ${display_change(change)} 
    254                 <form py:if="can_edit_comment and str(change.cnum) == cnum_edit" method="post" action="#comment:${change.cnum}"> 
     254                <div py:if="not show_editor and change.last_edit.rev >= 0" i18n:msg="date, author" class="trac-lastedit"> 
     255                  Last edited ${dateinfo(change.last_edit.date)} ago by ${authorinfo(change.last_edit.author)} 
     256                  (<a href="">diff</a>) 
     257                </div> 
     258                <form py:if="show_editor" method="post" action="#comment:${change.cnum}"> 
    255259                  <div> 
    256260                    <textarea id="trac-edited_comment" name="edited_comment" class="wikitext" rows="10" cols="78"> 
    257261${[edited_comment, change.comment][edited_comment is None]}</textarea> 
  • trac/ticket/web_ui.py

    diff --git a/trac/ticket/web_ui.py b/trac/ticket/web_ui.py
    a b  
    492492                req.perm(ticket.resource).require('TICKET_EDIT_COMMENT') 
    493493                comment = req.args.get('edited_comment') 
    494494                cnum = req.args.get('cnum_edit') 
    495                 ticket.modify_comment(cnum, comment) 
     495                ticket.modify_comment(cnum, req.authname, comment) 
    496496                req.redirect(req.href.ticket(ticket.id)) 
    497497 
    498498            # Do any action on the ticket? 
     
    14681468                    yield current 
    14691469                last_uid = uid 
    14701470                current = {'date': date, 'author': author, 'fields': {}, 
    1471                            'permanent': permanent, 'comment': ''} 
     1471                           'permanent': permanent, 'comment': '', 
     1472                           'last_edit': {'rev': -1}} 
    14721473                if permanent and not when: 
    14731474                    autonum += 1 
    14741475                    current['cnum'] = autonum 
     
    14821483                    else: 
    14831484                        this_num = old 
    14841485                    current['cnum'] = int(this_num) 
     1486            elif field.startswith('_comment'):      # Comment edits 
     1487                rev = int(field[8:]) 
     1488                if rev > current['last_edit']['rev']: 
     1489                    last_edit = datetime.fromtimestamp(int(new), utc) 
     1490                    current['last_edit'] = {'rev': rev, 'author': author, 
     1491                                            'date': last_edit} 
    14851492            elif old or new: 
    14861493                current['fields'][field] = {'old': old, 'new': new} 
    14871494        if current: