diff --git a/src/cloudron.js b/src/cloudron.js index 804211faf..67a6aa14f 100644 --- a/src/cloudron.js +++ b/src/cloudron.js @@ -93,9 +93,9 @@ function onActivated(callback) { // Starting the platform after a user is available means: // 1. mail bounces can now be sent to the cloudron owner // 2. the restore code path can run without sudo (since mail/ is non-root) - users.count(function (error, count) { + users.isActivated(function (error, activated) { if (error) return callback(new CloudronError(CloudronError.INTERNAL_ERROR, error)); - if (!count) return callback(); // not activated + if (!activated) return callback(); // not activated async.series([ platform.start, diff --git a/src/mail.js b/src/mail.js index 4f9ee57ce..e82c4eb5f 100644 --- a/src/mail.js +++ b/src/mail.js @@ -601,9 +601,9 @@ function restartMail(callback) { function restartMailIfActivated(callback) { assert.strictEqual(typeof callback, 'function'); - users.count(function (error, count) { + users.isActivated(function (error, activated) { if (error) return callback(new MailError(MailError.INTERNAL_ERROR, error)); - if (!count) { + if (!activated) { debug('restartMailIfActivated: skipping restart of mail container since Cloudron is not activated yet'); return callback(); // not provisioned yet, do not restart container after dns setup } diff --git a/src/setup.js b/src/setup.js index 33414464f..ede540485 100644 --- a/src/setup.js +++ b/src/setup.js @@ -280,9 +280,9 @@ function restore(backupConfig, backupId, version, autoconf, auditSource, callbac if (gWebadminStatus.configuring || gWebadminStatus.restore.active) return callback(new SetupError(SetupError.BAD_STATE, 'Already restoring or configuring')); - users.count(function (error, count) { + users.isActivated(function (error, activated) { if (error) return callback(new SetupError(SetupError.INTERNAL_ERROR, error)); - if (count) return callback(new SetupError(SetupError.ALREADY_PROVISIONED, 'Already activated')); + if (activated) return callback(new SetupError(SetupError.ALREADY_PROVISIONED, 'Already activated')); backups.testConfig(backupConfig, function (error) { if (error && error.reason === BackupsError.BAD_FIELD) return callback(new SetupError(SetupError.BAD_FIELD, error.message)); @@ -317,7 +317,7 @@ function restore(backupConfig, backupId, version, autoconf, auditSource, callbac function getStatus(callback) { assert.strictEqual(typeof callback, 'function'); - users.count(function (error, count) { + users.isActivated(function (error, activated) { if (error) return callback(new SetupError(SetupError.INTERNAL_ERROR, error)); settings.getCloudronName(function (error, cloudronName) { @@ -329,7 +329,7 @@ function getStatus(callback) { provider: config.provider(), cloudronName: cloudronName, adminFqdn: config.adminDomain() ? config.adminFqdn() : null, - activated: count !== 0, + activated: activated, edition: config.edition(), webadminStatus: gWebadminStatus // only valid when !activated }); diff --git a/src/test/users-test.js b/src/test/users-test.js index ede31b78f..888a2d57e 100644 --- a/src/test/users-test.js +++ b/src/test/users-test.js @@ -731,14 +731,25 @@ describe('User', function () { }); }); - describe('count', function () { - before(createOwner); + describe('activated', function () { after(cleanupUsers); - it('succeeds', function (done) { - users.count(function (error, count) { + it('succeeds with no users', function (done) { + users.isActivated(function (error, activated) { expect(error).to.not.be.ok(); - expect(count).to.be(1); + expect(activated).to.be(false); + done(); + }); + }); + + it('create users', function (done) { + createOwner(done); + }); + + it('succeeds with users', function (done) { + users.isActivated(function (error, activated) { + expect(error).to.not.be.ok(); + expect(activated).to.be(true); done(); }); }); diff --git a/src/users.js b/src/users.js index 90b846d1b..4e6a4ad55 100644 --- a/src/users.js +++ b/src/users.js @@ -8,7 +8,7 @@ exports = module.exports = { list: list, create: create, - count: count, + isActivated: isActivated, verify: verify, verifyWithUsername: verifyWithUsername, verifyWithEmail: verifyWithEmail, @@ -323,6 +323,16 @@ function count(callback) { }); } +function isActivated(callback) { + assert.strictEqual(typeof callback, 'function'); + + count(function (error, count) { + if (error) return callback(error); + + callback(null, count !== 0); + }); +} + function get(userId, callback) { assert.strictEqual(typeof userId, 'string'); assert.strictEqual(typeof callback, 'function');