]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2462 Leave false-positive review open until violation removed
authorFabrice Bellingard <bellingard@gmail.com>
Mon, 23 May 2011 14:50:07 +0000 (16:50 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Mon, 23 May 2011 14:50:07 +0000 (16:50 +0200)
A "False-Positive" review should be closed only when the underlying
violation disappears

sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_false_positive_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb

index 355fbb66ce8eac263faf625c6df10548b1627a6f..58fe6a6190eca447ce75768ff0e2f15f09fee3d7 100644 (file)
@@ -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)
index c284662f3ad91ce27a7d7399704855981cc1b3d6..7fecb7d342ae3dc64a5be31b6f02b6fff8a95736 100644 (file)
@@ -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
index 98f329bd088e1877ed5ad0cbd5cbe742bc2b69b5..c173a77029610f1a73fe71355ed3967b1197ab7a 100644 (file)
@@ -1,5 +1,8 @@
 <form method="POST" action="violation_flag_as_false_positive">
   <input type="hidden" name="id" value="<%= params[:id] -%>"/>
+  <% if params[:false_positive]=='true' -%>
+    <input type="hidden" name="false_positive" value="true"/>
+  <% end %>
   <h3>Why is it a false-positive ?</h3>
   <textarea id="commentText" rows="8" name="comment" style="width: 100%" onkeyup="if (this.value=='') $('submit_btn').disabled='true'; else $('submit_btn').disabled='';"></textarea>
   <%= submit_to_remote "submit_btn", "Flag as false-positive", :url => { :action => 'flag_as_false_positive' }, :html => { :id => "submit_btn", :disabled => "true" }, :update => 'review' -%>
index b5f69900cbfcb0b8aa57ff1c496cdc1c926ebf77..ef3ea5b72fa533c19cbfe55141669ee26cb58fc4 100644 (file)
@@ -2,19 +2,26 @@
   <div class="reportTitle">
     <h2>Review #<%= h(review.id.to_s) -%> - <%= h(review.title) -%></h2>
     
-    <% if current_user && review.status != "CLOSED" %>
+    <% 
+      if current_user && review.status != "CLOSED" && review.rule_failure
+        violation_switched_off = review.rule_failure.switched_off?
+    %>
     <span class="actions" id="rActions">
         &nbsp;
         <%= image_tag("sep12.png") -%>
         &nbsp;
+        <% 
+          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();" -%>
       
         &nbsp;
-        <%= 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();" -%>
     </span>