diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2011-04-11 10:21:42 +0200 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2011-04-20 08:49:58 +0200 |
commit | be76b328e72c85a582fcb2e3112f0a9ae6f4d5ed (patch) | |
tree | 53df481d779fe71e74b1fbecbc50b6286cdaf48f /sonar-server/src | |
parent | 7b523424f7fbb34f82cac3b0e053c56b122f254a (diff) | |
download | sonarqube-be76b328e72c85a582fcb2e3112f0a9ae6f4d5ed.tar.gz sonarqube-be76b328e72c85a582fcb2e3112f0a9ae6f4d5ed.zip |
[SONAR-2327] Add more params to SQL query for reviews service
Diffstat (limited to 'sonar-server/src')
-rw-r--r-- | sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb | 46 |
1 files changed, 39 insertions, 7 deletions
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 ac66e350e0e..c266654003f 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 @@ -29,7 +29,7 @@ class ReviewsController < ApplicationController @reviews = []
unless params.blank?
- @reviews = Review.find :all, :conditions => ['status=?', @statuses]
+ findReviewsForUserQuery
end
end
@@ -98,24 +98,56 @@ class ReviewsController < ApplicationController private
def init_params
- users = User.find :all
@user_names = [["Any", ""]]
- users.each do |user|
+ default_user = [""]
+ if current_user
+ @user_names << ["Me", current_user.id]
+ default_user = [current_user.id]
+ end
+ User.find( :all ).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]) || [""]
+ @review_authors = filter_any(params[:review_authors]) || default_user
+ @comment_authors = filter_any(params[:comment_authors]) || default_user
@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'
+ if array && array.size>1 && array.include?("")
+ array=[""]
end
array
end
+ def findReviewsForUserQuery
+ @conditions=""
+ @values=[]
+ @need_and = false;
+ @need_or = false;
+ add_sql_query_param "status", @statuses
+ add_sql_query_param "severity", @severities
+ add_sql_query_param "user_id", @review_authors
+
+ @reviews = Review.find :all, :conditions => [@conditions] + @values
+ end
+
+ def add_sql_query_param ( field, search_params )
+ unless search_params == [""]
+ @conditions += " AND" if @need_and
+ @conditions += "("
+ search_params.each do |search_param|
+ @conditions += " OR" if @need_or
+ @conditions += " " + field + "=?"
+ @values << search_param
+ @need_or = true
+ end
+ @conditions += ")"
+ @need_or = false;
+ @need_and = true;
+ end
+ end
+
def findReviewsForRuleFailure ( rule_failure_id )
return Review.find :all, :conditions => ['rule_failure_id=?', rule_failure_id]
end
|