From 83db31f8997d645152c2de178fb2c03dfb8c8805 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 19 Jul 2021 19:00:53 +0100 Subject: [PATCH] A lot of general fixes around getting logged in, setting up users etc. --- .../builder/src/pages/builder/_layout.svelte | 6 +++- .../src/pages/builder/admin/index.svelte | 6 ++-- .../src/pages/builder/auth/index.svelte | 23 +++++++++++-- .../builder/src/pages/builder/auth/org.svelte | 6 ++-- .../builder/src/pages/builder/index.svelte | 2 +- .../builder/portal/manage/email/index.svelte | 7 ++-- packages/builder/src/stores/portal/admin.js | 33 +++++++++++++++---- packages/builder/src/stores/portal/auth.js | 3 ++ packages/worker/scripts/dev/manage.js | 3 +- .../src/api/controllers/admin/tenants.js | 6 +++- packages/worker/src/api/index.js | 4 +++ .../worker/src/api/routes/admin/tenants.js | 3 -- packages/worker/src/api/routes/index.js | 2 ++ packages/worker/src/environment.js | 4 +-- 14 files changed, 82 insertions(+), 26 deletions(-) diff --git a/packages/builder/src/pages/builder/_layout.svelte b/packages/builder/src/pages/builder/_layout.svelte index cde1d332b2..ce883ee541 100644 --- a/packages/builder/src/pages/builder/_layout.svelte +++ b/packages/builder/src/pages/builder/_layout.svelte @@ -4,7 +4,9 @@ import { onMount } from "svelte" let loaded = false + $: multiTenancyEnabled = $admin.multiTenancy $: hasAdminUser = !!$admin?.checklist?.adminUser + $: tenantSet = $auth.tenantSet onMount(async () => { await admin.init() @@ -14,7 +16,9 @@ // Force creation of an admin user if one doesn't exist $: { - if (loaded && !hasAdminUser) { + if (loaded && multiTenancyEnabled && !tenantSet) { + $redirect("./auth/org") + } else if (loaded && !hasAdminUser) { $redirect("./admin") } } diff --git a/packages/builder/src/pages/builder/admin/index.svelte b/packages/builder/src/pages/builder/admin/index.svelte index 4a6ded819a..cf882132ad 100644 --- a/packages/builder/src/pages/builder/admin/index.svelte +++ b/packages/builder/src/pages/builder/admin/index.svelte @@ -9,15 +9,18 @@ } from "@budibase/bbui" import { goto } from "@roxi/routify" import api from "builderStore/api" - import { admin } from "stores/portal" + import { admin, auth } from "stores/portal" import PasswordRepeatInput from "components/common/users/PasswordRepeatInput.svelte" import Logo from "assets/bb-emblem.svg" let adminUser = {} let error + $: tenantId = $auth.tenantId + async function save() { try { + adminUser.tenantId = tenantId // Save the admin user const response = await api.post(`/api/admin/users/init`, adminUser) const json = await response.json() @@ -44,7 +47,6 @@ - diff --git a/packages/builder/src/pages/builder/auth/index.svelte b/packages/builder/src/pages/builder/auth/index.svelte index d335c3dfba..bbdd9949ba 100644 --- a/packages/builder/src/pages/builder/auth/index.svelte +++ b/packages/builder/src/pages/builder/auth/index.svelte @@ -1,5 +1,24 @@ diff --git a/packages/builder/src/pages/builder/auth/org.svelte b/packages/builder/src/pages/builder/auth/org.svelte index 33692030b9..ee3f2b9d4a 100644 --- a/packages/builder/src/pages/builder/auth/org.svelte +++ b/packages/builder/src/pages/builder/auth/org.svelte @@ -1,14 +1,16 @@