diff --git a/src/mail_templates/app_update_available.ejs b/src/mail_templates/app_update_available.ejs index ad83aa6ab..32c5a7d26 100644 --- a/src/mail_templates/app_update_available.ejs +++ b/src/mail_templates/app_update_available.ejs @@ -2,13 +2,14 @@ Dear Cloudron Admin, -a new version <%= updateInfo.manifest.version %> of the app '<%= app.manifest.title %>' installed at <%= app.fqdn %> is available! - -The app will update automatically tonight. Alternately, update immediately at <%= webadminUrl %>. +A new version <%= updateInfo.manifest.version %> of the app '<%= app.manifest.title %>' installed at <%= app.fqdn %> is available! Changes: <%= updateInfo.manifest.changelog %> +<% if (!hasSubscription) { -%> +*Keep your Cloudron automatically up-to-date and secure by upgrading to a paid plan at* <%= webadminUrl %>/#/settings +<% } -%> Powered by https://cloudron.io @@ -16,4 +17,35 @@ Sent at: <%= new Date().toUTCString() %> <% } else { %> +
+ A new version <%= updateInfo.manifest.version %> of the app '<%= app.manifest.title %>' installed at <%= app.fqdn %> is available! +
+ +Keep your Cloudron automatically up-to-date and secure by upgrading to a paid plan.
+ <% } %> + +
- Your Cloudron will update automatically tonight.
- Alternately, update immediately here.
-
Keep your Cloudron automatically up-to-date and secure by upgrading to a paid plan.
+ <% } %> +Weekly summary of activities on your Cloudron <%= cloudronName %>:
- -This is a summary of the activities on your Cloudron <%= cloudronName %> last week.
<% if (info.usersAdded.length) { -%>The following users were added:
diff --git a/src/mailer.js b/src/mailer.js index c8d2b0f05..2881db4c7 100644 --- a/src/mailer.js +++ b/src/mailer.js @@ -245,7 +245,7 @@ function userAdded(user, inviteSent) { debug('Sending mail for userAdded %s including invite link', inviteSent ? 'not' : ''); getAdminEmails(function (error, adminEmails) { - if (error) return console.log('Error getting admins', error); + if (error) return debug('Error getting admins', error); adminEmails = _.difference(adminEmails, [ user.email ]); @@ -342,7 +342,7 @@ function appDied(app) { debug('Sending mail for app %s @ %s died', app.id, app.fqdn); getAdminEmails(function (error, adminEmails) { - if (error) return console.log('Error getting admins', error); + if (error) return debug('Error getting admins', error); var mailOptions = { from: mailConfig().from, @@ -355,12 +355,13 @@ function appDied(app) { }); } -function boxUpdateAvailable(newBoxVersion, changelog) { +function boxUpdateAvailable(hasSubscription, newBoxVersion, changelog) { + assert.strictEqual(typeof hasSubscription, 'boolean'); assert.strictEqual(typeof newBoxVersion, 'string'); assert(util.isArray(changelog)); getAdminEmails(function (error, adminEmails) { - if (error) return console.log('Error getting admins', error); + if (error) return debug('Error getting admins', error); settings.getCloudronName(function (error, cloudronName) { if (error) { @@ -374,6 +375,7 @@ function boxUpdateAvailable(newBoxVersion, changelog) { fqdn: config.fqdn(), webadminUrl: config.adminOrigin(), newBoxVersion: newBoxVersion, + hasSubscription: hasSubscription, changelog: changelog, changelogHTML: changelog.map(function (e) { return converter.makeHtml(e); }), cloudronName: cloudronName, @@ -399,21 +401,49 @@ function boxUpdateAvailable(newBoxVersion, changelog) { }); } -function appUpdateAvailable(app, updateInfo) { +function appUpdateAvailable(app, hasSubscription, info) { assert.strictEqual(typeof app, 'object'); - assert.strictEqual(typeof updateInfo, 'object'); + assert.strictEqual(typeof hasSubscription, 'boolean'); + assert.strictEqual(typeof info, 'object'); getAdminEmails(function (error, adminEmails) { - if (error) return console.log('Error getting admins', error); + if (error) return debug('Error getting admins', error); - var mailOptions = { - from: mailConfig().from, - to: adminEmails.join(', '), - subject: util.format('[%s] Update available for %s', config.fqdn(), app.fqdn), - text: render('app_update_available.ejs', { fqdn: config.fqdn(), webadminUrl: config.adminOrigin(), app: app, updateInfo: updateInfo, format: 'text' }) - }; + settings.getCloudronName(function (error, cloudronName) { + if (error) { + debug(error); + cloudronName = 'Cloudron'; + } - enqueue(mailOptions); + var converter = new showdown.Converter(); + + var templateData = { + fqdn: config.fqdn(), + webadminUrl: config.adminOrigin(), + hasSubscription: hasSubscription, + app: app, + updateInfo: info, + changelogHTML: converter.makeHtml(info.manifest.changelog), + cloudronName: cloudronName, + cloudronAvatarUrl: config.adminOrigin() + '/api/v1/cloudron/avatar' + }; + + var templateDataText = JSON.parse(JSON.stringify(templateData)); + templateDataText.format = 'text'; + + var templateDataHTML = JSON.parse(JSON.stringify(templateData)); + templateDataHTML.format = 'html'; + + var mailOptions = { + from: mailConfig().from, + to: adminEmails.join(', '), + subject: util.format('App %s has a new update available', app.fqdn), + text: render('app_update_available.ejs', templateDataText), + html: render('app_update_available.ejs', templateDataHTML) + }; + + enqueue(mailOptions); + }); }); } @@ -421,7 +451,7 @@ function sendDigest(info) { assert.strictEqual(typeof info, 'object'); getAdminEmails(function (error, adminEmails) { - if (error) return console.log('Error getting admins', error); + if (error) return debug('Error getting admins', error); settings.getCloudronName(function (error, cloudronName) { if (error) { @@ -460,7 +490,7 @@ function outOfDiskSpace(message) { assert.strictEqual(typeof message, 'string'); getAdminEmails(function (error, adminEmails) { - if (error) return console.log('Error getting admins', error); + if (error) return debug('Error getting admins', error); var mailOptions = { from: mailConfig().from, @@ -477,7 +507,7 @@ function backupFailed(error) { var message = splatchError(error); getAdminEmails(function (error, adminEmails) { - if (error) return console.log('Error getting admins', error); + if (error) return debug('Error getting admins', error); var mailOptions = { from: mailConfig().from, @@ -495,7 +525,7 @@ function certificateRenewalError(domain, message) { assert.strictEqual(typeof message, 'string'); getAdminEmails(function (error, adminEmails) { - if (error) return console.log('Error getting admins', error); + if (error) return debug('Error getting admins', error); var mailOptions = { from: mailConfig().from, @@ -513,7 +543,7 @@ function oomEvent(program, context) { assert.strictEqual(typeof context, 'string'); getAdminEmails(function (error, adminEmails) { - if (error) return console.log('Error getting admins', error); + if (error) return debug('Error getting admins', error); var mailOptions = { from: mailConfig().from, diff --git a/src/updatechecker.js b/src/updatechecker.js index 5924790b8..6a85cbb94 100644 --- a/src/updatechecker.js +++ b/src/updatechecker.js @@ -113,7 +113,7 @@ function checkAppUpdates(callback) { // always send notifications if user is on the free plan if (result.plan.id === 'free' || result.plan.id === 'undecided') { debug('Notifying user of app update for %s from %s to %s', app.id, app.manifest.version, updateInfo.manifest.version); - mailer.appUpdateAvailable(app, updateInfo); + mailer.appUpdateAvailable(app, false /* subscription */, updateInfo); return iteratorDone(); } @@ -123,7 +123,7 @@ function checkAppUpdates(callback) { debug(error); } else if (result === constants.AUTOUPDATE_PATTERN_NEVER) { debug('Notifying user of app update for %s from %s to %s', app.id, app.manifest.version, updateInfo.manifest.version); - mailer.appUpdateAvailable(app, updateInfo); + mailer.appUpdateAvailable(app, true /* hasSubscription */, updateInfo); } iteratorDone(); @@ -169,14 +169,14 @@ function checkBoxUpdates(callback) { // always send notifications if user is on the free plan if (result.plan.id === 'free' || result.plan.id === 'undecided') { - mailer.boxUpdateAvailable(updateInfo.version, updateInfo.changelog); + mailer.boxUpdateAvailable(false /* hasSubscription */, updateInfo.version, updateInfo.changelog); return done(); } // only send notifications if update pattern is 'never' settings.getAutoupdatePattern(function (error, result) { if (error) debug(error); - else if (result === constants.AUTOUPDATE_PATTERN_NEVER) mailer.boxUpdateAvailable(updateInfo.version, updateInfo.changelog); + else if (result === constants.AUTOUPDATE_PATTERN_NEVER) mailer.boxUpdateAvailable(true /* hasSubscription */, updateInfo.version, updateInfo.changelog); done(); });