end\r
\r
def form\r
+ rule_failure = find_last_rule_failure_with_permanent_id params[:rule_failure_permanent_id]\r
@review = Review.new\r
- @review.rule_failure_permanent_id = params[:rule_failure_permanent_id]\r
+ @review.rule_failure_permanent_id = rule_failure.permanent_id\r
@review.user = current_user\r
- @review.severity = Review.default_severity\r
+ @review.assignee = current_user\r
+ @user_options = add_all_users []\r
+ @review.title = rule_failure.message\r
@review_comment = ReviewComment.new\r
@review_comment.review_text = ""\r
render :partial => "form"\r
end\r
\r
def create\r
- unless has_rights_to_create? params[:review][:rule_failure_permanent_id]\r
+ rule_failure = find_last_rule_failure_with_permanent_id params[:review][:rule_failure_permanent_id]\r
+ unless has_rights_to_create? rule_failure\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.severity = Sonar::RulePriority.to_s rule_failure.failure_level\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
if @review.valid?\r
@review.save\r
@reviews = find_reviews_for_rule_failure @review.rule_failure_permanent_id\r
+ else\r
+ @user_options = add_all_users []\r
end\r
render "create_result"\r
end\r
\r
def create_comment\r
- unless has_rights_to_create? params[:rule_failure_permanent_id]\r
+ rule_failure = find_last_rule_failure_with_permanent_id params[:rule_failure_permanent_id]\r
+ unless has_rights_to_create? rule_failure\r
render :text => "<b>Cannot create the comment</b> : access denied."\r
return\r
end\r
@user_names << ["Me", current_user.id]\r
default_user = [current_user.id]\r
end\r
- User.find( :all ).each do |user|\r
- @user_names << [user.name, user.id.to_s]\r
- end\r
+ add_all_users @user_names\r
@review_authors = filter_any(params[:review_authors]) || default_user\r
@comment_authors = filter_any(params[:comment_authors]) || default_user\r
@severities = filter_any(params[:severities]) || [""]\r
@statuses = filter_any(params[:statuses]) || ["open"]\r
end\r
+ \r
+ def add_all_users ( user_options )\r
+ User.find( :all ).each do |user|\r
+ user_options << [user.name, user.id.to_s]\r
+ end\r
+ return user_options\r
+ end\r
\r
def filter_any(array)\r
if array && array.size>1 && array.include?("")\r
return Review.find :all, :conditions => ['rule_failure_permanent_id=?', rule_failure_permanent_id]\r
end\r
\r
- def find_rule_failure_with_permanent_id ( rule_failure_permanent_id )\r
+ def find_last_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
- def has_rights_to_create? ( rule_failure_permanent_id )\r
+ def has_rights_to_create? ( rule_failure )\r
return false unless current_user\r
\r
- project = find_rule_failure_with_permanent_id( rule_failure_permanent_id).snapshot.root_project\r
+ project = rule_failure.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 Sonar; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
-#
-class Review < ActiveRecord::Base
- belongs_to :user
- belongs_to :rule_failure
- belongs_to :resource, :class_name => "Project", :foreign_key => "resource_id"
- has_many :review_comments, :order => "created_at", :dependent => :destroy
- validates_presence_of :user, :message => "can't be empty"
- validates_presence_of :review_type, :message => "can't be empty"
- validates_presence_of :status, :message => "can't be empty"
-
- SEVERITY_INFO = "info"
- SEVERITY_MINOR = "minor"
- SEVERITY_MAJOR = "major"
- SEVERITY_CRITICAL = "critical"
- SEVERITY_BLOCKER = "blocker"
-
- TYPE_COMMENTS = "comments"
- TYPE_FALSE_POSITIVE = "f-positive"
-
- STATUS_OPEN = "open"
- STATUS_CLOSED = "closed"
-
-
- def self.default_severity
- return SEVERITY_MAJOR
- end
-
- def self.default_type
- return TYPE_COMMENTS
- end
-
- def self.default_status
- return STATUS_OPEN
- end
-
- def self.severity_options
- severity_ops = []
- severity_ops << ["Info", SEVERITY_INFO]
- severity_ops << ["Minor", SEVERITY_MINOR]
- severity_ops << ["Major", SEVERITY_MAJOR]
- severity_ops << ["Critical", SEVERITY_CRITICAL]
- 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
+#\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 Review < ActiveRecord::Base\r
+ belongs_to :user\r
+ belongs_to :assignee, :class_name => "User", :foreign_key => "assignee_id"\r
+ belongs_to :resource, :class_name => "Project", :foreign_key => "resource_id"\r
+ has_many :review_comments, :order => "created_at", :dependent => :destroy\r
+ validates_presence_of :user, :message => "can't be empty"\r
+ validates_presence_of :assignee, :message => "can't be empty"\r
+ validates_presence_of :title, :message => "can't be empty"\r
+ validates_presence_of :review_type, :message => "can't be empty"\r
+ validates_presence_of :status, :message => "can't be empty"\r
+\r
+ SEVERITY_INFO = "INFO"\r
+ SEVERITY_MINOR = "MINOR"\r
+ SEVERITY_MAJOR = "MAJOR"\r
+ SEVERITY_CRITICAL = "CRITICAL"\r
+ SEVERITY_BLOCKER = "BLOCKER"\r
+ \r
+ TYPE_COMMENTS = "comments"\r
+ TYPE_FALSE_POSITIVE = "f-positive"\r
+ \r
+ STATUS_OPEN = "open"\r
+ STATUS_CLOSED = "closed"\r
+\r
+\r
+ def self.default_severity\r
+ return SEVERITY_MAJOR\r
+ end\r
+ \r
+ def self.default_type\r
+ return TYPE_COMMENTS\r
+ end\r
+\r
+ def self.default_status\r
+ return STATUS_OPEN\r
+ end\r
+ \r
+ def self.severity_options\r
+ severity_ops = []\r
+ severity_ops << ["Info", SEVERITY_INFO]\r
+ severity_ops << ["Minor", SEVERITY_MINOR]\r
+ severity_ops << ["Major", SEVERITY_MAJOR]\r
+ severity_ops << ["Critical", SEVERITY_CRITICAL]\r
+ severity_ops << ["Blocker", SEVERITY_BLOCKER]\r
+ return severity_ops\r
+ end\r
+ \r
+ def self.status_options\r
+ status_ops = []\r
+ status_ops << ["Open", STATUS_OPEN]\r
+ status_ops << ["Closed", STATUS_CLOSED]\r
+ return status_ops\r
+ end\r
+\r
+end\r
-<b>Create a new review</b>\r
<% form_for :review, @review do |f| %>\r
<%= f.hidden_field :rule_failure_permanent_id %>\r
- Severity: \r
- <%= select_tag "review[severity]", options_for_select(Review.severity_options, @review.severity) %>\r
+ <b>New review</b>: \r
+ <%= f.text_field :title, :size => 100 %>\r
+ <br/>\r
+ Assignee: \r
+ <%= select_tag "review[assignee_id]", options_for_select(@user_options, @review.assignee.id.to_s) %>\r
<br/>\r
<%= text_area :review_comment, :review_text, :id => "reviewText", :rows => 8, :style => "width:100%" %>\r
<br/>\r
:id => "commentText" + @review_comment.review_id.to_s,\r
:style => "width:100%" %>\r
<br/>\r
- <%= submit_to_remote 'create_btn', 'Add comment', \r
+ <%= submit_to_remote 'create_btn', 'Post', \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
+<%\r
+ last_comment_user_id = -1\r
+%>\r
<div id="review<%= review.id -%>">\r
<div>\r
- <b>Review initiated by <%= h(review.user.name) -%></b> - <%= l review.created_at -%>\r
- <br/>\r
- Status: <%= h(review.status) -%> / Severity: <%= h(review.severity) -%> \r
+ <b>Review #<%= review.id -%> - <%= h(review.title) -%></b>\r
+ <br/>\r
+ <i>Assigned to <%= h(review.assignee.name) -%></i>\r
</div>\r
\r
- <div style="margin-top: 10px">\r
- <table style="width:100%">\r
+ <div style="margin-top: 10px; margin-left: 20px">\r
<% unless review.review_comments.blank? \r
review.review_comments.each do |review_comment|\r
+ last_comment_user_id = review_comment.user_id\r
%>\r
- <tr>\r
- <td style="width:180px; vertical-align:top; padding: 5px; border:solid 1px grey; background-color: #F7F7F7">\r
- <%= image_tag("user.png") -%> <b><%= h(review_comment.user.name) -%></b> ยป\r
- <br/><%= l review_comment.created_at -%>\r
+ <table style="width:100%; margin-bottom: 3px">\r
+ <tr style="border: solid 1px grey; background-color: #F7F7F7">\r
+ <td style="width:180px; vertical-align:top; padding: 2px 2px 2px 10px; font-weight: bold">\r
+ <%= image_tag("user.png") -%> <b><%= h(review_comment.user.name) -%></b>\r
</td>\r
- <td style="vertical-align:top; padding: 5px; border:solid 1px grey; background: white">\r
- <%= h(review_comment.review_text) -%>\r
+ <td style="vertical-align: top; padding: 2px 10px 2px 2px; color: grey; text-align: right; font-style: italic">\r
+ <%= l review_comment.created_at -%>\r
</td>\r
</tr>\r
+ <tr style="border: solid 1px grey;">\r
+ <td colspan="2" style="padding: 5px;">\r
+ <%= h(review_comment.review_text) -%>\r
+ </td>\r
+ </tr>\r
+ </table>\r
<% \r
end\r
end\r
%>\r
- </table>\r
\r
<% if current_user %>\r
<div style="text-align: right; padding: 5px">\r
- <%= link_to_remote "Add a comment", \r
+ <% if current_user.id == last_comment_user_id %>\r
+ <%= image_tag("pencil.png") -%>\r
+ <%= link_to_remote "Edit my last comment", \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
+ \r
+ <% end %>\r
+ <%= image_tag("pencil.png") -%>\r
+ <%= link_to_remote "Add a new comment", \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
t.column 'created_at', :datetime\r
t.column 'updated_at', :datetime\r
t.column 'user_id', :integer, :null => true\r
+ t.column 'assignee_id', :integer, :null => true\r
+ t.column 'title', :string, :null => true, :limit => 500\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