Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bborn committed Aug 8, 2009
1 parent bfcd765 commit bdb607d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/controllers/comments_controller.rb
Expand Up @@ -129,8 +129,8 @@ def delete_selected

def unsubscribe
@comment = Comment.find(params[:comment_id])
if @comment.token.eql?(params[:token])
@comment.unsubscribe_notifications
if @comment.token_for(params[:email]).eql?(params[:token])
@comment.unsubscribe_notifications(params[:email])
flash[:notice] = :comment_unsubscribe_succeeded.l
end
redirect_to commentable_url(@comment)
Expand Down
9 changes: 4 additions & 5 deletions app/models/comment.rb
Expand Up @@ -106,13 +106,12 @@ def send_notifications
self.notify_previous_anonymous_commenters if AppConfig.allow_anonymous_commenting
end

def token
Digest::SHA1.hexdigest("#{id}--#{(user && user.email) || author_email}--#{created_at}")
def token_for(email)
Digest::SHA1.hexdigest("#{id}--#{email}--#{created_at}")
end

def unsubscribe_notifications
update_attribute :notify_by_email, false
commentable.comments.find_all_by_author_email(author_email).each do |previous_comment|
def unsubscribe_notifications(email)
commentable.comments.find_all_by_author_email(email).each do |previous_comment|
previous_comment.update_attribute :notify_by_email, false
end
end
Expand Down
5 changes: 2 additions & 3 deletions app/models/user_notifier.rb
Expand Up @@ -55,9 +55,8 @@ def follow_up_comment_notice_anonymous(email, comment)
@subject += "#{comment.username} has commented on a #{comment.commentable_type} that you also commented on."
@body[:url] = commentable_url(comment)
@body[:comment] = comment
if comment.notify_by_email
@body[:unsubscribe_link] = url_for(:controller => 'comments', :action => 'unsubscribe', :comment_id => comment.id, :token => comment.token)
end

@body[:unsubscribe_link] = url_for(:controller => 'comments', :action => 'unsubscribe', :comment_id => comment.id, :token => comment.token_for(email), :email => email)
end

def new_forum_post_notice(user, post)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/comments_controller_test.rb
Expand Up @@ -154,7 +154,7 @@ def test_should_unsubscribe_with_token
comment = Comment.create!(:comment => 'foo', :author_email => 'bar@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin), :commentable => users(:quentin), :notify_by_email => true)
AppConfig.allow_anonymous_commenting = false

post :unsubscribe, :comment_id => comment.id, :token => comment.token
post :unsubscribe, :comment_id => comment.id, :token => comment.token_for('bar@foo.com'), :email => 'bar@foo.com'
assert comment.reload.notify_by_email.eql?(false)
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit/comment_test.rb
Expand Up @@ -81,7 +81,7 @@ def test_should_unsubscribe_notifications
assert_equal comment.notify_by_email, true
AppConfig.allow_anonymous_commenting = false

comment.unsubscribe_notifications
comment.unsubscribe_notifications('alicia@foo.com')
assert comment.reload.notify_by_email.eql?(false)
assert first_comment.reload.notify_by_email.eql?(false)
end
Expand Down

0 comments on commit bdb607d

Please sign in to comment.