Send email to contact_email when a new version of Discourse is found. Disable with the new_version_emails setting.

This commit is contained in:
Neil Lalonde 2013-08-16 17:28:36 -04:00
parent 7dd470ccc0
commit baff59d752
5 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,14 @@
require_dependency 'email/message_builder'
class VersionMailer < ActionMailer::Base
include Email::BuildEmailHelper
def send_notice
if SiteSetting.contact_email.present?
build_email( SiteSetting.contact_email,
template: 'new_version_mailer',
new_version: DiscourseUpdates.latest_version,
installed_version: Discourse::VERSION::STRING )
end
end
end

View File

@ -45,6 +45,7 @@ class SiteSetting < ActiveRecord::Base
client_setting(:email_domains_blacklist, 'mailinator.com')
client_setting(:email_domains_whitelist)
client_setting(:version_checks, true)
setting(:new_version_emails, true)
client_setting(:min_title_similar_length, 10)
client_setting(:min_body_similar_length, 15)
# cf. https://github.com/discourse/discourse/pull/462#issuecomment-14991562

View File

@ -529,6 +529,7 @@ en:
email_domains_blacklist: "A pipe-delimited list of email domains that are not allowed. Example: mailinator.com|trashmail.net"
email_domains_whitelist: "A pipe-delimited list of email domains that users may register with. WARNING: Users with email domains other than those listed will not be allowed."
version_checks: "Ping the Discourse Hub for version updates and show version messages on the /admin dashboard"
new_version_emails: "Send an email to the contact_email address when a new version is available."
port: "DEVELOPER ONLY! WARNING! Use this HTTP port rather than the default of port 80. Leave blank for default of 80."
force_hostname: "DEVELOPER ONLY! WARNING! Specify a hostname in the URL. Leave blank for default."
@ -794,6 +795,17 @@ en:
<small>There should be an unsubscribe footer on every email you send, so let's mock one up. This email was sent by Name of Company, 55 Main Street, Anytown, USA 12345. If you would like to opt out of future emails, [click here to unsubscribe][5].</small>
new_version_mailer:
subject_template: "[%{site_name}] Updates Are Available"
text_body_template: |
A new version of Discourse is available.
**New version: %{new_version}**
Your version: %{installed_version}
Please upgrade as soon as possible to get the latest fixes and new features.
system_messages:
post_hidden:
subject_template: "Post hidden due to community flagging"

View File

@ -8,11 +8,18 @@ module Jobs
def execute(args)
if SiteSetting.version_checks? and (DiscourseUpdates.updated_at.nil? or DiscourseUpdates.updated_at < 1.minute.ago)
begin
should_send_email = (SiteSetting.new_version_emails and DiscourseUpdates.missing_versions_count and DiscourseUpdates.missing_versions_count == 0)
json = DiscourseHub.discourse_version_check
DiscourseUpdates.latest_version = json['latestVersion']
DiscourseUpdates.critical_updates_available = json['criticalUpdates']
DiscourseUpdates.missing_versions_count = json['missingVersionsCount']
DiscourseUpdates.updated_at = Time.zone.now
if should_send_email and json['missingVersionsCount'] > 0
message = VersionMailer.send_notice
Email::Sender.new(message, :new_version).send
end
rescue => e
raise e unless Rails.env == 'development' # Fail version check silently in development mode
end

View File

@ -0,0 +1,18 @@
require "spec_helper"
describe VersionMailer do
subject { VersionMailer.send_notice }
context 'contact_email is blank' do
before { SiteSetting.stubs(:contact_email).returns('') }
its(:to) { should be_blank }
end
context 'contact_email is set' do
before { SiteSetting.stubs(:contact_email).returns('me@example.com') }
its(:to) { should == ['me@example.com'] }
its(:subject) { should be_present }
its(:from) { should == [SiteSetting.notification_email] }
its(:body) { should be_present }
end
end