]> source.dussan.org Git - sonarqube.git/commitdiff
[SONAR-2327] First implementation of the review service
authorFabrice Bellingard <bellingard@gmail.com>
Fri, 8 Apr 2011 16:12:07 +0000 (18:12 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Wed, 20 Apr 2011 06:49:57 +0000 (08:49 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/reviews_helper.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.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/_index.html.erb [deleted file]
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_list.html.erb [new file with mode: 0644]
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/app/views/reviews/index.html.erb [new file with mode: 0644]

index 464bfdde0cec225bf6fb969f784182bf6350f69a..8dea0fb9b63354e53208fe9123888e15e81310c0 100644 (file)
 
 class ReviewsController < ApplicationController
 
-       SECTION=Navigation::SECTION_RESOURCE
-       
-       verify :method => :post, :only => [  :create, :create_comment ], :redirect_to => { :action => :error_not_post }
-       
-       def index
-         reviews = findReviewsForRuleFailure params[:rule_failure_id]
-         render :partial => "index", :locals => { :reviews => reviews }
-       end
-       
-       def form
-         @review = Review.new
-         @review.rule_failure_id = params[:violation_id]
-         @review.user = current_user
-         @review.severity = Review.default_severity
-         @review_comment = ReviewComment.new
-         @review_comment.review_text = ""
-         render :partial => "form"
-       end
-       
-       def form_comment
-         @review_comment = ReviewComment.new
-         @review_comment.user = current_user
-         @review_comment.review_id = params[:review_id]
-         @review_comment.review_text = ""
-         @rule_failure_id = params[:rule_failure_id]
-         render :partial => "form_comment"
-       end
-       
-       def create
-         unless hasRightsToCreate? params[:review][:rule_failure_id]
-           render :text => "<b>Cannot create the review</b> : access denied."
-           return
-         end
-                 
-         @review = Review.new(params[:review])
-         @review.user = current_user
-         @review.status = Review.default_status
-         @review.review_type = Review.default_type
-         @review_comment = ReviewComment.new(params[:review_comment])
-         @review_comment.user = current_user
-         @review.review_comments << @review_comment
-         if @review.valid?
-           @review.save
-               @reviews = findReviewsForRuleFailure @review.rule_failure_id
-         end
-         render "create_result"
-       end
-       
-       def create_comment
-         unless hasRightsToCreate? params[:rule_failure_id]
-           render :text => "<b>Cannot create the comment</b> : access denied."
-           return
-         end
-       
+  SECTION=Navigation::SECTION_HOME
+  
+  verify :method => :post, :only => [  :create, :create_comment ], :redirect_to => { :action => :error_not_post }
+  
+  def index
+    init_params
+    
+    @reviews = []
+    unless params.blank?
+      @reviews = Review.find :all, :conditions => ['status=?', @statuses]
+    end
+  end
+  
+  def list
+    reviews = findReviewsForRuleFailure params[:rule_failure_id]
+    render :partial => "index", :locals => { :reviews => reviews }
+  end
+  
+  def form
+    @review = Review.new
+    @review.rule_failure_id = params[:violation_id]
+    @review.user = current_user
+    @review.severity = Review.default_severity
+    @review_comment = ReviewComment.new
+    @review_comment.review_text = ""
+    render :partial => "form"
+  end
+  
+  def form_comment
+    @review_comment = ReviewComment.new
+    @review_comment.user = current_user
+    @review_comment.review_id = params[:review_id]
+    @review_comment.review_text = ""
+    @rule_failure_id = params[:rule_failure_id]
+    render :partial => "form_comment"
+  end
+  
+  def create
+    unless hasRightsToCreate? params[:review][:rule_failure_id]
+      render :text => "<b>Cannot create the review</b> : access denied."
+      return
+    end
+        
+    @review = Review.new(params[:review])
+    @review.user = current_user
+    @review.status = Review.default_status
+    @review.review_type = Review.default_type
+    @review_comment = ReviewComment.new(params[:review_comment])
+    @review_comment.user = current_user
+    @review.review_comments << @review_comment
+    if @review.valid?
+      @review.save
+      @reviews = findReviewsForRuleFailure @review.rule_failure_id
+    end
+    render "create_result"
+  end
+  
+  def create_comment
+    unless hasRightsToCreate? params[:rule_failure_id]
+      render :text => "<b>Cannot create the comment</b> : access denied."
+      return
+    end
+  
       @review_comment = ReviewComment.new(params[:review_comment])
       @review_comment.user = current_user
       @rule_failure_id = params[:rule_failure_id]
       if @review_comment.valid?
-           @review_comment.save
-           @reviews = findReviewsForRuleFailure @rule_failure_id
-         end
+      @review_comment.save
+      @reviews = findReviewsForRuleFailure @rule_failure_id
+    end
       render "create_comment_result"
-       end
-       
-       private
-       
-       def findReviewsForRuleFailure ( rule_failure_id )
-         return Review.find :all, :conditions => ['rule_failure_id=?', rule_failure_id]
-       end
-       
-       def hasRightsToCreate? ( rule_failure_id )
-         return false unless current_user
-         
-         project = RuleFailure.find( rule_failure_id, :include => ['snapshot'] ).snapshot.root_project
-         unless has_role?(:user, project)
-           return false
-         end
-         return true
-       end
-       
-       def error_not_post
-         render :text => "Create actions must use POST method."
-       end
-       
+  end
+  
+  
+  ## -------------- PRIVATE -------------- ##
+  private
+  
+  def init_params
+    users = User.find :all
+    @user_names = [["Any", ""]]
+    users.each do |user|
+      @user_names << [user.name, user.id.to_s]
+    end
+    @review_authors = filter_any(params[:review_authors]) || [""]
+    @comment_authors = filter_any(params[:comment_authors]) || [""]
+    @severities = filter_any(params[:severities]) || [""]
+    @statuses = filter_any(params[:statuses]) || ["open"]
+  end
+  
+  def filter_any(array)
+    if array && array.size>1 && array.include?('')
+      array=['']  #keep only 'any'
+    end
+    array
+  end
+  
+  def findReviewsForRuleFailure ( rule_failure_id )
+    return Review.find :all, :conditions => ['rule_failure_id=?', rule_failure_id]
+  end
+  
+  def hasRightsToCreate? ( rule_failure_id )
+    return false unless current_user
+    
+    project = RuleFailure.find( rule_failure_id, :include => ['snapshot'] ).snapshot.root_project
+    unless has_role?(:user, project)
+      return false
+    end
+    return true
+  end
+  
+  def error_not_post
+    render :text => "Create actions must use POST method."
+  end
+  
 end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/reviews_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/reviews_helper.rb
new file mode 100644 (file)
index 0000000..c615c99
--- /dev/null
@@ -0,0 +1,40 @@
+#
+# 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
+#
+module ReviewsHelper
+  
+  def self.severity_options_with_any
+    severity_ops = []
+    severity_ops << ["Any", ""]
+    Review.severity_options.each do |severity|
+      severity_ops << severity
+    end
+    return severity_ops
+  end
+  
+  def self.status_options_with_any
+    status_ops = []
+    status_ops << ["Any", ""]
+    Review.status_options.each do |status|
+      status_ops << status
+    end
+    return status_ops
+  end
+
+end
index 2e42efb6f15e4de20c54560d7127152909740868..6fc2db26717b660cbd6cefc277b64e622f3f2dd7 100644 (file)
@@ -60,5 +60,12 @@ class Review < ActiveRecord::Base
     severity_ops << ["Blocker", SEVERITY_BLOCKER]
     return severity_ops
   end
+  
+  def self.status_options
+    status_ops = []
+    status_ops << ["Open", STATUS_OPEN]
+    status_ops << ["Closed", STATUS_CLOSED]
+    return status_ops
+  end
 
 end
index fe68331926607ecf97ceb301c557b605870da735..e6ab11b5d22d2044f0da61f5e92a3a7c64301888 100644 (file)
@@ -26,6 +26,7 @@
         <ul>
         <% if selected_section==Navigation::SECTION_HOME %>
           <li class="<%= 'selected' if controller.controller_path=='filters' -%>"><a href="<%= ApplicationController.root_context -%>/filters/index">Filters</a></li>
+          <li class="<%= 'selected' if controller.controller_path=='reviews' -%>"><a href="<%= ApplicationController.root_context -%>/reviews/index">Reviews</a></li>
           <li class="<%= 'selected' if controller.controller_path=='dependencies' -%>"><a href="<%= ApplicationController.root_context -%>/dependencies/index">Dependencies</a></li>
 
           <% controller.java_facade.getPages(Navigation::SECTION_HOME, nil, nil, nil).each do |page|
index 1b1bdeee3316826faa991112506250c6212eff57..6ac4247163f0248f5bf7137e5d23e86fdf180816 100644 (file)
@@ -32,7 +32,7 @@
                <% end %>
                
                <div id="reviewFailure<%= violation.id -%>" style="padding:5px; background:white; display:<%= displayReviewFailureDiv -%>">
-                 <%= render :partial => "reviews/index", :locals => { :reviews => violation.reviews } %>
+                 <%= render :partial => "reviews/list", :locals => { :reviews => violation.reviews } %>
                </div>
       </td>
       
index 6bf3b47b6eb254ec482d927e383c1842037df3cb..ea5710840cb8b90409079d3c9be2ca6ebe5a2c7d 100644 (file)
@@ -9,7 +9,7 @@
       <%= 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 => 'index', :rule_failure_id => @rule_failure_id.to_s },
+                     :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%>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_index.html.erb
deleted file mode 100644 (file)
index 2fbbd00..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<% 
-   unless reviews.blank? 
-     reviews.each do |review|
-%>
-
-  <%= render :partial => "reviews/view", :locals => { :review => review } %>
-
-<% 
-     end
-   end
-%>
\ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_list.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_list.html.erb
new file mode 100644 (file)
index 0000000..2fbbd00
--- /dev/null
@@ -0,0 +1,11 @@
+<% 
+   unless reviews.blank? 
+     reviews.each do |review|
+%>
+
+  <%= render :partial => "reviews/view", :locals => { :review => review } %>
+
+<% 
+     end
+   end
+%>
\ No newline at end of file
index ba5a4d8fb5384ca2e2005a89672c030593d546a8..0c4c474c601e378ed71406fee03f37439bb87ac7 100644 (file)
@@ -1,5 +1,5 @@
 if @reviews
-  page.replace_html "reviewFailure" + @rule_failure_id.to_s, :partial => "index", :locals => { :reviews => @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"
 end
\ No newline at end of file
index bdf20061a893e418d470de7201accd01e18663d7..0a771dac806f51cd6c7b071c886440f590f29843 100644 (file)
@@ -1,6 +1,6 @@
 if @reviews
   page.hide "createReviewLink" + @review.rule_failure_id.to_s
-  page.replace_html "reviewFailure" + @review.rule_failure_id.to_s, :partial => "index", :locals => { :reviews => @reviews }
+  page.replace_html "reviewFailure" + @review.rule_failure_id.to_s, :partial => "list", :locals => { :reviews => @reviews }
 else
   page.replace_html "reviewFailure" + @review.rule_failure_id.to_s, :partial => "form"
 end
\ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb
new file mode 100644 (file)
index 0000000..9394ad5
--- /dev/null
@@ -0,0 +1,45 @@
+<h1>Reviews</h1>
+
+<div class="tabs-panel marginbottom10 background-gray">
+  <% form_tag({:action => 'index'}, {:method => 'get'}) do %>
+   <table class="spaced" id="search_table">
+     <tr>
+       <td class="left" valign="top" width="1%" nowrap>
+         <span class="note">Created by</span><br/>
+         <%= select_tag "review_authors", options_for_select(@user_names, @review_authors), :multiple => true, :size => 6 %>
+       </td>
+       <td class="left" valign="top" width="1%" nowrap>
+         <span class="note">Commented by</span><br/>
+         <%= select_tag "comment_authors", options_for_select(@user_names, @comment_authors), :multiple => true, :size => 6 %>
+       </td>
+       <td class="left" valign="top" width="1%" nowrap>
+         <span class="note">Severity</span><br/>
+         <%= select_tag "severities", options_for_select(ReviewsHelper.severity_options_with_any, @severities), :multiple => true, :size => 6 %>
+       </td>
+       <td class="left" valign="top" width="1%" nowrap>
+         <span class="note">Status</span><br/>
+         <%= select_tag "statuses", options_for_select(ReviewsHelper.status_options_with_any, @statuses), :multiple => true, :size => 6 %>
+       </td>
+       <td class="left" valign="top" >
+         <br/>
+         <%= submit_tag "Search", :id => 'submit_search' %>
+       </td>
+     </tr>
+   </table>
+  <% end %>
+</div>
+
+<div id="reviewList">
+<% 
+   unless @reviews.blank? 
+     @reviews.each do |review|
+%>
+
+  <%= render :partial => "reviews/view", :locals => { :review => review } %>
+
+<% 
+     end
+   end
+%>
+<div>
+