From 4fc93781dca9b3516488d1d569e48c98c05273ca Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 5 May 2021 17:58:09 +0100 Subject: [PATCH 01/10] basic UI for creating first admin user --- packages/builder/src/pages/admin/index.svelte | 77 +++++++++++++++++++ .../builder/src/pages/builder/_layout.svelte | 7 +- .../builder/src/pages/portal/_layout.svelte | 15 ++-- packages/server/src/api/index.js | 2 - 4 files changed, 89 insertions(+), 12 deletions(-) create mode 100644 packages/builder/src/pages/admin/index.svelte diff --git a/packages/builder/src/pages/admin/index.svelte b/packages/builder/src/pages/admin/index.svelte new file mode 100644 index 0000000000..1205f7b9d2 --- /dev/null +++ b/packages/builder/src/pages/admin/index.svelte @@ -0,0 +1,77 @@ + + +
+
+
+ Create an admin user + The admin user has access to everything in budibase. +
+
+ + + + + +
+
+
+ + diff --git a/packages/builder/src/pages/builder/_layout.svelte b/packages/builder/src/pages/builder/_layout.svelte index de657a63ac..59ebc28a8b 100644 --- a/packages/builder/src/pages/builder/_layout.svelte +++ b/packages/builder/src/pages/builder/_layout.svelte @@ -23,7 +23,6 @@
- +
-
+
Get Started Checklist
{#each Object.keys($admin.checklist) as checklistItem, idx} -
+
{idx + 1}. {MESSAGES[checklistItem]}
@@ -46,15 +46,9 @@ From 7d09bd8d70aa0562a0284a572474bd45c359cacb Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 6 May 2021 10:54:01 +0100 Subject: [PATCH 08/10] unit tests --- .../src/api/routes/tests/configs.spec.js | 38 +++++++++++++++++++ .../tests/utilities/TestConfiguration.js | 27 +++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 packages/worker/src/api/routes/tests/configs.spec.js diff --git a/packages/worker/src/api/routes/tests/configs.spec.js b/packages/worker/src/api/routes/tests/configs.spec.js new file mode 100644 index 0000000000..0b01c5b261 --- /dev/null +++ b/packages/worker/src/api/routes/tests/configs.spec.js @@ -0,0 +1,38 @@ +const setup = require("./utilities") + +// mock the email system +const sendMailMock = jest.fn() +jest.mock("nodemailer") +const nodemailer = require("nodemailer") +nodemailer.createTransport.mockReturnValue({ + verify: jest.fn() +}) + +describe("/api/admin/configs/checklist", () => { + let request = setup.getRequest() + let config = setup.getConfig() + + beforeAll(async () => { + await config.init() + }) + + afterAll(setup.afterAll) + + it("should return the correct checklist status based on the state of the budibase installation", async () => { + // initially configure settings + await config.saveAdminUser() + await config.saveSmtpConfig() + + const res = await request + .get(`/api/admin/configs/checklist`) + .set(config.defaultHeaders()) + .expect("Content-Type", /json/) + .expect(200) + + const checklist = res.body + + expect(checklist.apps).toBe(0) + expect(checklist.smtp).toBe(true) + expect(checklist.adminUser).toBe(true) + }) +}) \ No newline at end of file diff --git a/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js b/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js index 0f97b50c82..a262f6a2e2 100644 --- a/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js +++ b/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js @@ -105,6 +105,22 @@ class TestConfiguration { ) } + async saveOAuthConfig() { + await this.deleteConfig(Configs.GOOGLE) + await this._req( + { + type: Configs.GOOGLE, + config: { + callbackURL: "http://somecallbackurl", + clientID: "clientId", + clientSecret: "clientSecret", + }, + }, + null, + controllers.config.save + ) + } + async saveSmtpConfig() { await this.deleteConfig(Configs.SMTP) await this._req( @@ -141,6 +157,17 @@ class TestConfiguration { controllers.config.save ) } + + async saveAdminUser() { + await this._req( + { + email: "testuser@test.com", + password: "test@test.com" + }, + null, + controllers.users.adminUser + ) + } } module.exports = TestConfiguration From 42e0b3c1f90181fc36146c52c9373250bc58af88 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 6 May 2021 10:57:24 +0100 Subject: [PATCH 09/10] lint :sparkles: --- packages/builder/src/pages/admin/index.svelte | 3 ++- packages/builder/src/pages/builder/_layout.svelte | 6 ++++-- packages/builder/src/stores/portal/admin.js | 9 ++++++--- packages/worker/src/api/controllers/admin/configs.js | 9 +++++---- packages/worker/src/api/controllers/admin/users.js | 2 -- .../src/api/routes/tests/utilities/TestConfiguration.js | 2 +- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/builder/src/pages/admin/index.svelte b/packages/builder/src/pages/admin/index.svelte index f0d708602c..3f7793da2a 100644 --- a/packages/builder/src/pages/admin/index.svelte +++ b/packages/builder/src/pages/admin/index.svelte @@ -41,7 +41,8 @@ + bind:value={adminUser.password} + />
diff --git a/packages/builder/src/pages/builder/_layout.svelte b/packages/builder/src/pages/builder/_layout.svelte index 59ebc28a8b..77f8b655f5 100644 --- a/packages/builder/src/pages/builder/_layout.svelte +++ b/packages/builder/src/pages/builder/_layout.svelte @@ -32,13 +32,15 @@ + icon="PeopleGroup" + > Community + icon="Bug" + > Raise an issue diff --git a/packages/builder/src/stores/portal/admin.js b/packages/builder/src/stores/portal/admin.js index 570d925a76..33eb23a64d 100644 --- a/packages/builder/src/stores/portal/admin.js +++ b/packages/builder/src/stores/portal/admin.js @@ -11,15 +11,18 @@ export function createAdminStore() { const onboardingSteps = Object.keys(json) - const stepsComplete = onboardingSteps.reduce((score, step) => score + Number(!!json[step]), 0) + const stepsComplete = onboardingSteps.reduce( + (score, step) => score + Number(!!json[step]), + 0 + ) set({ checklist: json, - onboardingProgress: stepsComplete / onboardingSteps.length * 100 + onboardingProgress: (stepsComplete / onboardingSteps.length) * 100, }) } catch (err) { set({ - checklist: null + checklist: null, }) } } diff --git a/packages/worker/src/api/controllers/admin/configs.js b/packages/worker/src/api/controllers/admin/configs.js index b7cf731be4..ef54898326 100644 --- a/packages/worker/src/api/controllers/admin/configs.js +++ b/packages/worker/src/api/controllers/admin/configs.js @@ -104,13 +104,14 @@ exports.destroy = async function (ctx) { } } -exports.configChecklist = async function(ctx) { +exports.configChecklist = async function (ctx) { const db = new CouchDB(GLOBAL_DB) try { // TODO: Watch get started video // Apps exist + let allDbs if (env.COUCH_DB_URL) { allDbs = await (await fetch(`${env.COUCH_DB_URL}/_all_dbs`)).json() } else { @@ -120,7 +121,7 @@ exports.configChecklist = async function(ctx) { // They have set up SMTP const smtpConfig = await determineScopedConfig(db, { - type: Configs.SMTP + type: Configs.SMTP, }) // They have set up an admin user @@ -131,10 +132,10 @@ exports.configChecklist = async function(ctx) { ) const adminUser = users.rows.some(row => row.doc.admin) - ctx.body = { + ctx.body = { apps: appDbNames.length, smtp: !!smtpConfig, - adminUser + adminUser, } } catch (err) { ctx.throw(err.status, err) diff --git a/packages/worker/src/api/controllers/admin/users.js b/packages/worker/src/api/controllers/admin/users.js index 94c7463690..452c3be846 100644 --- a/packages/worker/src/api/controllers/admin/users.js +++ b/packages/worker/src/api/controllers/admin/users.js @@ -7,8 +7,6 @@ const { const { hash, getGlobalUserByEmail } = require("@budibase/auth").utils const { UserStatus } = require("../../../constants") -const FIRST_USER_EMAIL = "test@test.com" -const FIRST_USER_PASSWORD = "test" const GLOBAL_DB = StaticDatabases.GLOBAL.name exports.save = async ctx => { diff --git a/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js b/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js index a262f6a2e2..e0e2f966ff 100644 --- a/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js +++ b/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js @@ -162,7 +162,7 @@ class TestConfiguration { await this._req( { email: "testuser@test.com", - password: "test@test.com" + password: "test@test.com", }, null, controllers.users.adminUser From 6b9a2230948ae06e8c13a6c743bda9b7eff5b80b Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 6 May 2021 12:09:35 +0100 Subject: [PATCH 10/10] update scoped config imports --- packages/worker/src/api/controllers/admin/configs.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/worker/src/api/controllers/admin/configs.js b/packages/worker/src/api/controllers/admin/configs.js index 4944037676..a8847e8075 100644 --- a/packages/worker/src/api/controllers/admin/configs.js +++ b/packages/worker/src/api/controllers/admin/configs.js @@ -3,7 +3,6 @@ const { generateConfigID, StaticDatabases, getConfigParams, - determineScopedConfig, getGlobalUserParams, getScopedFullConfig, } = require("@budibase/auth").db @@ -123,7 +122,7 @@ exports.configChecklist = async function (ctx) { const appDbNames = allDbs.filter(dbName => dbName.startsWith(APP_PREFIX)) // They have set up SMTP - const smtpConfig = await determineScopedConfig(db, { + const smtpConfig = await getScopedFullConfig(db, { type: Configs.SMTP, })