Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow toggling on and off comment notifications by inidividual post

  • Loading branch information...
commit 87854c7bf46ddfc629f1dac24a4bf7ac370045d8 1 parent d4bcf36
@bborn bborn authored
View
1  CHANGELOG
@@ -2,6 +2,7 @@
=1.2.1
* Anonymous forum replies
+* Turn comment notifications on or off by post
=1.2.0
* Threaded private messages
View
1  app/models/comment.rb
@@ -104,6 +104,7 @@ def notify_previous_anonymous_commenters
end
def send_notifications
+ return if commentable.respond_to?(:send_comment_notifications?) && !commentable.send_comment_notifications?
UserNotifier.deliver_comment_notice(self) if should_notify_recipient?
self.notify_previous_commenters
self.notify_previous_anonymous_commenters if AppConfig.allow_anonymous_commenting
View
2  app/views/comments/_comment_form.html.haml
@@ -31,6 +31,8 @@
%label
=f.check_box :notify_by_email, :style => 'width: 10px;'
=:notify_me_of_follow_ups_via_email.l
+ -if commentable.respond_to?(:send_comment_notifications?) && !commentable.send_comment_notifications?
+ %em="(#{:comment_notifications_off.l})"
%label{"for"=>"comment[author_url"}
=:comment_web_site_label.l
View
6 app/views/posts/edit.html.haml
@@ -34,6 +34,12 @@
= auto_complete_field 'tag_list', {:url => { :controller => "tags", :action => 'auto_complete_for_tag_name'}, :tokens => [','] }
%label=:save_post_as.l
= f.select(:published_as, [[:published.l, 'live'], [:draft.l, 'draft']])
+
+ %label
+ = f.check_box :send_comment_notifications
+ =:send_comment_notifications.l
+
+
%p
= submit_tag :update.l
= :or.l
View
5 app/views/posts/new.html.haml
@@ -55,6 +55,11 @@
=:save_post_as.l
= f.select(:published_as, [[:published.l, 'live'], [:draft.l, 'draft']])
+ %label
+ = f.check_box :send_comment_notifications
+ =:send_comment_notifications.l
+
+
%p
= submit_tag :save.l
%p
View
9 db/migrate/076_add_comment_notification_toggle.rb
@@ -0,0 +1,9 @@
+class AddCommentNotificationToggle < ActiveRecord::Migration
+ def self.up
+ add_column :posts, :send_comment_notifications, :boolean, :default => true
+ end
+
+ def self.down
+ remove_column :posts, :send_comment_notifications
+ end
+end
View
4 lang/ui/en.yml
@@ -273,6 +273,8 @@ en:
comment_character_limit: (2000 character limit)
#en: comment_could_not_be_deleted: Comment could not be deleted.
comment_could_not_be_deleted: Comment could not be deleted.
+ #en: comment_notifications_off: Comment notifications are currently off
+ comment_notifications_off: Comment notifications are currently off
#en: comment_save_error: Your comment couldn't be saved.
comment_save_error: "Your comment couldn't be saved: {{error}}"
#en: comment_was_successfully_created: Comment was successfully created.
@@ -1183,6 +1185,8 @@ en:
select_your_city: Select your city
#en: send: "Send"
send: "Send"
+ #en: send_comment_notifications: Send comment notifications?
+ send_comment_notifications: Send comment notifications?
#en: send_me_a_message: "Send me a message"
send_me_a_message: "Send me a message"
#en: send_invitations: Send Invitations!
View
11 test/unit/comment_test.rb
@@ -85,6 +85,17 @@ def test_should_unsubscribe_notifications
assert comment.reload.notify_by_email.eql?(false)
assert first_comment.reload.notify_by_email.eql?(false)
end
+
+ def test_should_not_notify_of_comments_on_post_with_send_notifications_off
+ post = posts(:funny_post)
+ post.send_comment_notifications = false
+ post.save!
+
+ comment = Comment.create!(:comment => 'foo', :user => users(:aaron), :commentable => post)
+ assert_difference ActionMailer::Base.deliveries, :length, 0 do
+ comment.send_notifications
+ end
+ end
end
View
12 test/unit/post_test.rb
@@ -176,6 +176,18 @@ def test_should_show_published_at_display_for_draft
post.save_as_draft
assert_equal post.published_at_display, 'Draft'
end
+
+ def test_should_not_notify_for_posts_without_comment_notification_on
+ post = posts(:funny_post)
+ post.send_comment_notifications = false
+ post.save!
+
+ assert_difference ActionMailer::Base.deliveries, :length, 0 do
+ comment = Comment.create!(:comment => 'foo', :user => users(:aaron), :commentable => post)
+ comment.send_notifications
+ end
+
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.