From 42bf33b1ef9777ece3b8b1c8c77a700be8c84cd8 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Fri, 20 May 2011 10:28:23 +0200 Subject: [PATCH] SONAR-2449 'updated_at' attribute of a review is not always updated It was not updated when a comment is added, edited or deleted. Now it is the case. --- .../app/controllers/reviews_controller.rb | 24 ++++++------------- .../main/webapp/WEB-INF/app/models/review.rb | 22 +++++++++++++++++ 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb index 48bcf107ba7..7097953cba0 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb @@ -97,15 +97,11 @@ class ReviewsController < ApplicationController end if params[:comment_id] - comment = @review.comments.find(params[:comment_id].to_i) - if comment - comment.text=params[:text] - comment.save! - end + @review.edit_comment(params[:comment_id].to_i, params[:text]) else - @review.comments.create!(:user => current_user, :text => params[:text]) + @review.create_comment(:user => current_user, :text => params[:text]) end - + render :partial => "reviews/view" end @@ -146,8 +142,7 @@ class ReviewsController < ApplicationController end if @review - comment=@review.comments.find(params[:comment_id].to_i) - comment.delete if comment + @review.delete_comment(params[:comment_id].to_i) end render :partial => "reviews/view" end @@ -245,13 +240,9 @@ class ReviewsController < ApplicationController end if params[:comment_id] - comment=violation.review.comments.find(params[:comment_id].to_i) - if comment - comment.text=params[:text] - comment.save! - end + violation.review.edit_comment(params[:comment_id].to_i, params[:text]) else - violation.review.comments.create!(:user => current_user, :text => params[:text]) + violation.review.create_comment(:user => current_user, :text => params[:text]) end render :partial => "resource/violation", :locals => { :violation => violation } @@ -266,8 +257,7 @@ class ReviewsController < ApplicationController end sanitize_violation(violation) if violation.review - comment=violation.review.comments.find(params[:comment_id].to_i) - comment.delete if comment + violation.review.delete_comment(params[:comment_id].to_i) end render :partial => "resource/violation", :locals => { :violation => violation } end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb index 3fe1de33f86..55d7dce4efe 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb @@ -49,6 +49,28 @@ class Review < ActiveRecord::Base end end + def create_comment(options={}) + comments.create!(options) + touch + end + + def edit_comment(comment_id, comment_text) + comment=comments.find(comment_id) + if comment + comment.text=comment_text + comment.save! + touch + end + end + + def delete_comment(comment_id) + comment=comments.find(comment_id) + if comment + comment.delete + touch + end + end + def self.search(options={}) conditions=[] values={} -- 2.39.5