module Commentable
  def verify_comment_permissions
    unless member?
      flash[:notice] = t(:'comments.not_a_member')
      redirect_to root_without_cache_path
    end
  end

  def commenting_allowed?
    member?
  end

  def add_comment_to(object, opts = {})
    return unless commenting_allowed?

    @comment = Comment.new(params[:comment])
    @comment.user             = current_user
    @comment.ip               = request.remote_ip
    @comment.country_name_id  = visitor_country_name_id
    @comment.approved         = false
    @comment.commentable      = object

    success = @comment.save
    flash[:notice] = t(:'comments.successfully_created') if success

    success
  end
end