]> source.dussan.org Git - sonarqube.git/commitdiff
[SONAR-1973] Update code to use the permanent ID of violations, set
authorFabrice Bellingard <bellingard@gmail.com>
Wed, 13 Apr 2011 13:48:27 +0000 (15:48 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Wed, 20 Apr 2011 06:54:54 +0000 (08:54 +0200)
resource on review and update review date when comment added

sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form_comment.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_view.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/create_comment_result.js.rjs
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/create_result.js.rjs
sonar-server/src/main/webapp/WEB-INF/db/migrate/191_create_review.rb

index 6f491007194745ff10a7d41793a17299bdd6db0a..5cbf398eae52e2218a1075080911028f9c1b617f 100644 (file)
-#
-# 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
index 14d23c6a5052eb3583559210a2f34515802340e4..cc41f63549a37f5f383fac42d0521f79e5d3b104 100644 (file)
@@ -34,13 +34,13 @@ class ReviewsController < ApplicationController
   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
@@ -53,12 +53,12 @@ class ReviewsController < ApplicationController
     @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
@@ -67,28 +67,34 @@ class ReviewsController < ApplicationController
     @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
@@ -143,14 +149,18 @@ class ReviewsController < ApplicationController
     @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
index 3cac05b8463af63ea956fcdae96ba754912cd9cc..27e1ec254017e6ce8e890a85c329a1bd39866be1 100644 (file)
@@ -1,75 +1,75 @@
-#
-# 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
index 476a0383255cbcdd6b8805088f2db1256a9a1320..3a599ba11e6d62443eba52eacd3c201b9a43845c 100644 (file)
       <td style="width: 30px; vertical-align: top; text-align: center;">\r
        <% if current_user && violation.reviews.blank? %>\r
           <%= link_to_remote image_tag("reviews/+review.png"),  \r
-                       :url => { :controller => "reviews", :action => "form", :violation_id => violation.id },\r
-                       :update => "reviewFailure" + violation.id.to_s,\r
-                       :html => { :id => "createReviewLink" + violation.id.to_s, :title => "Add a review" },\r
-                       :complete => "$('reviewFailure" + violation.id.to_s + "').style.display='';$('reviewText').focus();" -%>\r
+                       :url => { :controller => "reviews", :action => "form", :rule_failure_permanent_id => violation.permanent_id },\r
+                       :update => "reviewFailure" + violation.permanent_id.to_s,\r
+                       :html => { :id => "createReviewLink" + violation.permanent_id.to_s, :title => "Add a review" },\r
+                       :complete => "$('reviewFailure" + violation.permanent_id.to_s + "').style.display='';$('reviewText').focus();" -%>\r
        <% end %>\r
        <% unless violation.reviews.blank? %>\r
          <%= image_tag("reviews/review.png") -%>\r
@@ -38,7 +38,7 @@
     \r
     <tr>\r
       <td colspan="2">\r
-               <div id="reviewFailure<%= violation.id -%>" style="margin-left: 13px; padding: 10px 5px 5px 10px; border-left: 2px solid #EFEFEF; display:<%= displayReviewFailureDiv -%>">\r
+               <div id="reviewFailure<%= violation.permanent_id -%>" style="margin-left: 13px; padding: 10px 5px 5px 10px; border-left: 2px solid #EFEFEF; display:<%= displayReviewFailureDiv -%>">\r
                  <%= render :partial => "reviews/list", :locals => { :reviews => violation.reviews } %>\r
                </div>\r
       </td>\r
index 375e4fa087357713cb2c18a522d6b641f0772e85..d31edd0dca2a7acb569eb7444b4d72f47a1b8647 100644 (file)
@@ -1,6 +1,6 @@
 <b>Create a new review</b>\r
 <% form_for :review, @review do |f| %>\r
-      <%= f.hidden_field :rule_failure_id %>\r
+      <%= f.hidden_field :rule_failure_permanent_id %>\r
       Severity: \r
       <%= select_tag "review[severity]", options_for_select(Review.severity_options, @review.severity)  %>\r
       <br/>\r
@@ -9,7 +9,7 @@
       \r
       <%= submit_to_remote "create_btn", "Create review", :url => { :action => 'create' } %>\r
       <input type="button" name="cancel_btn" value="Cancel" \r
-             onclick="new Ajax.Updater({success:'reviewFailure<%= @review.rule_failure_id.to_s -%>'}, '<%= ApplicationController.root_context -%>/reviews/list?rule_failure_id=<%= @review.rule_failure_id.to_s -%>', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form), }); $('reviewFailure<%= @review.rule_failure_id.to_s -%>').style.display='none';">\r
+             onclick="new Ajax.Updater({success:'reviewFailure<%= @review.rule_failure_permanent_id.to_s -%>'}, '<%= ApplicationController.root_context -%>/reviews/list?rule_failure_permanent_id=<%= @review.rule_failure_permanent_id.to_s -%>', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form), }); $('reviewFailure<%= @review.rule_failure_permanent_id.to_s -%>').style.display='none';">\r
 \r
       <%= f.error_messages :header_message => "Can't create the review", :message => "", :header_tag => :h3 %>\r
       \r
index 6cf80541e2a7b86a834899455e77a94860bbbdbe..b0da98bae3171ab27e49f6d59e67757c9d710bc4 100644 (file)
@@ -1,15 +1,15 @@
-<% form_for :review_comment, @review_comment do |f| %>
-      <%= f.hidden_field :review_id %>
-      <%= f.text_area :review_text, :rows => 8, 
-            :id => "commentText" + @review_comment.review_id.to_s,
-            :style => "width:100%" %>
-      <br/>
-      <%= submit_to_remote 'create_btn', 'Add comment', 
-                     :url => { :action => 'create_comment', :rule_failure_id => @rule_failure_id } %>
-      <%= submit_to_remote 'cancel_btn', 'Cancel', 
-                     :url => { :action => 'list', :rule_failure_id => @rule_failure_id.to_s },
-                     :update => { :success => "reviewFailure" + @rule_failure_id.to_s } %>
-      
-      <%= f.error_messages :header_message => "Can't save the comment", :message => "", :header_tag => :h3%>
-      
+<% form_for :review_comment, @review_comment do |f| %>\r
+      <%= f.hidden_field :review_id %>\r
+      <%= f.text_area :review_text, :rows => 8, \r
+            :id => "commentText" + @review_comment.review_id.to_s,\r
+            :style => "width:100%" %>\r
+      <br/>\r
+      <%= submit_to_remote 'create_btn', 'Add comment', \r
+                     :url => { :action => 'create_comment', :rule_failure_permanent_id => @rule_failure_permanent_id } %>\r
+      <%= submit_to_remote 'cancel_btn', 'Cancel', \r
+                     :url => { :action => 'list', :rule_failure_permanent_id => @rule_failure_permanent_id.to_s },\r
+                     :update => { :success => "reviewFailure" + @rule_failure_permanent_id.to_s } %>\r
+      \r
+      <%= f.error_messages :header_message => "Can't save the comment", :message => "", :header_tag => :h3%>\r
+      \r
 <% end %>
\ No newline at end of file
index b93300505bdc63a257874c55b8ad790fdd8cf00c..639a3f036fb1323c7bbcaeec57cf1b423c9d1f50 100644 (file)
@@ -28,7 +28,7 @@
         <% if current_user %>\r
            <div style="text-align: right; padding: 5px">\r
              <%= link_to_remote "Add a comment", \r
-                       :url => { :controller => "reviews", :action => "form_comment", :review_id => review.id, :rule_failure_id => review.rule_failure_id },\r
+                       :url => { :controller => "reviews", :action => "form_comment", :review_id => review.id, :rule_failure_permanent_id => review.rule_failure_permanent_id },\r
                        :update => "createComment" + review.id.to_s, \r
                        :complete => "$('commentText" + review.id.to_s + "').focus()" -%>\r
            </div>\r
index 0c4c474c601e378ed71406fee03f37439bb87ac7..6eae877ae47f2026a495da783048ddc15f0eab50 100644 (file)
@@ -1,5 +1,5 @@
-if @reviews
-  page.replace_html "reviewFailure" + @rule_failure_id.to_s, :partial => "list", :locals => { :reviews => @reviews }
-else
-  page.replace_html "createComment" + @review_comment.review_id.to_s, :partial => "form_comment"
+if @reviews\r
+  page.replace_html "reviewFailure" + @rule_failure_permanent_id.to_s, :partial => "list", :locals => { :reviews => @reviews }\r
+else\r
+  page.replace_html "createComment" + @review_comment.review_id.to_s, :partial => "form_comment"\r
 end
\ No newline at end of file
index aa8ac5ad6182ac71473b44844dc8a5205bd4b7e3..5f802780b34f7cb36f75f4871c4c40f179a9eba7 100644 (file)
@@ -1,6 +1,6 @@
 if @reviews\r
-  page.replace_html "createReviewLink" + @review.rule_failure_id.to_s, image_tag("reviews/review.png")\r
-  page.replace_html "reviewFailure" + @review.rule_failure_id.to_s, :partial => "list", :locals => { :reviews => @reviews }\r
+  page.replace_html "createReviewLink" + @review.rule_failure_permanent_id.to_s, image_tag("reviews/review.png")\r
+  page.replace_html "reviewFailure" + @review.rule_failure_permanent_id.to_s, :partial => "list", :locals => { :reviews => @reviews }\r
 else\r
-  page.replace_html "reviewFailure" + @review.rule_failure_id.to_s, :partial => "form"\r
+  page.replace_html "reviewFailure" + @review.rule_failure_permanent_id.to_s, :partial => "form"\r
 end
\ No newline at end of file
index 4978f21e5c5b4f4d28de9363535b6ef455fc7206..467e8c63fcdf7460549d711b000e640b3d9d3698 100644 (file)
@@ -25,19 +25,20 @@ class CreateReview < ActiveRecord::Migration
 \r
   def self.up\r
     create_table 'reviews' do |t|\r
-      t.column 'created_at',           :datetime\r
-      t.column 'updated_at',           :datetime\r
-      t.column 'user_id',                      :integer,       :null => true\r
-      t.column 'review_type',          :string,        :null => true,  :limit => 10\r
-      t.column 'status',                       :string,        :null => true,  :limit => 10\r
-      t.column 'severity',                     :string,        :null => true,  :limit => 10\r
-      t.column 'rule_failure_id',      :integer,       :null => true   \r
-      t.column 'resource_id',          :integer,       :null => true   \r
-      t.column 'resource_line',        :integer,       :null => true      \r
+      t.column 'created_at',                                   :datetime\r
+      t.column 'updated_at',                                   :datetime\r
+      t.column 'user_id',                                              :integer,       :null => true\r
+      t.column 'review_type',                                  :string,        :null => true,  :limit => 10\r
+      t.column 'status',                                               :string,        :null => true,  :limit => 10\r
+      t.column 'severity',                                             :string,        :null => true,  :limit => 10\r
+      t.column 'rule_failure_permanent_id',    :integer,       :null => true   \r
+      t.column 'resource_id',                                  :integer,       :null => true   \r
+      t.column 'resource_line',                                :integer,       :null => true      \r
     end\r
     \r
     create_table 'review_comments' do |t|\r
       t.column 'created_at',           :datetime\r
+      t.column 'updated_at',           :datetime\r
       t.column 'review_id',            :integer\r
       t.column 'user_id',                      :integer,       :null => true\r
       t.column 'review_text',          :text,          :null => true\r