From ce02440ba57029b7c1da98661b9ce326144671eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Georget?= Date: Mon, 28 Oct 2019 16:48:54 +0100 Subject: [PATCH 1/3] Update initialisation detection when starting a project --- examples/getstarted/groups/openingtimes.json | 3 +++ .../lib/resources/files/config/.init.json | 3 --- packages/strapi/lib/Strapi.js | 8 ++++---- packages/strapi/lib/utils/index.js | 15 ++++++++++++--- 4 files changed, 19 insertions(+), 10 deletions(-) delete mode 100644 packages/strapi-generate-new/lib/resources/files/config/.init.json diff --git a/examples/getstarted/groups/openingtimes.json b/examples/getstarted/groups/openingtimes.json index 8e93e3ea80..2c1dcbaf65 100755 --- a/examples/getstarted/groups/openingtimes.json +++ b/examples/getstarted/groups/openingtimes.json @@ -11,6 +11,9 @@ }, "time": { "type": "string" + }, + "addresses": { + "collection": "address" } } } \ No newline at end of file diff --git a/packages/strapi-generate-new/lib/resources/files/config/.init.json b/packages/strapi-generate-new/lib/resources/files/config/.init.json deleted file mode 100644 index 9697e15cde..0000000000 --- a/packages/strapi-generate-new/lib/resources/files/config/.init.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "init": true -} diff --git a/packages/strapi/lib/Strapi.js b/packages/strapi/lib/Strapi.js index fefd643a7f..f447d269c6 100644 --- a/packages/strapi/lib/Strapi.js +++ b/packages/strapi/lib/Strapi.js @@ -199,8 +199,8 @@ class Strapi extends EventEmitter { await this.runBootstrapFunctions(); // Freeze object. await this.freeze(); - // Init first start - utils.init(this.config); + // Is the project initialised? + const isInitialised = await utils.isInitialised(this); this.app.use(this.router.routes()).use(this.router.allowedMethods()); @@ -208,7 +208,7 @@ class Strapi extends EventEmitter { this.server.listen(this.config.port, async err => { if (err) return this.stopWithError(err); - if (this.config.init) { + if (!isInitialised) { this.logFirstStartupMessage(); } else { this.logStartupMessage(); @@ -228,7 +228,7 @@ class Strapi extends EventEmitter { 'server.admin.autoOpen', true ) !== false) || - this.config.init + !isInitialised ) { await utils.openBrowser.call(this); } diff --git a/packages/strapi/lib/utils/index.js b/packages/strapi/lib/utils/index.js index e5f029c254..e59645eb10 100644 --- a/packages/strapi/lib/utils/index.js +++ b/packages/strapi/lib/utils/index.js @@ -23,9 +23,18 @@ const exposer = require('./exposer'); const openBrowser = require('./openBrowser'); module.exports = { - init(config) { - if (config.init) { - fs.unlinkSync(path.resolve(config.appPath, 'config', '.init.json')); + /* + * Return false where there is no administrator, otherwise return true. + */ + async isInitialised(strapi) { + try { + const numberOfAdministrators = await strapi + .query('administrator', 'admin') + .find({ _limit: 1 }); + + return numberOfAdministrators.length > 0; + } catch (err) { + strapi.stopWithError(err); } }, From d0268ad3973cc0aa2f9728e983cde3d505fdfece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Georget?= Date: Mon, 28 Oct 2019 17:18:41 +0100 Subject: [PATCH 2/3] Add security to ensure the admin is available --- packages/strapi/lib/utils/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/strapi/lib/utils/index.js b/packages/strapi/lib/utils/index.js index e59645eb10..c7221e7817 100644 --- a/packages/strapi/lib/utils/index.js +++ b/packages/strapi/lib/utils/index.js @@ -12,6 +12,7 @@ const { get, difference, intersection, + isEmpty, isObject, isFunction, } = require('lodash'); @@ -28,6 +29,10 @@ module.exports = { */ async isInitialised(strapi) { try { + if (isEmpty(strapi.admin)) { + return true; + } + const numberOfAdministrators = await strapi .query('administrator', 'admin') .find({ _limit: 1 }); From 693df046d6615ad5b005015f28a7bedb895af16f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Georget?= Date: Mon, 28 Oct 2019 17:24:51 +0100 Subject: [PATCH 3/3] Remove addresses field in the OpeningTimes group --- examples/getstarted/groups/openingtimes.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/getstarted/groups/openingtimes.json b/examples/getstarted/groups/openingtimes.json index 2c1dcbaf65..8e93e3ea80 100755 --- a/examples/getstarted/groups/openingtimes.json +++ b/examples/getstarted/groups/openingtimes.json @@ -11,9 +11,6 @@ }, "time": { "type": "string" - }, - "addresses": { - "collection": "address" } } } \ No newline at end of file