diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2011-04-21 10:18:23 +0200 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2011-04-21 10:18:23 +0200 |
commit | 1ca2b0d56c4056c0d9d3cca22a54656979e758c4 (patch) | |
tree | 8b6df943e615a9caeac72ad6ec08e7b53ac19938 | |
parent | 07b20316ee247a1694eb9191f985cb2de2d08b49 (diff) | |
download | sonarqube-1ca2b0d56c4056c0d9d3cca22a54656979e758c4.tar.gz sonarqube-1ca2b0d56c4056c0d9d3cca22a54656979e758c4.zip |
SONAR-1973 Improve Resource Viewer
5 files changed, 49 insertions, 26 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb index ad8dfbed1ba..4c2f796a5dd 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb @@ -173,15 +173,25 @@ class ResourceController < ApplicationController conditions='snapshot_id=?' values=[@snapshot.id] - unless params[:rule].blank? - severity=Sonar::RulePriority.id(params[:rule]) - if severity - conditions += ' AND failure_level=?' - values<<severity + if params[:rule].blank? + conditions+='AND (switched_off IS NULL OR switched_off=?)' + values<<false + else + if params[:rule] == "f-positive" + conditions+='AND switched_off=?' + values<<true else - rule=Rule.by_key_or_id(params[:rule]) - conditions += ' AND rule_id=?' - values<<(rule ? rule.id : -1) + conditions+='AND (switched_off IS NULL OR switched_off=?)' + values<<false + severity=Sonar::RulePriority.id(params[:rule]) + if severity + conditions += ' AND failure_level=?' + values<<severity + else + rule=Rule.by_key_or_id(params[:rule]) + conditions += ' AND rule_id=?' + values<<(rule ? rule.id : -1) + end end end @@ -194,15 +204,6 @@ class ResourceController < ApplicationController conditions+=' AND id=-1' end end - - if params[:switchedOff] - @switchedOff=true - conditions+='AND switched_off=?' - values<<true - else - conditions+='AND (switched_off IS NULL OR switched_off=?)' - values<<false - end RuleFailure.find(:all, :include => ['rule', 'reviews' ], :conditions => [conditions] + values, :order => 'failure_level DESC').each do |violation| # sorted by severity => from blocker to info 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 a0efbef1645..dd98d5a3ecc 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 @@ -59,7 +59,7 @@ class ReviewsController < ApplicationController def create rule_failure = find_last_rule_failure_with_permanent_id params[:review][:rule_failure_permanent_id] - unless has_rights_to_create? rule_failure + unless has_rights_to_modify? rule_failure render :text => "<b>Cannot create the review</b> : access denied." return end @@ -107,7 +107,7 @@ class ReviewsController < ApplicationController def create_comment rule_failure = find_last_rule_failure_with_permanent_id params[:rule_failure_permanent_id] - unless has_rights_to_create? rule_failure + unless has_rights_to_modify? rule_failure render :text => "<b>Cannot create the comment</b> : access denied." return end @@ -179,6 +179,23 @@ class ReviewsController < ApplicationController violation = find_last_rule_failure_with_permanent_id review.rule_failure_permanent_id render :partial => "resource/violation", :locals => { :violation => violation } end + + def switch_on_violation + rule_failure = RuleFailure.find params[:rule_failure_id] + unless has_rights_to_modify? rule_failure + render :text => "<b>Cannot switch on the violation</b> : access denied." + return + end + + rule_failure.switched_off = false + rule_failure.save + + review = rule_failure.get_open_review + review.status = "closed" + review.save + + render :partial => "resource/violation", :locals => { :violation => rule_failure } + end ## -------------- PRIVATE -------------- ## private @@ -246,7 +263,7 @@ class ReviewsController < ApplicationController return RuleFailure.last( :all, :conditions => [ "permanent_id = ?", rule_failure_permanent_id ], :include => ['snapshot'] ) end - def has_rights_to_create? ( rule_failure ) + def has_rights_to_modify? ( rule_failure ) return false unless current_user project = rule_failure.snapshot.root_project diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb index e1594d7d441..7e765102206 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb @@ -50,10 +50,6 @@ <% if @display_violations %> <td class="<%= 'first' if first -%>"> - <input type="checkbox" value="true" name="switchedOff" id="switchedOff" <%= 'checked' if @switchedOff -%> onclick="applyOptions()"/> - <label for="expand">Show only switched-off violations</label> - </td> - <td class="<%= 'first' if first -%>"> <select id="period" name="period" onchange="applyOptions()"> <option value="">Time changes...</option> <%= violation_period_select_options(@snapshot, 1) -%> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_rules_filter.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_rules_filter.html.erb index 0bd942683bd..06d89dc5414 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_rules_filter.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_rules_filter.html.erb @@ -32,7 +32,8 @@ end %> <select id="rule" name="rule" onchange="applyOptions()"> - <option value="">No filters</option> + <option value="">All violations</option> + <option value="f-positive" <%= 'selected' if params[:rule]=="f-positive" -%>>False-Positives only</option> <optgroup label="Severity"> <% if blocker_violations value=(@period ? blocker_violations.variation(@period) : blocker_violations.value) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb index 880786791c8..1fec9f4e7bc 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb @@ -32,11 +32,13 @@ <%= image_tag("sep12.png") -%> False-Positive + <% end %> <% if current_open_review && current_open_review.assignee %> <%= image_tag("sep12.png") -%> <%= h(current_open_review.assignee.name) -%> + <% end %> @@ -62,10 +64,16 @@ :complete => "$('reviewForm" + violation.permanent_id.to_s + "').style.display='';$('reviewText').focus();" -%> <% end %> - <%= link_to_remote "Switch-off", + <% if violation.switched_off %> + <%= link_to_remote "Switch-on", + :url => { :controller => "reviews", :action => "switch_on_violation", :rule_failure_id => violation.id }, + :update => "vId" + violation.permanent_id.to_s -%> + <% else %> + <%= link_to_remote "Switch-off", :url => { :controller => "reviews", :action => "form", :rule_failure_permanent_id => violation.permanent_id, :switch_off => true }, :update => "reviewForm" + violation.permanent_id.to_s, :complete => "$('reviewForm" + violation.permanent_id.to_s + "').style.display='';$('reviewText').focus();" -%> + <% end %> </span> <% end %> |