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
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
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
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
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
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
end %>
<% 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>
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)
<%= 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 %>
: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 %>