Don’t allow comments on questions for unverified users and when the phase is closed

This commit is contained in:
Amaia Castro
2017-02-08 18:19:10 +01:00
parent 60c7947cb4
commit 3009706b0d
13 changed files with 155 additions and 18 deletions

View File

@@ -1,6 +1,10 @@
class CommentsController < ApplicationController
include CustomUrlsHelper
before_action :authenticate_user!, only: :create
before_action :load_commentable, only: :create
before_action :verify_resident_for_commentable!, only: :create
before_action :verify_comments_open!, only: [:create, :vote]
before_action :build_comment, only: :create
load_and_authorize_resource
@@ -75,6 +79,22 @@ class CommentsController < ApplicationController
notifiable = comment.commentable
end
Notification.add(notifiable.author_id, notifiable) unless comment.author_id == notifiable.author_id
end
end
end
def verify_resident_for_commentable!
return if current_user.administrator? || current_user.moderator?
if @commentable.respond_to?(:comments_for_verified_residents_only?) && @commentable.comments_for_verified_residents_only?
verify_resident!
end
end
def verify_comments_open!
return if current_user.administrator? || current_user.moderator?
if @commentable.respond_to?(:comments_closed?) && @commentable.comments_closed?
redirect_to @commentable, alert: t('comments.comments_closed')
end
end
end