From bad2d9fee69d536dab5d1bcd9e9ea96e8dec861f Mon Sep 17 00:00:00 2001 From: Caio SBA Date: Wed, 26 Oct 2011 01:35:48 -0300 Subject: [PATCH] Captcha for comment reply and title is not mandatory for comment anymore --- app/controllers/public/content_viewer_controller.rb | 2 +- app/models/comment.rb | 2 +- app/views/content_viewer/_comment_form.rhtml | 49 +++++++++++++++++++++++++++++++++++++++++++++---- public/javascripts/application.js | 1 - public/stylesheets/application.css | 25 ------------------------- test/unit/comment_test.rb | 5 ++--- 6 files changed, 49 insertions(+), 35 deletions(-) diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index 6494c30..226c0d6 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -119,7 +119,7 @@ class ContentViewerController < ApplicationController def add_comment @comment.author = user if logged_in? @comment.article = @page - if (logged_in? || @comment.reply_of_id || verify_recaptcha(:model => @comment, :message => _('Please type the words correctly'))) && @comment.save + if (logged_in? || verify_recaptcha(:model => @comment, :message => _('Please type the words correctly'))) && @comment.save @page.touch @comment = nil # clear the comment form redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] diff --git a/app/models/comment.rb b/app/models/comment.rb index 89b44f6..9fb59e7 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -2,7 +2,7 @@ class Comment < ActiveRecord::Base track_actions :leave_comment, :after_create, :keep_params => ["article.title", "article.url", "title", "url", "body"], :custom_target => :action_tracker_target - validates_presence_of :title, :body + validates_presence_of :body belongs_to :article, :counter_cache => true belongs_to :author, :class_name => 'Person', :foreign_key => 'author_id' has_many :children, :class_name => 'Comment', :foreign_key => 'reply_of_id', :dependent => :destroy diff --git a/app/views/content_viewer/_comment_form.rhtml b/app/views/content_viewer/_comment_form.rhtml index ae73269..e6a842d 100644 --- a/app/views/content_viewer/_comment_form.rhtml +++ b/app/views/content_viewer/_comment_form.rhtml @@ -1,3 +1,26 @@ + + <% focus_on = logged_in? ? 'title' : 'name' %> <% if @comment && @comment.errors.any? && @comment.reply_of_id.blank? %> @@ -19,6 +42,23 @@ <%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %> +<% unless logged_in? %> + + + +<% end %> + <% form_tag( url_for(@page.view_url.merge({:only_path => true})), { :class => 'comment_form' } ) do %> <%= hidden_field_tag(:confirm, 'false') %> @@ -32,15 +72,16 @@ <%= _('If you are a registered user, you can login and be automatically recognized.') %>

+ <%= hidden_field_tag(:recaptcha_response_field, nil, :id => nil) %> + <%= hidden_field_tag(:recaptcha_challenge_field, nil, :id => nil) %> + <% end %> - <%= required labelled_form_field(_('Title'), text_field(:comment, :title)) %> + <%= labelled_form_field(_('Title'), text_field(:comment, :title)) %> <%= required labelled_form_field(_('Enter your comment'), text_area(:comment, :body, :rows => 5)) %> - <%= recaptcha_tags(:display => { :theme => 'clean' }, :ajax => true) unless logged_in? %> - <% button_bar do %> - <%= submit_button('add', _('Post comment'), :onclick => "this.form.confirm.value = 'true'; this.disabled = true; this.form.submit(); return true;") %> + <%= submit_button('add', _('Post comment'), :onclick => "submit_comment_form(this); return false") %> <%= button_to_function :cancel, _('Cancel'), "f=jQuery(this).parents('.post_comment_box'); f.removeClass('opened'); f.addClass('closed'); return false" %> <% end %> <% end %> diff --git a/public/javascripts/application.js b/public/javascripts/application.js index a134af2..c368626 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -662,7 +662,6 @@ function add_comment_reply_form(button, comment_id) { var f = container.find('.comment_form'); if (f.length == 0) { f = jQuery('#page-comment-form .comment_form').clone(); - f.find('#dynamic_recaptcha').remove(); f.find('.fieldWithErrors').map(function() { jQuery(this).replaceWith(jQuery(this).contents()); }); f.prepend(''); container.append(f); diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index a1957e3..e3f8df9 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -6173,31 +6173,6 @@ h1#agenda-title { /* Captcha */ -.comment_reply #recaptcha_area { - margin-bottom: 3px !important; -} - -.comment_reply .recaptchatable tr td + td + td { - display: none !important; -} - -.comment_reply .recaptcha-container { - width: 100%; - overflow: hidden; -} - -.comment_reply .recaptcha-container:hover { - overflow: visible; -} - -.comment_reply .recaptcha-container tr:hover td { - background: transparent; -} - -.comment_reply .recaptcha_image_cell { - background: transparent !important; -} - /* Colorbox */ #cboxClose { diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 526f250..884353f 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -5,8 +5,8 @@ class CommentTest < Test::Unit::TestCase def setup end - should 'have a name and require it' do - assert_mandatory(Comment.new, :title) + should 'have a name but not require it' do + assert_optional(Comment.new, :title) end should 'have a body and require it' do @@ -197,7 +197,6 @@ class CommentTest < Test::Unit::TestCase comment.valid? assert comment.errors.invalid?(:name) - assert comment.errors.invalid?(:title) assert comment.errors.invalid?(:body) end -- libgit2 0.21.2