-#
-# 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 ReviewsController < ApplicationController
-
- 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
- render "create_comment_result"
- 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
+#\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
+\r
+class ReviewsController < ApplicationController\r
+\r
+ SECTION=Navigation::SECTION_HOME\r
+ \r
+ verify :method => :post, :only => [ :create, :create_comment ], :redirect_to => { :action => :error_not_post }\r
+ \r
+ def index\r
+ init_params\r
+ \r
+ @reviews = []\r
+ unless params.blank?\r
+ @reviews = Review.find :all, :conditions => ['status=?', @statuses]\r
+ end\r
+ end\r
+ \r
+ def list\r
+ reviews = findReviewsForRuleFailure params[:rule_failure_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.user = current_user\r
+ @review.severity = Review.default_severity\r
+ @review_comment = ReviewComment.new\r
+ @review_comment.review_text = ""\r
+ render :partial => "form"\r
+ end\r
+ \r
+ def form_comment\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
+ render :partial => "form_comment"\r
+ end\r
+ \r
+ def create\r
+ unless hasRightsToCreate? params[:review][:rule_failure_id]\r
+ render :text => "<b>Cannot create the review</b> : access denied."\r
+ return\r
+ end\r
+ \r
+ @review = Review.new(params[:review])\r
+ @review.user = current_user\r
+ @review.status = Review.default_status\r
+ @review.review_type = Review.default_type\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 = findReviewsForRuleFailure @review.rule_failure_id\r
+ end\r
+ render "create_result"\r
+ end\r
+ \r
+ def create_comment\r
+ unless hasRightsToCreate? params[:rule_failure_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
+ if @review_comment.valid?\r
+ @review_comment.save\r
+ @reviews = findReviewsForRuleFailure @rule_failure_id\r
+ end\r
+ render "create_comment_result"\r
+ end\r
+ \r
+ \r
+ ## -------------- PRIVATE -------------- ##\r
+ private\r
+ \r
+ def init_params\r
+ users = User.find :all\r
+ @user_names = [["Any", ""]]\r
+ users.each do |user|\r
+ @user_names << [user.name, user.id.to_s]\r
+ end\r
+ @review_authors = filter_any(params[:review_authors]) || [""]\r
+ @comment_authors = filter_any(params[:comment_authors]) || [""]\r
+ @severities = filter_any(params[:severities]) || [""]\r
+ @statuses = filter_any(params[:statuses]) || ["open"]\r
+ end\r
+ \r
+ def filter_any(array)\r
+ if array && array.size>1 && array.include?('')\r
+ array=[''] #keep only 'any'\r
+ end\r
+ array\r
+ end\r
+ \r
+ def findReviewsForRuleFailure ( rule_failure_id )\r
+ return Review.find :all, :conditions => ['rule_failure_id=?', rule_failure_id]\r
+ end\r
+ \r
+ def hasRightsToCreate? ( rule_failure_id )\r
+ return false unless current_user\r
+ \r
+ project = RuleFailure.find( rule_failure_id, :include => ['snapshot'] ).snapshot.root_project\r
+ unless has_role?(:user, project)\r
+ return false\r
+ end\r
+ return true\r
+ end\r
+ \r
+ def error_not_post\r
+ render :text => "Create actions must use POST method."\r
+ end\r
+ \r
+end\r