-#
-# Sonar, entreprise quality control tool.
-# Copyright (C) 2008-2011 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# Sonar is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# Sonar is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with Sonar; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
-#
-class ResourceController < ApplicationController
-
- SECTION=Navigation::SECTION_RESOURCE
- helper DashboardHelper
-
- def index
- @resource = Project.by_key(params[:id])
-
- if (@resource && has_role?(:user, @resource))
- params[:layout]='false'
- @snapshot=@resource.last_snapshot
-
- load_extensions()
-
- if @extension
- if (@extension.getId()=='violations')
- render_violations()
- elsif (@extension.getId()=='coverage')
- render_coverage()
- elsif (@extension.getId()=='source')
- render_source()
- else
- render_extension()
- end
- else
- render_nothing()
- end
- else
- access_denied
- end
- end
-
- private
-
- def load_extensions
- @extensions=[]
- java_facade.getResourceTabs(@resource.scope, @resource.qualifier, @resource.language).each do |tab|
- tab.getUserRoles().each do |role|
- if has_role?(role, @resource)
- @extensions<<tab
- break
- end
- end
- end
-
- if !params[:tab].blank?
- @extension=@extensions.find{|extension| extension.getId()==params[:tab]}
-
- elsif !params[:metric].blank?
- metric=Metric.by_key(params[:metric])
- @extension=@extensions.find{|extension| extension.getDefaultTabForMetrics().include?(metric.key)}
-
- end
- @extension=@extensions.find{|extension| extension.isDefaultTab()} if @extension==nil
- end
-
- def load_sources
- @period = params[:period].to_i unless params[:period].blank?
- @expanded=(params[:expand]=='true')
-
- if @snapshot.source
- source_lines=@snapshot.source.syntax_highlighted_lines()
- init_scm()
-
- @lines=[]
- source_lines.each_with_index do |source, index|
- line=Line.new(source)
- @lines<<line
-
- line.revision=@revisions_by_line[index+1]
- line.author=@authors_by_line[index+1]
-
- date_string=@dates_by_line[index+1]
- line.datetime=(date_string ? Java::OrgSonarApiUtils::DateUtils.parseDateTime(date_string): nil)
- end
- end
- end
-
- def init_scm
- @scm_available=(@snapshot.measure('last_commit_datetimes_by_line')!=nil)
- @authors_by_line=load_distribution('authors_by_line')
- @revisions_by_line=load_distribution('revisions_by_line')
- @dates_by_line=load_distribution('last_commit_datetimes_by_line')
- end
-
- def load_distribution(metric_key)
- m=@snapshot.measure(metric_key)
- m ? m.data_as_line_distribution() : {}
- end
-
- def render_coverage
- load_sources()
- @display_coverage=true
- @expandable=(@lines!=nil)
- if @lines
- @hits_by_line=load_distribution('coverage_line_hits_data')
- @conditions_by_line=load_distribution('conditions_by_line')
- @covered_conditions_by_line=load_distribution('covered_conditions_by_line')
-
- @hits_by_line.each_pair do |line_id,hits|
- line=@lines[line_id-1]
- if line
- line.hits=hits.to_i
- line.conditions=@conditions_by_line[line_id].to_i
- line.covered_conditions=@covered_conditions_by_line[line_id].to_i
- end
- end
-
- if @snapshot.measure('conditions_by_line').nil?
- # TODO remove this code when branch_coverage_hits_data is fully removed from CoreMetrics
- deprecated_branches_by_line=load_distribution('branch_coverage_hits_data')
- deprecated_branches_by_line.each_pair do |line_id,label|
- line=@lines[line_id-1]
- if line
- line.deprecated_conditions_label=label
- end
- end
- end
-
- to=(@period ? Java::JavaUtil::Date.new(@snapshot.period_datetime(@period).to_f * 1000) : nil)
- metric=Metric.by_key(params[:coverage_filter]||params[:metric])
- @coverage_filter=(metric ? metric.key : 'coverage')
- @filtered=true
- if ('lines_to_cover'==@coverage_filter || 'coverage'==@coverage_filter || 'line_coverage'==@coverage_filter ||
- 'new_lines_to_cover'==@coverage_filter || 'new_coverage'==@coverage_filter || 'new_line_coverage'==@coverage_filter)
- @coverage_filter='lines_to_cover'
- filter_lines{|line| line.hits && line.after(to)}
-
- elsif 'uncovered_lines'==@coverage_filter || 'new_uncovered_lines'==@coverage_filter
- @coverage_filter='uncovered_lines'
- filter_lines{|line| line.hits && line.hits==0 && line.after(to)}
-
- elsif 'conditions_to_cover'==@coverage_filter || 'branch_coverage'==@coverage_filter ||
- 'new_conditions_to_cover'==@coverage_filter || 'new_branch_coverage'==@coverage_filter
- @coverage_filter='conditions_to_cover'
- filter_lines{|line| line.conditions && line.conditions>0 && line.after(to)}
-
- elsif 'uncovered_conditions'==@coverage_filter || 'new_uncovered_conditions'==@coverage_filter
- @coverage_filter='uncovered_conditions'
- filter_lines{|line| line.conditions && line.covered_conditions && line.covered_conditions<line.conditions && line.after(to)}
- end
- end
- render :action => 'index', :layout => !request.xhr?
- end
-
-
-
- def render_violations
- load_sources()
- @display_violations=true
- @global_violations=[]
- @expandable=(@lines!=nil)
- @filtered=!@expanded
-
- conditions='snapshot_id=?'
- values=[@snapshot.id]
- unless params[:rule].blank?
- 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
-
- if @period
- date=@snapshot.period_datetime(@period)
- if date
- conditions+=' AND created_at>?'
- values<<date.advance(:minutes => 1)
- else
- conditions+=' AND id=-1'
- end
- end
-
- RuleFailure.find(:all, :include => ['rule', 'reviews' ], :conditions => [conditions] + values, :order => 'failure_level DESC').each do |violation|
- # sorted by severity => from blocker to info
- if violation.line && violation.line>0 && @lines
- @lines[violation.line-1].add_violation(violation)
- else
- @global_violations<<violation
- end
- end
-
- if !@expanded && @lines
- filter_lines{|line| line.violations?}
- end
- render :action => 'index', :layout => !request.xhr?
- end
-
-
- def render_source
- load_sources()
- filter_lines_by_date()
- render :action => 'index', :layout => !request.xhr?
- end
-
-
- def filter_lines_by_date
- if @period
- @filtered=true
- to=Java::JavaUtil::Date.new(@snapshot.period_datetime(@period).to_f * 1000)
- if to
- @lines.each do |line|
- line.flag_as_hidden() if !line.after(to)
- end
- end
- end
- end
-
- def filter_lines(&block)
- @lines.each_with_index do |line,index|
- if yield(line)
- for i in index-4...index
- @lines[i].flag_as_highlight_context() if i>=0
- end
- line.flag_as_highlighted()
- for i in index+1..index+4
- @lines[i].flag_as_highlight_context() if i<@lines.size
- end
- else
- line.flag_as_hidden()
- end
- end
- end
-
- class Line
- attr_accessor :source, :revision, :author, :datetime, :violations, :hits, :conditions, :covered_conditions, :hidden, :highlighted, :deprecated_conditions_label
-
- def initialize(source)
- @source=source
- end
-
- def add_violation(violation)
- @violations||=[]
- @violations<<violation
- @visible=true
- end
-
- def violations?
- @violations && @violations.size>0
- end
-
- def violation_severity
- if @violations && @violations.size>0
- @violations[0].failure_level
- else
- nil
- end
- end
-
- def after(date)
- if date && @datetime
- @datetime.after(date)
- else
- true
- end
- end
-
- def flag_as_highlighted
- @highlighted=true
- @hidden=false
- end
-
- def flag_as_highlight_context
- # do not force if highlighted has already been set to true
- @highlighted=false if @highlighted.nil?
- @hidden=false
- end
-
- def flag_as_hidden
- # do not force if it has already been flagged as visible
- if @hidden.nil?
- @hidden=true
- @highlighted=false
- end
- end
-
- def hidden?
- @hidden==true
- end
-
- def highlighted?
- # highlighted if the @highlighted has not been set or has been set to true
- !hidden? && @highlighted!=false
- end
-
- def deprecated_conditions_label=(label)
- if label
- @deprecated_conditions_label=label
- if label=='0%'
- @conditions=2
- @covered_conditions=0
- elsif label=='100%'
- @conditions=2
- @covered_conditions=2
- else
- @conditions=2
- @covered_conditions=1
- end
- end
- end
- end
-
- def render_extension()
- render :action => 'extension', :layout => !request.xhr?
- end
-
- def render_nothing()
- render :action => 'nothing', :layout => !request.xhr?
+#\r
+# Sonar, entreprise quality control tool.\r
+# Copyright (C) 2008-2011 SonarSource\r
+# mailto:contact AT sonarsource DOT com\r
+#\r
+# Sonar is free software; you can redistribute it and/or\r
+# modify it under the terms of the GNU Lesser General Public\r
+# License as published by the Free Software Foundation; either\r
+# version 3 of the License, or (at your option) any later version.\r
+#\r
+# Sonar is distributed in the hope that it will be useful,\r
+# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+# Lesser General Public License for more details.\r
+#\r
+# You should have received a copy of the GNU Lesser General Public\r
+# License along with Sonar; if not, write to the Free Software\r
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02\r
+#\r
+class ResourceController < ApplicationController\r
+\r
+ SECTION=Navigation::SECTION_RESOURCE\r
+ helper DashboardHelper\r
+ \r
+ def index\r
+ @resource = Project.by_key(params[:id])\r
+\r
+ if (@resource && has_role?(:user, @resource))\r
+ params[:layout]='false'\r
+ @snapshot=@resource.last_snapshot\r
+\r
+ load_extensions()\r
+\r
+ if @extension\r
+ if (@extension.getId()=='violations')\r
+ render_violations()\r
+ elsif (@extension.getId()=='coverage')\r
+ render_coverage()\r
+ elsif (@extension.getId()=='source')\r
+ render_source()\r
+ else\r
+ render_extension()\r
+ end\r
+ else\r
+ render_nothing()\r
+ end\r
+ else\r
+ access_denied\r
+ end\r
+ end\r
+\r
+ private\r
+\r
+ def load_extensions\r
+ @extensions=[]\r
+ java_facade.getResourceTabs(@resource.scope, @resource.qualifier, @resource.language).each do |tab|\r
+ tab.getUserRoles().each do |role|\r
+ if has_role?(role, @resource)\r
+ @extensions<<tab\r
+ break\r
+ end\r
+ end\r
+ end\r
+\r
+ if !params[:tab].blank?\r
+ @extension=@extensions.find{|extension| extension.getId()==params[:tab]}\r
+\r
+ elsif !params[:metric].blank?\r
+ metric=Metric.by_key(params[:metric])\r
+ @extension=@extensions.find{|extension| extension.getDefaultTabForMetrics().include?(metric.key)}\r
+\r
+ end\r
+ @extension=@extensions.find{|extension| extension.isDefaultTab()} if @extension==nil\r
+ end\r
+\r
+ def load_sources\r
+ @period = params[:period].to_i unless params[:period].blank?\r
+ @expanded=(params[:expand]=='true')\r
+\r
+ if @snapshot.source\r
+ source_lines=Java::OrgSonarServerUi::JRubyFacade.new.colorizeCode(@snapshot.source.data, @snapshot.project.language).split("\n")\r
+ init_scm()\r
+\r
+ @lines=[]\r
+ source_lines.each_with_index do |source, index|\r
+ line=Line.new(source)\r
+ @lines<<line\r
+\r
+ line.revision=@revisions_by_line[index+1]\r
+ line.author=@authors_by_line[index+1]\r
+\r
+ date_string=@dates_by_line[index+1]\r
+ line.datetime=(date_string ? Java::OrgSonarApiUtils::DateUtils.parseDateTime(date_string): nil)\r
+ end\r
+ end\r
+ end\r
+\r
+ def init_scm\r
+ @scm_available=(@snapshot.measure('last_commit_datetimes_by_line')!=nil)\r
+ @authors_by_line=load_distribution('authors_by_line')\r
+ @revisions_by_line=load_distribution('revisions_by_line')\r
+ @dates_by_line=load_distribution('last_commit_datetimes_by_line')\r
+ end\r
+\r
+ def load_distribution(metric_key)\r
+ m=@snapshot.measure(metric_key)\r
+ m ? m.data_as_line_distribution() : {}\r
+ end\r
+\r
+ def render_coverage\r
+ load_sources()\r
+ @display_coverage=true\r
+ @expandable=(@lines!=nil)\r
+ if @lines\r
+ @hits_by_line=load_distribution('coverage_line_hits_data')\r
+ @conditions_by_line=load_distribution('conditions_by_line')\r
+ @covered_conditions_by_line=load_distribution('covered_conditions_by_line')\r
+\r
+ @hits_by_line.each_pair do |line_id,hits|\r
+ line=@lines[line_id-1]\r
+ if line\r
+ line.hits=hits.to_i\r
+ line.conditions=@conditions_by_line[line_id].to_i\r
+ line.covered_conditions=@covered_conditions_by_line[line_id].to_i\r
+ end\r
+ end\r
+\r
+ if @snapshot.measure('conditions_by_line').nil?\r
+ # TODO remove this code when branch_coverage_hits_data is fully removed from CoreMetrics\r
+ deprecated_branches_by_line=load_distribution('branch_coverage_hits_data')\r
+ deprecated_branches_by_line.each_pair do |line_id,label|\r
+ line=@lines[line_id-1]\r
+ if line\r
+ line.deprecated_conditions_label=label\r
+ end\r
+ end\r
+ end\r
+\r
+ to=(@period ? Java::JavaUtil::Date.new(@snapshot.period_datetime(@period).to_f * 1000) : nil)\r
+ metric=Metric.by_key(params[:coverage_filter]||params[:metric])\r
+ @coverage_filter=(metric ? metric.key : 'coverage')\r
+ @filtered=true\r
+ if ('lines_to_cover'==@coverage_filter || 'coverage'==@coverage_filter || 'line_coverage'==@coverage_filter ||\r
+ 'new_lines_to_cover'==@coverage_filter || 'new_coverage'==@coverage_filter || 'new_line_coverage'==@coverage_filter)\r
+ @coverage_filter='lines_to_cover'\r
+ filter_lines{|line| line.hits && line.after(to)}\r
+\r
+ elsif 'uncovered_lines'==@coverage_filter || 'new_uncovered_lines'==@coverage_filter\r
+ @coverage_filter='uncovered_lines'\r
+ filter_lines{|line| line.hits && line.hits==0 && line.after(to)}\r
+\r
+ elsif 'conditions_to_cover'==@coverage_filter || 'branch_coverage'==@coverage_filter ||\r
+ 'new_conditions_to_cover'==@coverage_filter || 'new_branch_coverage'==@coverage_filter\r
+ @coverage_filter='conditions_to_cover'\r
+ filter_lines{|line| line.conditions && line.conditions>0 && line.after(to)}\r
+\r
+ elsif 'uncovered_conditions'==@coverage_filter || 'new_uncovered_conditions'==@coverage_filter\r
+ @coverage_filter='uncovered_conditions'\r
+ filter_lines{|line| line.conditions && line.covered_conditions && line.covered_conditions<line.conditions && line.after(to)}\r
+ end\r
+ end\r
+ render :action => 'index', :layout => !request.xhr?\r
+ end\r
+\r
+ \r
+ \r
+ def render_violations\r
+ load_sources()\r
+ @display_violations=true\r
+ @global_violations=[]\r
+ @expandable=(@lines!=nil)\r
+ @filtered=!@expanded\r
+\r
+ conditions='snapshot_id=?'\r
+ values=[@snapshot.id]\r
+ unless params[:rule].blank?\r
+ severity=Sonar::RulePriority.id(params[:rule])\r
+ if severity\r
+ conditions += ' AND failure_level=?'\r
+ values<<severity\r
+ else\r
+ rule=Rule.by_key_or_id(params[:rule])\r
+ conditions += ' AND rule_id=?'\r
+ values<<(rule ? rule.id : -1)\r
+ end\r
+ end\r
+\r
+ if @period\r
+ date=@snapshot.period_datetime(@period)\r
+ if date\r
+ conditions+=' AND created_at>?'\r
+ values<<date.advance(:minutes => 1)\r
+ else\r
+ conditions+=' AND id=-1'\r
+ end\r
+ end\r
+\r
+ RuleFailure.find(:all, :include => ['rule', 'reviews' ], :conditions => [conditions] + values, :order => 'failure_level DESC').each do |violation|\r
+ # sorted by severity => from blocker to info\r
+ if violation.line && violation.line>0 && @lines\r
+ @lines[violation.line-1].add_violation(violation)\r
+ else\r
+ @global_violations<<violation\r
+ end\r
+ # if the permanent_id does not exist, set it to the current id\r
+ unless violation.permanent_id\r
+ violation.permanent_id = violation.id\r
+ violation.save\r
+ end\r
+ end\r
+\r
+ if !@expanded && @lines\r
+ filter_lines{|line| line.violations?}\r
+ end\r
+ render :action => 'index', :layout => !request.xhr?\r
+ end\r
+ \r
+ \r
+ def render_source\r
+ load_sources()\r
+ filter_lines_by_date()\r
+ render :action => 'index', :layout => !request.xhr?\r
+ end\r
+\r
+ \r
+ def filter_lines_by_date\r
+ if @period\r
+ @filtered=true\r
+ to=Java::JavaUtil::Date.new(@snapshot.period_datetime(@period).to_f * 1000)\r
+ if to\r
+ @lines.each do |line|\r
+ line.flag_as_hidden() if !line.after(to)\r
+ end\r
+ end\r
+ end\r
+ end\r
+\r
+ def filter_lines(&block)\r
+ @lines.each_with_index do |line,index|\r
+ if yield(line)\r
+ for i in index-4...index\r
+ @lines[i].flag_as_highlight_context() if i>=0\r
+ end\r
+ line.flag_as_highlighted()\r
+ for i in index+1..index+4\r
+ @lines[i].flag_as_highlight_context() if i<@lines.size\r
+ end\r
+ else\r
+ line.flag_as_hidden()\r
+ end\r
+ end\r
+ end\r
+\r
+ class Line\r
+ attr_accessor :source, :revision, :author, :datetime, :violations, :hits, :conditions, :covered_conditions, :hidden, :highlighted, :deprecated_conditions_label\r
+\r
+ def initialize(source)\r
+ @source=source\r
+ end\r
+\r
+ def add_violation(violation)\r
+ @violations||=[]\r
+ @violations<<violation\r
+ @visible=true\r
+ end\r
+\r
+ def violations?\r
+ @violations && @violations.size>0\r
+ end\r
+\r
+ def violation_severity\r
+ if @violations && @violations.size>0\r
+ @violations[0].failure_level\r
+ else\r
+ nil\r
+ end\r
+ end\r
+\r
+ def after(date)\r
+ if date && @datetime\r
+ @datetime.after(date)\r
+ else\r
+ true\r
+ end\r
+ end\r
+\r
+ def flag_as_highlighted\r
+ @highlighted=true\r
+ @hidden=false\r
+ end\r
+\r
+ def flag_as_highlight_context\r
+ # do not force if highlighted has already been set to true\r
+ @highlighted=false if @highlighted.nil?\r
+ @hidden=false\r
+ end\r
+\r
+ def flag_as_hidden\r
+ # do not force if it has already been flagged as visible\r
+ if @hidden.nil?\r
+ @hidden=true\r
+ @highlighted=false\r
+ end\r
+ end\r
+\r
+ def hidden?\r
+ @hidden==true\r
+ end\r
+\r
+ def highlighted?\r
+ # highlighted if the @highlighted has not been set or has been set to true\r
+ !hidden? && @highlighted!=false\r
+ end\r
+\r
+ def deprecated_conditions_label=(label)\r
+ if label\r
+ @deprecated_conditions_label=label\r
+ if label=='0%'\r
+ @conditions=2\r
+ @covered_conditions=0\r
+ elsif label=='100%'\r
+ @conditions=2\r
+ @covered_conditions=2\r
+ else\r
+ @conditions=2\r
+ @covered_conditions=1\r
+ end\r
+ end\r
+ end\r
+ end\r
+\r
+ def render_extension()\r
+ render :action => 'extension', :layout => !request.xhr?\r
+ end\r
+\r
+ def render_nothing()\r
+ render :action => 'nothing', :layout => !request.xhr?\r
end
end
\ No newline at end of file
end\r
\r
def list\r
- reviews = find_reviews_for_rule_failure params[:rule_failure_id]\r
+ reviews = find_reviews_for_rule_failure params[:rule_failure_permanent_id]\r
render :partial => "list", :locals => { :reviews => reviews }\r
end\r
\r
def form\r
@review = Review.new\r
- @review.rule_failure_id = params[:violation_id]\r
+ @review.rule_failure_permanent_id = params[:rule_failure_permanent_id]\r
@review.user = current_user\r
@review.severity = Review.default_severity\r
@review_comment = ReviewComment.new\r
@review_comment.user = current_user\r
@review_comment.review_id = params[:review_id]\r
@review_comment.review_text = ""\r
- @rule_failure_id = params[:rule_failure_id]\r
+ @rule_failure_permanent_id = params[:rule_failure_permanent_id]\r
render :partial => "form_comment"\r
end\r
\r
def create\r
- unless has_rights_to_create? params[:review][:rule_failure_id]\r
+ unless has_rights_to_create? params[:review][:rule_failure_permanent_id]\r
render :text => "<b>Cannot create the review</b> : access denied."\r
return\r
end\r
@review.user = current_user\r
@review.status = Review.default_status\r
@review.review_type = Review.default_type\r
+ @review.resource = RuleFailure.find( @review.rule_failure_permanent_id, :include => ['snapshot'] ).snapshot.project\r
@review_comment = ReviewComment.new(params[:review_comment])\r
@review_comment.user = current_user\r
@review.review_comments << @review_comment\r
if @review.valid?\r
@review.save\r
- @reviews = find_reviews_for_rule_failure @review.rule_failure_id\r
+ @reviews = find_reviews_for_rule_failure @review.rule_failure_permanent_id\r
end\r
render "create_result"\r
end\r
\r
def create_comment\r
- unless has_rights_to_create? params[:rule_failure_id]\r
+ unless has_rights_to_create? params[:rule_failure_permanent_id]\r
render :text => "<b>Cannot create the comment</b> : access denied."\r
return\r
end\r
\r
@review_comment = ReviewComment.new(params[:review_comment])\r
@review_comment.user = current_user\r
- @rule_failure_id = params[:rule_failure_id]\r
+ @rule_failure_permanent_id = params[:rule_failure_permanent_id]\r
if @review_comment.valid?\r
@review_comment.save\r
- @reviews = find_reviews_for_rule_failure @rule_failure_id\r
+ # -- TODO : should create a Review#create_comment and put the following logic in it\r
+ review = @review_comment.review\r
+ review.updated_at = @review_comment.created_at\r
+ review.save\r
+ # -- End of TODO code --\r
+ @reviews = find_reviews_for_rule_failure @rule_failure_permanent_id\r
end\r
render "create_comment_result"\r
end\r
@reviews = Review.find( :all, :order => "created_at DESC", :joins => :review_comments, :conditions => [ conditions.join(" AND "), values] ).uniq\r
end\r
\r
- def find_reviews_for_rule_failure ( rule_failure_id )\r
- return Review.find :all, :conditions => ['rule_failure_id=?', rule_failure_id]\r
+ def find_reviews_for_rule_failure ( rule_failure_permanent_id )\r
+ return Review.find :all, :conditions => ['rule_failure_permanent_id=?', rule_failure_permanent_id]\r
end\r
\r
- def has_rights_to_create? ( rule_failure_id )\r
- return false unless current_user\r
+ def find_rule_failure_with_permanent_id ( rule_failure_permanent_id )\r
+ return RuleFailure.last( :all, :conditions => [ "permanent_id = ?", rule_failure_permanent_id ], :include => ['snapshot'] )\r
+ end\r
\r
- project = RuleFailure.find( rule_failure_id, :include => ['snapshot'] ).snapshot.root_project\r
+ def has_rights_to_create? ( rule_failure_permanent_id )\r
+ return false unless current_user\r
+ \r
+ project = find_rule_failure_with_permanent_id( rule_failure_permanent_id).snapshot.root_project\r
unless has_role?(:user, project)\r
return false\r
end\r
-#
-# Sonar, entreprise quality control tool.
-# Copyright (C) 2008-2011 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# Sonar is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# Sonar is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with {library}; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
-#
-
-class RuleFailure < ActiveRecord::Base
-
- belongs_to :rule
- belongs_to :snapshot
- has_many :reviews, :order => "created_at"
-
- def to_hash_json
- json = {}
- json['message'] = message
- json['line'] = line if line
- json['priority'] = Sonar::RulePriority.to_s(failure_level).upcase
- if created_at
- json['createdAt'] = format_datetime(created_at)
- end
- json['rule'] = {
- :key => rule.key,
- :name => rule.name
- }
- json['resource'] = {
- :key => snapshot.project.key,
- :name => snapshot.project.name,
- :scope => snapshot.project.scope,
- :qualifier => snapshot.project.qualifier,
- :language => snapshot.project.language
- }
- json
- end
-
- def to_xml(xml=Builder::XmlMarkup.new(:indent => 0))
- xml.violation do
- xml.message(message)
- xml.line(line) if line
- xml.priority(Sonar::RulePriority.to_s(failure_level))
- if created_at
- xml.createdAt(format_datetime(created_at))
- end
- xml.rule do
- xml.key(rule.key)
- xml.name(rule.name)
- end
- xml.resource do
- xml.key(snapshot.project.key)
- xml.name(snapshot.project.name)
- xml.scope(snapshot.project.scope)
- xml.qualifier(snapshot.project.qualifier)
- xml.language(snapshot.project.language)
- end
- end
- end
-
- def format_datetime(datetime)
- datetime.strftime("%Y-%m-%dT%H:%M:%S%z")
- end
-
-end
+#\r
+# Sonar, entreprise quality control tool.\r
+# Copyright (C) 2008-2011 SonarSource\r
+# mailto:contact AT sonarsource DOT com\r
+#\r
+# Sonar is free software; you can redistribute it and/or\r
+# modify it under the terms of the GNU Lesser General Public\r
+# License as published by the Free Software Foundation; either\r
+# version 3 of the License, or (at your option) any later version.\r
+#\r
+# Sonar is distributed in the hope that it will be useful,\r
+# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+# Lesser General Public License for more details.\r
+#\r
+# You should have received a copy of the GNU Lesser General Public\r
+# License along with {library}; if not, write to the Free Software\r
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02\r
+#\r
+\r
+class RuleFailure < ActiveRecord::Base\r
+\r
+ belongs_to :rule\r
+ belongs_to :snapshot\r
+ has_many :reviews, :primary_key => "permanent_id", :foreign_key => "rule_failure_permanent_id", :order => "created_at"\r
+\r
+ def to_hash_json\r
+ json = {}\r
+ json['message'] = message\r
+ json['line'] = line if line\r
+ json['priority'] = Sonar::RulePriority.to_s(failure_level).upcase\r
+ if created_at\r
+ json['createdAt'] = format_datetime(created_at)\r
+ end\r
+ json['rule'] = {\r
+ :key => rule.key,\r
+ :name => rule.name\r
+ }\r
+ json['resource'] = {\r
+ :key => snapshot.project.key,\r
+ :name => snapshot.project.name,\r
+ :scope => snapshot.project.scope,\r
+ :qualifier => snapshot.project.qualifier,\r
+ :language => snapshot.project.language\r
+ }\r
+ json\r
+ end\r
+\r
+ def to_xml(xml=Builder::XmlMarkup.new(:indent => 0))\r
+ xml.violation do\r
+ xml.message(message)\r
+ xml.line(line) if line\r
+ xml.priority(Sonar::RulePriority.to_s(failure_level))\r
+ if created_at\r
+ xml.createdAt(format_datetime(created_at))\r
+ end\r
+ xml.rule do\r
+ xml.key(rule.key)\r
+ xml.name(rule.name)\r
+ end\r
+ xml.resource do\r
+ xml.key(snapshot.project.key)\r
+ xml.name(snapshot.project.name)\r
+ xml.scope(snapshot.project.scope)\r
+ xml.qualifier(snapshot.project.qualifier)\r
+ xml.language(snapshot.project.language)\r
+ end\r
+ end\r
+ end\r
+\r
+ def format_datetime(datetime)\r
+ datetime.strftime("%Y-%m-%dT%H:%M:%S%z")\r
+ end\r
+\r
+end\r