Ticket #454: comment_edit.patch
| File comment_edit.patch, 10.7 KB (added by David Sorber <baranovich@…>, 3 years ago) |
|---|
-
trac/ticket/api.py
354 354 def get_permission_actions(self): 355 355 return ['TICKET_APPEND', 'TICKET_CREATE', 'TICKET_CHGPROP', 356 356 'TICKET_VIEW', 'TICKET_EDIT_CC', 'TICKET_EDIT_DESCRIPTION', 357 'TICKET_EDIT_COMMENT', 357 358 ('TICKET_MODIFY', ['TICKET_APPEND', 'TICKET_CHGPROP']), 358 359 ('TICKET_ADMIN', ['TICKET_CREATE', 'TICKET_MODIFY', 359 360 'TICKET_VIEW', 'TICKET_EDIT_CC', 360 'TICKET_EDIT_DESCRIPTION'])] 361 'TICKET_EDIT_DESCRIPTION', 362 'TICKET_EDIT_COMMENT'])] 361 363 362 364 # IWikiSyntaxProvider methods 363 365 -
trac/ticket/web_ui.py
39 39 from trac.timeline.api import ITimelineEventProvider 40 40 from trac.util import get_reporter_id 41 41 from trac.util.compat import any 42 from trac.util.datefmt import format_datetime, to_timestamp, utc 42 from trac.util.datefmt import parse_date, pretty_timedelta, to_datetime, \ 43 format_datetime, to_timestamp, utc 43 44 from trac.util.text import CRLF, shorten_line, obfuscate_email_address, \ 44 45 exception_to_unicode 45 46 from trac.util.presentation import separated … … 474 475 return self._render_history(req, ticket, data, text_fields) 475 476 elif action == 'diff': 476 477 return self._render_diff(req, ticket, data, text_fields) 477 elif req.method == 'POST': # 'Preview' or 'Submit' 478 # Comment edit preview is a special case, similar to 'View' action 479 elif (req.method == 'POST' and 'preview_comment' in req.args and 480 'TICKET_EDIT_COMMENT' in req.perm(ticket.resource)): 481 data['comment_preview'] = req.args.get('edited_comment') 482 data['cnum_edit'] = req.args.get('comment_num') 483 field_changes = {} 484 elif req.method == 'POST': # 'Preview' or 'Submit' or Comment Edit 485 # Cancel comment edit 486 if 'cancel_comment' in req.args: 487 req.redirect(req.href.ticket(ticket.id)) 488 # Edit a ticket comment 489 elif ('edit_comment' in req.args and 490 'TICKET_EDIT_COMMENT' in req.perm(ticket.resource)): 491 author = req.args.get('comment_author') 492 if (author == req.authname or 493 'TRAC_ADMIN' in req.perm(ticket.resource)): 494 comment = req.args.get('edited_comment') 495 comment += "^^%s&%s^^" % (to_timestamp(datetime.now(utc)), 496 get_reporter_id(req, 'author')) 497 when = req.args.get('edit_comment_when') 498 when_ts = to_timestamp(parse_date(when, req.tz)) 499 ticket.edit_comment(comment, when_ts) 500 req.redirect(req.href.ticket(ticket.id)) 501 478 502 # Do any action on the ticket? 479 503 actions = TicketSystem(self.env).get_available_actions( 480 504 req, ticket) … … 1214 1238 """Insert ticket data into the template `data`""" 1215 1239 replyto = req.args.get('replyto') 1216 1240 data['replyto'] = replyto 1241 if req.args.get('cnum_edit'): 1242 data['cnum_edit'] = req.args.get('cnum_edit') 1217 1243 data['version'] = ticket.resource.version 1218 1244 data['description_change'] = None 1219 1245 … … 1442 1468 current['cnum'] = autonum 1443 1469 # some common processing for fields 1444 1470 if field == 'comment': 1471 # find comments that have been edited and create pretty 1472 # "edited by" messages for them 1473 m = re.search('\^\^(.+?)\&(.+?)\^\^$', new) 1474 if m: 1475 ts = int(m.group(1)) 1476 user = m.group(2) 1477 verb = 'Edited' 1478 if re.search('^\^\^(.+?)\&(.+?)\^\^$', new): 1479 verb = 'Comment removed' # Comment is empty! 1480 current['comment_edited'] = ("\n\n''%s %s ago by %s.''" 1481 % (verb, pretty_timedelta(to_datetime(ts)), user)) 1482 new = new[:m.start(0)] 1445 1483 current['comment'] = new 1446 1484 if old: 1447 1485 if '.' in old: # retrieve parent.child relationship -
trac/ticket/model.py
363 363 364 364 for listener in TicketSystem(self.env).change_listeners: 365 365 listener.ticket_deleted(self) 366 367 def edit_comment(self, cmt, ts, db=None): 368 db, handle_ta = self._get_db_for_write(db) 369 cursor = db.cursor() 366 370 371 cursor.execute("UPDATE ticket_change SET newvalue=%s " 372 "WHERE ticket=%s AND time=%s AND field='comment'", 373 (cmt, self.id, ts)) 374 if handle_ta: 375 db.commit() 367 376 368 377 def simplify_whitespace(name): 369 378 """Strip spaces and remove duplicate spaces within names""" -
trac/ticket/templates/ticket.html
48 48 <a href="#comment:$cnum">$prefix$cnum</a> 49 49 </py:def> 50 50 51 <py:def function="display_change(change )">51 <py:def function="display_change(change, edit_cnum=0)"> 52 52 <ul py:if="change.fields" class="changes"> 53 53 <li py:for="field_name, field in change.fields.items()"> 54 54 <strong>${field_name}</strong> … … 69 69 </py:choose> 70 70 </li> 71 71 </ul> 72 <div py:if="'comment' in change" class="comment searchable" xml:space="preserve"> 73 ${wiki_to_html(context, change.comment, escape_newlines=preserve_newlines)} 72 <div py:if="'comment' in change and (str(change.cnum) != cnum_edit or comment_preview)" class="comment searchable ${(comment_preview and cnum_edit == str(change.cnum)) and 'ticketdraft'}" xml:space="preserve"> 73 <py:choose test="comment_preview and cnum_edit == str(change.cnum)"> 74 <py:when>${wiki_to_html(context, comment_preview, escape_newlines=preserve_newlines)}</py:when> 75 <py:otherwise>${wiki_to_html(context, change.comment, escape_newlines=preserve_newlines)}</py:otherwise> 76 </py:choose> 77 <py:if test="change.comment_edited and not (comment_preview and cnum_edit == str(change.cnum))"> 78 ${wiki_to_html(context, change.comment_edited, escape_newlines=preserve_newlines)} 79 </py:if> 74 80 </div> 75 81 </py:def> 76 82 … … 204 210 <py:if test="ticket.exists and changes"> 205 211 <h2>Change History</h2> 206 212 <div id="changelog"> 207 < form py:for="change in changes" method="get" action="#comment" class="printableform">213 <py:for each="change in changes" class="printableform"> 208 214 <div class="change"> 209 215 <h3 class="change"> 210 216 <span class="threading" py:if="'cnum' in change" … … 223 229 </span> 224 230 Changed ${dateinfo(change.date)} ago by ${authorinfo(change.author)} 225 231 </h3> 226 <div py:if="'cnum' in change and 'TICKET_APPEND' in perm(ticket.resource)" class="inlinebuttons"> 227 <input type="hidden" name="replyto" value="${change.cnum}" /> 228 <input type="submit" value="${_('Reply')}" title="Reply to comment ${change.cnum}" /> 232 <div class="inlinebuttons"> 233 <form py:if="'cnum' in change and 'TICKET_APPEND' in perm(ticket.resource)" 234 method="get" action="#comment" class="changelogbuttons"> 235 <input type="hidden" name="replyto" value="${change.cnum}" /> 236 <input type="submit" value="${_('Reply')}" title="Reply to comment ${change.cnum}" /> 237 </form> 238 <form py:if="'TICKET_EDIT_COMMENT' in perm(ticket.resource) and 239 (authname == change.author or 'TRAC_ADMIN' in perm(ticket.resource))" 240 method="get" action="#comment:${change.cnum}" class="changelogbuttons"> 241 <input type="hidden" name="cnum_edit" value="${change.cnum}" /> 242 <input type="submit" value="${_('Edit')}" title="Edit comment ${change.cnum}" /> 243 </form> 229 244 </div> 230 ${display_change(change)} 245 ${display_change(change, ('TICKET_EDIT_COMMENT' in perm(ticket.resource) and cnum_edit or 0))} 246 <form method="post" py:if="'TICKET_EDIT_COMMENT' in perm(ticket.resource) and str(change.cnum) == cnum_edit"> 247 <p> 248 <py:choose test="comment_preview"> 249 <py:when><textarea name="edited_comment" class="wikitext" rows="10" cols="78">${comment_preview}</textarea></py:when> 250 <py:otherwise><textarea name="edited_comment" class="wikitext" rows="10" cols="78">${change.comment}</textarea></py:otherwise> 251 </py:choose> 252 </p> 253 <input type="hidden" name="edit_comment_when" value="${change.date.isoformat()}" /> 254 <input type="hidden" name="comment_author" value="${change.author}" /> 255 <input type="hidden" name="comment_num" value="${change.cnum}" /> 256 <input type="submit" name="preview_comment" value="${_('Preview')}" title='Preview changes to comment ${change.cnum}' /> 257 <input type="submit" name="edit_comment" value="${_('Submit changes')}" title="Submit changes to comment ${change.cnum}" /> 258 <input type="submit" name="cancel_comment" value="${_('Cancel')}" title="Cancel comment edit" /> 259 </form> 231 260 </div> 232 </ form>261 </py:for> 233 262 </div> 234 263 </py:if> 235 264 </py:if> -
trac/htdocs/css/ticket.css
76 76 } 77 77 78 78 #changelog { border: 1px outset #996; padding: 1em } 79 #changelog .changelogbuttons { 80 display: inline; 81 } 79 82 #preview { border: 1px solid #d7d7d7; padding: 1em } 80 83 #preview h3, #changelog h3 { 81 84 border-bottom: 1px solid #d7d7d7;
