diff options
author | Gareth Rees <gareth@mysociety.org> | 2014-03-11 14:37:48 +0000 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2014-03-13 11:48:43 +0000 |
commit | 73d0f361fd4e49f11b3b99db7b3dc2b06dc9e9d7 (patch) | |
tree | 6f4af5f7e1c3043d9a45e5d57ad8c6be3026d7f1 /app/controllers/comment_controller.rb | |
parent | 68a9536dc68f35965156aeb84c9f4c5bee391159 (diff) |
Use filter to reject if user is banned
Extract checking whether a user is banned from making Comments on an
InfoRequest to a filter in CommentController.
Removes responsibility from the #new method.
Adds a missing spec.
Diffstat (limited to 'app/controllers/comment_controller.rb')
-rw-r--r-- | app/controllers/comment_controller.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/app/controllers/comment_controller.rb b/app/controllers/comment_controller.rb index ce022f000..5e39c3a2c 100644 --- a/app/controllers/comment_controller.rb +++ b/app/controllers/comment_controller.rb @@ -9,6 +9,7 @@ class CommentController < ApplicationController before_filter :find_info_request, :only => [ :new ] before_filter :create_track_thing, :only => [ :new ] before_filter :reject_unless_comments_allowed, :only => [ :new ] + before_filter :reject_if_user_banned, :only => [ :new ] protect_from_forgery :only => [ :new ] def new @@ -19,13 +20,6 @@ class CommentController < ApplicationController })) end - # Banned from adding comments? - if !authenticated_user.nil? && !authenticated_user.can_make_comments? - @details = authenticated_user.can_fail_html - render :template => 'user/banned' - return - end - if params[:comment] # XXX this check should theoretically be a validation rule in the model @existing_comment = Comment.find_existing(@info_request.id, params[:comment][:body]) @@ -106,4 +100,12 @@ class CommentController < ApplicationController end end + # Banned from adding comments? + def reject_if_user_banned + if authenticated_user && !authenticated_user.can_make_comments? + @details = authenticated_user.can_fail_html + render :template => 'user/banned' + end + end + end |