From ac70590aa782d7285429a3940d133932d94abb01 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 23 May 2012 14:15:25 +0200 Subject: [PATCH] SONAR-2706 fix reloading of available commands in review detail --- .../condition/HasReviewPropertyCondition.java | 4 ++-- .../controllers/project_reviews_controller.rb | 17 +++++++++----- .../main/webapp/WEB-INF/app/models/review.rb | 9 +++++--- .../views/project_reviews/_review.html.erb | 22 +++++++++++-------- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasReviewPropertyCondition.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasReviewPropertyCondition.java index 1e34b4feeb7..01ab093372a 100644 --- a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasReviewPropertyCondition.java +++ b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasReviewPropertyCondition.java @@ -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; } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_reviews_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_reviews_controller.rb index 68d1818e4e5..9093108c74a 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_reviews_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_reviews_controller.rb @@ -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 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 3269e34abd4..25bac3056ec 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 @@ -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 # # diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project_reviews/_review.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project_reviews/_review.html.erb index 0dd5a5aa481..47e888ad8d4 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/project_reviews/_review.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project_reviews/_review.html.erb @@ -47,19 +47,23 @@ :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 + %> <% end %> -- 2.39.5