]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2706 fix reloading of available commands in review detail
authorSimon Brandhof <simon.brandhof@gmail.com>
Wed, 23 May 2012 12:15:25 +0000 (14:15 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Wed, 23 May 2012 12:15:40 +0000 (14:15 +0200)
sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasReviewPropertyCondition.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/project_reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
sonar-server/src/main/webapp/WEB-INF/app/views/project_reviews/_review.html.erb

index 1e34b4feeb70d376c1432fa87ffeb532d5b5d087..01ab093372a70ebd60b9592687c8a99dfbff2776 100644 (file)
@@ -33,13 +33,13 @@ public final class HasReviewPropertyCondition extends Condition {
 
   private final String propertyKey;
 
-  protected HasReviewPropertyCondition(String propertyKey) {
+  public HasReviewPropertyCondition(String propertyKey) {
     super(false);
     Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyKey));
     this.propertyKey = propertyKey;
   }
 
-  protected final String getPropertyKey() {
+  public final String getPropertyKey() {
     return propertyKey;
   }
 
index 68d1818e4e59fa239f7862ad3392b3d096849fc3..9093108c74ad9af3bedaa8a1b252da644b3d85fe 100644 (file)
@@ -261,20 +261,27 @@ class ProjectReviewsController < ApplicationController
   # POST
   def execute
     bad_request('Missing review id') unless params[:id]
-    @review = Review.find(params[:id], :include => ['project'])
+    review = Review.find(params[:id], :include => ['project'])
 
-    access_denied unless has_rights_to_modify?(@review.resource)
+    access_denied unless has_rights_to_modify?(review.resource)
 
     bad_request('Missing command') if params[:command].blank?
 
     error_message = nil
     begin
-      RuleFailure.execute_command(params[:command], @review.violation, @review.resource.project, current_user, params)
+      RuleFailure.execute_command(params[:command], review.violation, review.resource.project, current_user, params)
     rescue Exception => e
       error_message=Api::Utils.exception_message(e, :backtrace => false)
     end
-    @review.reload
-    render :partial => "project_reviews/view", :locals => {:review => @review, :error_message => error_message}
+
+    ActiveRecord::Base.uncached() do
+      review.clean_violation_cache
+      review.reload
+
+      # TODO remove this ugly workaround to bypass ActiveRecord cache....
+      review.violation.review=review
+    end
+    render :partial => "project_reviews/review", :locals => {:review => review, :error_message => error_message}
   end
 
 
index 3269e34abd4e34847e943b5a41df9ef77890b8e5..25bac3056ec17f1a77fb492960402668008b33b9 100644 (file)
@@ -62,12 +62,15 @@ class Review < ActiveRecord::Base
   def rule_failure
     @rule_failure ||=
       begin
-        # We need to manually run this DB request as the real relation Reviews-RuleFailures is 1:n but we want only 1 violation
-        # (more than 1 violation can have the same "permanent_id" when several analyses are run in a small time frame)
-        RuleFailure.find(:first, :conditions => {:permanent_id => rule_failure_permanent_id}, :order => 'id desc')
+          # We need to manually run this DB request as the real relation Reviews-RuleFailures is 1:n but we want only 1 violation
+          # (more than 1 violation can have the same "permanent_id" when several analyses are run in a small time frame)
+          RuleFailure.find(:first, :conditions => {:permanent_id => rule_failure_permanent_id}, :order => 'id desc')
       end
   end
 
+  def clean_violation_cache
+    @rule_failure=nil
+  end
 
   #
   #
index 0dd5a5aa4810e1060f55c69b259034e80ae5ab61..47e888ad8d483b7e20cc0a6c62c24056e081d758 100644 (file)
                              :url => {:controller => "project_reviews", :action => "action_plan_form", :id => review.id},
                              :update => "actionForm",
                              :complete => "$('actionButtons').remove();$('actionForm').show();$('selectSeverity').focus();" -%>
-
         <%
-           screens = review.violation.available_java_screens(current_user)
-           screens.each do |screen|
+         end
         %>
-          <%= button_to_remote message("reviews.command.#{screen.getCommandKey()}.button"),
-                             :url => {:controller => "project_reviews", :action => "screen", :id => review.id, :command => screen.getCommandKey()},
-                             :update => "actionForm",
-                             :complete => "$('actionButtons').remove();$('actionForm').show();$('actionText').focus();" -%>
         <%
-           end
-         end
+         puts "-------------- in template: #{review.violation.review.data} versus #{review.data}"
+          if review.violation
+            screens = review.violation.available_java_screens(current_user)
+            screens.each do |screen|
         %>
+          <%= button_to_remote message("reviews.command.#{screen.getCommandKey()}.button"),
+                 :url => {:controller => "project_reviews", :action => "screen", :id => review.id, :command => screen.getCommandKey()},
+                 :update => "actionForm",
+                 :complete => "$('actionButtons').remove();$('actionForm').show();$('actionText').focus();" -%>
+          <%
+             end
+          end
+          %>
     </div>
   <% end %>