mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user