FIX: don't send notification emails to deactivated user

This commit is contained in:
Arpit Jalan 2015-08-31 11:24:37 +05:30
parent 14a15491a4
commit 4e5228dc9e
2 changed files with 44 additions and 2 deletions

View File

@ -39,7 +39,7 @@ class UserEmailObserver < ActiveRecord::Observer
private
def enqueue(type)
return unless notification.user.email_direct?
return unless (notification.user.email_direct? && notification.user.active?)
Jobs.enqueue_in(delay,
:user_email,
@ -49,7 +49,7 @@ class UserEmailObserver < ActiveRecord::Observer
end
def enqueue_private(type)
return unless notification.user.email_private_messages?
return unless (notification.user.email_private_messages? && notification.user.active?)
Jobs.enqueue_in(delay,
:user_email,

View File

@ -24,6 +24,12 @@ describe UserEmailObserver do
UserEmailObserver.send(:new).after_commit(notification)
end
it "doesn't enqueue an email if the user account is deactivated" do
user.active = false
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_mentioned)).never
UserEmailObserver.send(:new).after_commit(notification)
end
end
context 'posted' do
@ -42,6 +48,12 @@ describe UserEmailObserver do
UserEmailObserver.send(:new).after_commit(notification)
end
it "doesn't enqueue an email if the user account is deactivated" do
user.active = false
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_posted)).never
UserEmailObserver.send(:new).after_commit(notification)
end
end
context 'user_replied' do
@ -60,6 +72,12 @@ describe UserEmailObserver do
UserEmailObserver.send(:new).after_commit(notification)
end
it "doesn't enqueue an email if the user account is deactivated" do
user.active = false
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_replied)).never
UserEmailObserver.send(:new).after_commit(notification)
end
end
context 'user_quoted' do
@ -78,6 +96,12 @@ describe UserEmailObserver do
UserEmailObserver.send(:new).after_commit(notification)
end
it "doesn't enqueue an email if the user account is deactivated" do
user.active = false
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_quoted)).never
UserEmailObserver.send(:new).after_commit(notification)
end
end
context 'email_user_invited_to_private_message' do
@ -96,6 +120,12 @@ describe UserEmailObserver do
UserEmailObserver.send(:new).after_commit(notification)
end
it "doesn't enqueue an email if the user account is deactivated" do
user.active = false
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_invited_to_private_message)).never
UserEmailObserver.send(:new).after_commit(notification)
end
end
context 'private_message' do
@ -114,6 +144,12 @@ describe UserEmailObserver do
UserEmailObserver.send(:new).after_commit(notification)
end
it "doesn't enqueue an email if the user account is deactivated" do
user.active = false
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_private_message)).never
UserEmailObserver.send(:new).after_commit(notification)
end
end
context 'user_invited_to_topic' do
@ -132,6 +168,12 @@ describe UserEmailObserver do
UserEmailObserver.send(:new).after_commit(notification)
end
it "doesn't enqueue an email if the user account is deactivated" do
user.active = false
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_invited_to_topic)).never
UserEmailObserver.send(:new).after_commit(notification)
end
end
end