From e94923b9290d403435e9f6c555b2bb0aaaaaf00b Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Mon, 23 May 2011 16:50:07 +0200 Subject: [PATCH] SONAR-2462 Leave false-positive review open until violation removed A "False-Positive" review should be closed only when the underlying violation disappears --- .../app/controllers/reviews_controller.rb | 7 ++-- .../main/webapp/WEB-INF/app/models/review.rb | 32 +++++++++++++++++-- .../reviews/_false_positive_form.html.erb | 3 ++ .../app/views/reviews/_review.html.erb | 13 ++++++-- 4 files changed, 45 insertions(+), 10 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 355fbb66ce8..58fe6a6190e 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 @@ -118,13 +118,13 @@ class ReviewsController < ApplicationController return end + false_positive=(params[:false_positive]=='true') RuleFailure.find( :all, :conditions => [ "permanent_id = ?", @review.rule_failure_permanent_id ] ).each do |violation| - violation.switched_off=true + violation.switched_off=false_positive violation.save! end - @review.review_type = Review::TYPE_FALSE_POSITIVE - @review.status = Review::STATUS_CLOSED + @review.review_type = (false_positive ? Review::TYPE_FALSE_POSITIVE : Review::TYPE_VIOLATION) @review.assignee = nil @review.save! unless params[:comment].blank? @@ -206,7 +206,6 @@ class ReviewsController < ApplicationController violation.build_review(:user_id => current_user.id) end violation.review.review_type=(false_positive ? Review::TYPE_FALSE_POSITIVE : Review::TYPE_VIOLATION) - violation.review.status=(false_positive ? Review::STATUS_CLOSED : Review::STATUS_OPEN) violation.review.assignee=nil violation.review.save! violation.review.comments.create(:review_text => params[:comment], :user_id => current_user.id) 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 c284662f3ad..7fecb7d342a 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,14 @@ class Review < ActiveRecord::Base end end + + + # + # + # REVIEW CORE METHODS + # + # + def create_comment(options={}) comments.create!(options) touch @@ -71,6 +79,14 @@ class Review < ActiveRecord::Base end end + + + # + # + # SEARCH METHODS + # + # + def self.search(options={}) conditions=[] values={} @@ -160,6 +176,14 @@ class Review < ActiveRecord::Base Review.find(:all, :include => [ 'review_comments', 'project', 'assignee', 'resource', 'user' ], :conditions => [conditions.join(' AND '), values], :order => sort, :limit => 200) end + + + # + # + # XML AND JSON UTILITY METHODS + # + # + def self.reviews_to_xml(reviews, convert_markdown=false) xml = Builder::XmlMarkup.new(:indent => 0) xml.instruct! @@ -230,11 +254,13 @@ class Review < ActiveRecord::Base - + # + # + # PRIVATE METHODS + # + # private - - def assign_project if self.project.nil? && self.resource self.project=self.resource.root_project diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_false_positive_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_false_positive_form.html.erb index 98f329bd088..c173a770296 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_false_positive_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_false_positive_form.html.erb @@ -1,5 +1,8 @@
+ <% if params[:false_positive]=='true' -%> + + <% end %>

Why is it a false-positive ?

<%= submit_to_remote "submit_btn", "Flag as false-positive", :url => { :action => 'flag_as_false_positive' }, :html => { :id => "submit_btn", :disabled => "true" }, :update => 'review' -%> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb index b5f69900cbf..ef3ea5b72fa 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb @@ -2,19 +2,26 @@

Review #<%= h(review.id.to_s) -%> - <%= h(review.title) -%>

- <% if current_user && review.status != "CLOSED" %> + <% + if current_user && review.status != "CLOSED" && review.rule_failure + violation_switched_off = review.rule_failure.switched_off? + %>   <%= image_tag("sep12.png") -%>   + <% + if !violation_switched_off + %> <%= link_to_remote (review.assignee_id ? "Reassign" : "Assign"), :url => { :controller => "reviews", :action => "assign_form", :review_id => review.id}, :update => "assignForm", :complete => "$('rActions').hide(); $('editActions').hide(); $('assignee_id').focus();" -%>   - <%= link_to_remote ("Flag as false-positive"), - :url => { :controller => "reviews", :action => "false_positive_form", :id => review.id }, + <% end %> + <%= link_to_remote (violation_switched_off ? "Unflag as false-positive" : "Flag as false-positive"), + :url => { :controller => "reviews", :action => "false_positive_form", :id => review.id, :false_positive => !violation_switched_off }, :update => "reviewForm", :complete => "$('reviewForm').show(); $('rActions').hide(); $('editActions').hide(); $('commentText').focus();" -%> -- 2.39.5