Ticket #454: 454-save-edit-history-r8561.patch
| File 454-save-edit-history-r8561.patch, 6.2 KB (added by rblank, 2 years ago) |
|---|
-
trac/htdocs/css/ticket.css
diff --git a/trac/htdocs/css/ticket.css b/trac/htdocs/css/ticket.css
a b 87 87 } 88 88 .threading, #changelog .inlinebuttons { float: right; } 89 89 .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 } 90 96 91 97 #preview .changes, #changelog .changes { list-style: square; margin-left: 2em; padding: 0 } 92 98 #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 367 367 for listener in TicketSystem(self.env).change_listeners: 368 368 listener.ticket_deleted(self) 369 369 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 371 376 db, handle_ta = self._get_db_for_write(db) 377 like = db.like() 372 378 cursor = db.cursor() 373 cursor.execute(" UPDATE ticket_change SET newvalue=%%s"379 cursor.execute("SELECT time,newvalue FROM ticket_change " 374 380 "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 379 397 if handle_ta: 380 398 db.commit() 381 399 -
trac/ticket/templates/ticket.html
diff --git a/trac/ticket/templates/ticket.html b/trac/ticket/templates/ticket.html
a b 216 216 <h2>Change History</h2> 217 217 <div id="changelog"> 218 218 <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"> 220 220 <h3 class="change"> 221 221 <span class="threading" py:if="'cnum' in change" 222 222 py:with="change_replies = replies.get(str(change.cnum), [])"> … … 234 234 </span> 235 235 <i18n:msg params="date, author">Changed ${dateinfo(change.date)} ago by ${authorinfo(change.author)}</i18n:msg> 236 236 </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"> 238 238 <form py:if="'cnum' in change and can_append" 239 239 method="get" action="#comment" class="inlinebuttons"> 240 240 <div> … … 251 251 </form> 252 252 </div> 253 253 ${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}"> 255 259 <div> 256 260 <textarea id="trac-edited_comment" name="edited_comment" class="wikitext" rows="10" cols="78"> 257 261 ${[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 492 492 req.perm(ticket.resource).require('TICKET_EDIT_COMMENT') 493 493 comment = req.args.get('edited_comment') 494 494 cnum = req.args.get('cnum_edit') 495 ticket.modify_comment(cnum, comment)495 ticket.modify_comment(cnum, req.authname, comment) 496 496 req.redirect(req.href.ticket(ticket.id)) 497 497 498 498 # Do any action on the ticket? … … 1468 1468 yield current 1469 1469 last_uid = uid 1470 1470 current = {'date': date, 'author': author, 'fields': {}, 1471 'permanent': permanent, 'comment': ''} 1471 'permanent': permanent, 'comment': '', 1472 'last_edit': {'rev': -1}} 1472 1473 if permanent and not when: 1473 1474 autonum += 1 1474 1475 current['cnum'] = autonum … … 1482 1483 else: 1483 1484 this_num = old 1484 1485 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} 1485 1492 elif old or new: 1486 1493 current['fields'][field] = {'old': old, 'new': new} 1487 1494 if current:
