From 550ed0aa483d0b31a6f844a728340e5a81a753ed Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Tue, 11 Mar 2014 12:53:49 +0000 Subject: Graceful failure of new_comment route Fixes https://github.com/mysociety/alaveteli/issues/662 If /annotate/request/:url_title is accessed when comments are disabled an exception is incorrectly thrown. Conditionals should be used for control flow, so now the action redirects to the info_request path and displays a notice. --- app/controllers/comment_controller.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'app/controllers/comment_controller.rb') diff --git a/app/controllers/comment_controller.rb b/app/controllers/comment_controller.rb index cda56a211..4904463b5 100644 --- a/app/controllers/comment_controller.rb +++ b/app/controllers/comment_controller.rb @@ -21,13 +21,15 @@ class CommentController < ApplicationController else raise "Unknown type " + params[:type] end - + # Are comments disabled on this request? # # There is no “add comment” link when comments are disabled, so users should - # not usually hit this unless they are explicitly attempting to avoid the comment - # block, so we just raise an exception. - raise "Comments are not allowed on this request" if !@info_request.comments_allowed? + # not usually hit this unless they are explicitly attempting to avoid the comment block + unless @info_request.comments_allowed? + redirect_to request_url(@info_request), :notice => "Comments are not allowed on this request" + return + end # Banned from adding comments? if !authenticated_user.nil? && !authenticated_user.can_make_comments? -- cgit v1.2.3