diff --git a/scripts/cloudron-setup b/scripts/cloudron-setup index 4223a2ef6..3fd871541 100755 --- a/scripts/cloudron-setup +++ b/scripts/cloudron-setup @@ -214,9 +214,6 @@ if [[ -z "${dataJson}" ]]; then "format": "tgz", "retentionSecs": 172800 }, - "updateConfig": { - "prerelease": ${prerelease} - }, "version": "${version}" } EOF diff --git a/setup/argparser.sh b/setup/argparser.sh index 749026d90..1c412daf2 100644 --- a/setup/argparser.sh +++ b/setup/argparser.sh @@ -20,7 +20,6 @@ arg_version="" arg_web_server_origin="" arg_backup_config="" arg_dns_config="" -arg_update_config="" arg_provider="" arg_app_bundle="" arg_is_demo="false" @@ -86,9 +85,6 @@ while true; do arg_dns_config=$(echo "$2" | $json dnsConfig) [[ "${arg_dns_config}" == "null" ]] && arg_dns_config="" - arg_update_config=$(echo "$2" | $json updateConfig) - [[ "${arg_update_config}" == "null" ]] && arg_update_config="" - shift 2 ;; --) break;; diff --git a/setup/start.sh b/setup/start.sh index 6650a89fe..ed4e8da7e 100755 --- a/setup/start.sh +++ b/setup/start.sh @@ -303,11 +303,6 @@ if [[ ! -z "${arg_dns_config}" ]]; then -e "REPLACE INTO settings (name, value) VALUES (\"dns_config\", '$arg_dns_config')" box fi -if [[ ! -z "${arg_update_config}" ]]; then - mysql -u root -p${mysql_root_password} \ - -e "REPLACE INTO settings (name, value) VALUES (\"update_config\", '$arg_update_config')" box -fi - if [[ ! -z "${arg_tls_config}" ]]; then mysql -u root -p${mysql_root_password} \ -e "REPLACE INTO settings (name, value) VALUES (\"tls_config\", '$arg_tls_config')" box diff --git a/src/mailer.js b/src/mailer.js index da6fd232d..eb99e6dd7 100644 --- a/src/mailer.js +++ b/src/mailer.js @@ -385,7 +385,7 @@ function boxUpdateAvailable(newBoxVersion, changelog) { var templateDataHTML = JSON.parse(JSON.stringify(templateData)); templateDataHTML.format = 'html'; - var mailOptions = { + var mailOptions = { from: mailConfig().from, to: adminEmails.join(', '), subject: util.format('%s has a new update available', config.fqdn()), @@ -405,7 +405,7 @@ function appUpdateAvailable(app, updateInfo) { getAdminEmails(function (error, adminEmails) { if (error) return console.log('Error getting admins', error); - var mailOptions = { + var mailOptions = { from: mailConfig().from, to: adminEmails.join(', '), subject: util.format('[%s] Update available for %s', config.fqdn(), app.fqdn), @@ -561,8 +561,8 @@ function sendFeedback(user, type, subject, description) { type === exports.FEEDBACK_TYPE_UPGRADE_REQUEST || type === exports.FEEDBACK_TYPE_APP_ERROR); - var mailOptions = { - from: mailConfig().from, + var mailOptions = { + from: mailConfig().from, to: 'support@cloudron.io', subject: util.format('[%s] %s - %s', type, config.fqdn(), subject), text: render('feedback.ejs', { fqdn: config.fqdn(), type: type, user: user, subject: subject, description: description, format: 'text'}) diff --git a/src/settings.js b/src/settings.js index f35dd5ea7..e3f054bf9 100644 --- a/src/settings.js +++ b/src/settings.js @@ -33,9 +33,6 @@ exports = module.exports = { getTlsConfig: getTlsConfig, setTlsConfig: setTlsConfig, - getUpdateConfig: getUpdateConfig, - setUpdateConfig: setUpdateConfig, - getAppstoreConfig: getAppstoreConfig, setAppstoreConfig: setAppstoreConfig, @@ -429,30 +426,6 @@ function setBackupConfig(backupConfig, callback) { }); } -function getUpdateConfig(callback) { - assert.strictEqual(typeof callback, 'function'); - - settingsdb.get(exports.UPDATE_CONFIG_KEY, function (error, value) { - if (error && error.reason === DatabaseError.NOT_FOUND) return callback(null, gDefaults[exports.UPDATE_CONFIG_KEY]); - if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error)); - - callback(null, JSON.parse(value)); // { prerelease } - }); -} - -function setUpdateConfig(updateConfig, callback) { - assert.strictEqual(typeof updateConfig, 'object'); - assert.strictEqual(typeof callback, 'function'); - - settingsdb.set(exports.UPDATE_CONFIG_KEY, JSON.stringify(updateConfig), function (error) { - if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error)); - - exports.events.emit(exports.UPDATE_CONFIG_KEY, updateConfig); - - callback(null); - }); -} - function getMailConfig(callback) { assert.strictEqual(typeof callback, 'function'); diff --git a/src/test/settings-test.js b/src/test/settings-test.js index b911b7d87..28a3e1114 100644 --- a/src/test/settings-test.js +++ b/src/test/settings-test.js @@ -162,29 +162,6 @@ describe('Settings', function () { }); }); - it('can get default update config config', function (done) { - settings.getUpdateConfig(function (error, updateConfig) { - expect(error).to.be(null); - expect(updateConfig.prerelease).to.be(false); - done(); - }); - }); - - it('can set update config', function (done) { - settings.setUpdateConfig({ prerelease: true }, function (error) { - expect(error).to.be(null); - done(); - }); - }); - - it('can get update config', function (done) { - settings.getUpdateConfig(function (error, updateConfig) { - expect(error).to.be(null); - expect(updateConfig.prerelease).to.be(true); - done(); - }); - }); - it('can set mail config', function (done) { settings.setMailConfig({ enabled: true }, function (error) { expect(error).to.be(null); diff --git a/src/test/updatechecker-test.js b/src/test/updatechecker-test.js index d9297b2f0..5c5ff2814 100644 --- a/src/test/updatechecker-test.js +++ b/src/test/updatechecker-test.js @@ -66,7 +66,8 @@ describe('updatechecker - box - manual (email)', function () { user.createOwner.bind(null, USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE), settings.setAutoupdatePattern.bind(null, constants.AUTOUPDATE_PATTERN_NEVER), settingsdb.set.bind(null, settings.APPSTORE_CONFIG_KEY, JSON.stringify({ userId: 'uid', cloudronId: 'cid', token: 'token' })), - mailer._clearMailQueue + mailer._clearMailQueue, + mailer.start ], done); }); @@ -113,7 +114,7 @@ describe('updatechecker - box - manual (email)', function () { }); }); - it('does not offer prerelease', function (done) { + it('offers prerelease', function (done) { nock.cleanAll(); var scope = nock('http://localhost:4444') @@ -121,39 +122,18 @@ describe('updatechecker - box - manual (email)', function () { .query({ boxVersion: config.version(), accessToken: 'token' }) .reply(200, { version: '2.0.0-pre.0', changelog: [''], sourceTarballUrl: '2.0.0-pre.0.tar.gz' } ); + var scope2 = nock('http://localhost:4444') + .get('/api/v1/users/uid/cloudrons/cid/subscription') + .query({ accessToken: 'token' }) + .reply(200, { subscription: { plan: { id: 'pro' } } } ); + updatechecker.checkBoxUpdates(function (error) { expect(!error).to.be.ok(); - expect(updatechecker.getUpdateInfo().box).to.be(null); + expect(updatechecker.getUpdateInfo().box.version).to.be('2.0.0-pre.0'); expect(scope.isDone()).to.be.ok(); + expect(scope2.isDone()).to.be.ok(); - checkMails(0, done); - }); - }); - - it('offers prerelease', function (done) { - nock.cleanAll(); - - settings.setUpdateConfig({ prerelease: true }, function (error) { - if (error) return done(error); - - var scope = nock('http://localhost:4444') - .get('/api/v1/users/uid/cloudrons/cid/boxupdate') - .query({ boxVersion: config.version(), accessToken: 'token' }) - .reply(200, { version: '2.0.0-pre.0', changelog: [''], sourceTarballUrl: '2.0.0-pre.0.tar.gz' } ); - - var scope2 = nock('http://localhost:4444') - .get('/api/v1/users/uid/cloudrons/cid/subscription') - .query({ accessToken: 'token' }) - .reply(200, { subscription: { plan: { id: 'pro' } } } ); - - updatechecker.checkBoxUpdates(function (error) { - expect(!error).to.be.ok(); - expect(updatechecker.getUpdateInfo().box.version).to.be('2.0.0-pre.0'); - expect(scope.isDone()).to.be.ok(); - expect(scope2.isDone()).to.be.ok(); - - checkMails(1, done); - }); + checkMails(1, done); }); }); @@ -184,6 +164,7 @@ describe('updatechecker - box - automatic (no email)', function () { database.initialize, settings.initialize, mailer._clearMailQueue, + mailer.start, user.createOwner.bind(null, USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE), settingsdb.set.bind(null, settings.APPSTORE_CONFIG_KEY, JSON.stringify({ userId: 'uid', cloudronId: 'cid', token: 'token' })) ], done); diff --git a/src/updatechecker.js b/src/updatechecker.js index 1f5ba30a0..5924790b8 100644 --- a/src/updatechecker.js +++ b/src/updatechecker.js @@ -19,7 +19,6 @@ var apps = require('./apps.js'), mailer = require('./mailer.js'), paths = require('./paths.js'), safe = require('safetydance'), - semver = require('semver'), settings = require('./settings.js'); var gAppUpdateInfo = { }, // id -> update info { creationDate, manifest } @@ -149,48 +148,37 @@ function checkBoxUpdates(callback) { appstore.getBoxUpdate(function (error, updateInfo) { if (error || !updateInfo) return callback(error); - settings.getUpdateConfig(function (error, updateConfig) { + gBoxUpdateInfo = updateInfo; + + // decide whether to send email + var state = loadState(); + + if (state.box === gBoxUpdateInfo.version) { + debug('Skipping notification of box update as user was already notified'); + return callback(); + } + + appstore.getSubscription(function (error, result) { if (error) return callback(error); - var isPrerelease = semver.parse(updateInfo.version).prerelease.length !== 0; - - if (isPrerelease && !updateConfig.prerelease) { - debug('Skipping update %s since this box does not want prereleases', updateInfo.version); - return callback(); + function done() { + state.box = updateInfo.version; + saveState(state); + callback(); } - gBoxUpdateInfo = updateInfo; - - // decide whether to send email - var state = loadState(); - - if (state.box === gBoxUpdateInfo.version) { - debug('Skipping notification of box update as user was already notified'); - return 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); + return done(); } - appstore.getSubscription(function (error, result) { - if (error) return callback(error); + // 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); - function done() { - state.box = updateInfo.version; - saveState(state); - 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); - 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); - - done(); - }); + done(); }); }); });