FEATURE: limit daily emails per user to 100 per day via site setting

- controlled via max_emails_per_day_per_user, 0 to disable
- when limit is reached user is warned
This commit is contained in:
Sam
2016-03-23 15:08:34 +11:00
parent 389801f244
commit c095304d6d
11 changed files with 124 additions and 7 deletions

View File

@@ -243,6 +243,31 @@ describe UserNotifications do
end
end
it 'adds a warning when mail limit is reached' do
SiteSetting.max_emails_per_day_per_user = 2
user = Fabricate(:user)
user.email_logs.create(email_type: 'blah', to_address: user.email, user_id: user.id, skipped: false)
post = Fabricate(:post)
reply = Fabricate(:post, topic_id: post.topic_id)
notification = Fabricate(:notification, topic_id: post.topic_id, post_number: reply.post_number,
user: post.user, data: {original_username: 'bob'}.to_json)
mail = UserNotifications.user_replied(
user,
post: reply,
notification_type: notification.notification_type,
notification_data_hash: notification.data_hash
)
# WARNING: you reached the limit of 100 email notifications per day. Further emails will be suppressed.
# Consider watching less topics or disabling mailing list mode.
expect(mail.html_part.to_s).to match("WARNING: ")
expect(mail.body.to_s).to match("WARNING: ")
end
def expects_build_with(condition)
UserNotifications.any_instance.expects(:build_email).with(user.email, condition)
mailer = UserNotifications.send(mail_type, user,