Disable digest emails site setting

This commit is contained in:
Arpit Jalan 2015-01-27 10:16:21 +05:30
parent fbd18f3b69
commit 12c82bed59
6 changed files with 39 additions and 14 deletions

View file

@ -42,6 +42,10 @@ export default ObjectController.extend(CanCheckEmails, {
return !Discourse.SiteSettings.enable_sso && Discourse.SiteSettings.enable_local_logins;
}.property(),
canReceiveDigest: function() {
return !this.siteSettings.disable_digest_emails
}.property(),
availableLocales: function() {
return Discourse.SiteSettings.available_locales.split('|').map( function(s) {
return {name: s, value: s};
@ -166,5 +170,3 @@ export default ObjectController.extend(CanCheckEmails, {
}
});

View file

@ -171,11 +171,13 @@
<div class="control-group pref-email-settings">
<label class="control-label">{{i18n 'user.email_settings'}}</label>
{{preference-checkbox labelKey="user.email_digests.title" checked=email_digests}}
{{#if email_digests}}
<div class='controls controls-dropdown'>
{{combo-box valueAttribute="value" content=digestFrequencies value=digest_after_days}}
</div>
{{#if canReceiveDigest}}
{{preference-checkbox labelKey="user.email_digests.title" checked=email_digests}}
{{#if email_digests}}
<div class='controls controls-dropdown'>
{{combo-box valueAttribute="value" content=digestFrequencies value=digest_after_days}}
</div>
{{/if}}
{{/if}}
{{preference-checkbox labelKey="user.email_private_messages" checked=email_private_messages}}
{{preference-checkbox labelKey="user.email_direct" checked=email_direct}}

View file

@ -5,8 +5,10 @@ module Jobs
every 6.hours
def execute(args)
target_user_ids.each do |user_id|
Jobs.enqueue(:user_email, type: :digest, user_id: user_id)
unless SiteSetting.disable_digest_emails?
target_user_ids.each do |user_id|
Jobs.enqueue(:user_email, type: :digest, user_id: user_id)
end
end
end

View file

@ -991,6 +991,7 @@ en:
digest_min_excerpt_length: "Minimum post excerpt in the email digest, in characters."
default_digest_email_frequency: "How often users receive digest emails by default. They can change this setting in their preferences."
suppress_digest_email_after_days: "Suppress digest emails for users not seen on the site for more than (n) days."
disable_digest_emails: "Disable digest emails for all users."
default_external_links_in_new_tab: "Open external links in a new tab. Users can change this in their preferences."
detect_custom_avatars: "Whether or not to check that users have uploaded custom avatars."

View file

@ -409,6 +409,9 @@ email:
default: 7
enum: 'DigestEmailSiteSetting'
suppress_digest_email_after_days: 365
disable_digest_emails:
default: false
client: true
email_custom_headers: 'Auto-Submitted: auto-generated'
email_subject: '[%{site_name}] %{optional_pm}%{optional_cat}%{topic_title}'
reply_by_email_enabled: false

View file

@ -89,13 +89,28 @@ describe Jobs::EnqueueDigestEmails do
let(:user) { Fabricate(:user) }
before do
Jobs::EnqueueDigestEmails.any_instance.expects(:target_user_ids).returns([user.id])
context "digest emails are enabled" do
before do
Jobs::EnqueueDigestEmails.any_instance.expects(:target_user_ids).returns([user.id])
end
it "enqueues the digest email job" do
SiteSetting.stubs(:disable_digest_emails?).returns(false)
Jobs.expects(:enqueue).with(:user_email, type: :digest, user_id: user.id)
Jobs::EnqueueDigestEmails.new.execute({})
end
end
it "enqueues the digest email job" do
Jobs.expects(:enqueue).with(:user_email, type: :digest, user_id: user.id)
Jobs::EnqueueDigestEmails.new.execute({})
context "digest emails are disabled" do
before do
Jobs::EnqueueDigestEmails.any_instance.expects(:target_user_ids).never
end
it "does not enqueue the digest email job" do
SiteSetting.stubs(:disable_digest_emails?).returns(true)
Jobs.expects(:enqueue).with(:user_email, type: :digest, user_id: user.id).never
Jobs::EnqueueDigestEmails.new.execute({})
end
end
end