aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-05-30 12:28:47 +0200
committerFabrice Bellingard <bellingard@gmail.com>2011-05-30 19:19:11 +0200
commit9d66cd90629de1ccfc144636f66a96efbdfd53d8 (patch)
tree0cbd16993e6da900d8e134c1f013c710d223fdbd /sonar-server/src
parent437c987ea9938be8ec0c31ba8ecaca1a4fcb79d6 (diff)
downloadsonarqube-9d66cd90629de1ccfc144636f66a96efbdfd53d8.tar.gz
sonarqube-9d66cd90629de1ccfc144636f66a96efbdfd53d8.zip
SONAR-2404 Extend the Review web service API to create & update
- Server side: delete last comment of a review
Diffstat (limited to 'sonar-server/src')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb49
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/review.rb1
2 files changed, 49 insertions, 1 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb
index acef45b743a..4d485008464 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb
@@ -25,6 +25,7 @@ class Api::ReviewsController < Api::ApiController
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
verify :method => :put, :only => [ :update ]
verify :method => :post, :only => [ :create ]
+ verify :method => :delete, :only => [ :delete ]
def index
convert_markdown=(params[:output]=='HTML')
@@ -38,8 +39,8 @@ class Api::ReviewsController < Api::ApiController
#
# POST /api/reviews
# Required parameters:
- # - 'text' : the text of the comment
# - 'violation_id' : the violation on which the review shoul be created
+ # - 'text' : the text of the comment
#
# Optional parameters :
# - 'assignee' : login used to create a review directly assigned
@@ -133,6 +134,7 @@ class Api::ReviewsController < Api::ApiController
# 3- Modify the review
if !false_positive.blank?
raise "'false_positive' parameter must be either 'true' or 'false'." unless false_positive=='true' || false_positive=='false'
+ raise "Review 'false_positive' status is already " + false_positive if review.false_positive == false_positive
raise "'new_text' parameter is mandatory with 'false_positive'." if new_text.blank?
review.set_false_positive(false_positive=='true', :user => current_user, :text => new_text)
elsif !assignee.blank?
@@ -165,6 +167,51 @@ class Api::ReviewsController < Api::ApiController
end
+ #
+ # --- Delete the last comment of a review ---
+ #
+ # DELETE /api/reviews
+ # Required parameters:
+ # - 'id' : the review id
+ # - 'comment_id' : for the moment, only 'last_comment' value is accepted
+ #
+ # Example :
+ # - DELETE "/api/reviews/update?id=1&comment=last_comment
+ #
+ def delete
+ begin
+ # 1- Get some parameters
+ convert_markdown=(params[:output]=='HTML')
+ comment_id = params[:comment_id]
+ raise "'comment' parameter is missing." unless comment_id
+ raise "Currently, only 'last_comment' is accepted for the 'comment' parameter." unless comment_id == 'last_comment'
+
+ # 2- Get the review or create one
+ raise "No 'id' parameter has been provided." unless params[:id]
+ review = Review.find(params[:id], :include => ['project', 'review_comments'])
+ unless has_rights_to_modify?(review.project)
+ access_denied
+ return
+ end
+
+ # 3- Delete the last comment if possible
+ raise "Cannot delete the only existing comment of this review." if review.comments.size == 1
+ last_comment = review.comments.last
+ raise "You do not have the rights to edit this comment as it is not yours." unless last_comment.user == current_user
+ review.delete_comment(last_comment.id)
+
+ # 4- And finally send back the review
+ render_reviews([review], convert_markdown)
+
+ rescue ApiException => e
+ render_error(e.msg, e.code)
+
+ rescue Exception => e
+ render_error(e.message, 400)
+ end
+ end
+
+
private
def render_reviews(reviews, convert_markdown)
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
index 8b0a46f746f..fe2d2073f4d 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
@@ -79,6 +79,7 @@ class Review < ActiveRecord::Base
def delete_comment(comment_id)
comment=comments.find(comment_id)
+ comments.pop
if comment
comment.delete
touch