mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FIX: don't send notification emails to deactivated user
This commit is contained in:
parent
14a15491a4
commit
4e5228dc9e
2 changed files with 44 additions and 2 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue