From e62c858a8dbe3ff1cf9e61f9814d1469f82ee433 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 21 Jul 2021 17:52:42 +0100 Subject: [PATCH] Adding mechanism to disable org functionality when multi-tenancy disabled. --- packages/auth/src/db/utils.js | 3 ++- .../src/pages/builder/admin/index.svelte | 20 ++++++++++++++++--- .../src/pages/builder/auth/forgot.svelte | 17 +++++++++++----- .../src/pages/builder/auth/index.svelte | 1 - .../src/pages/builder/auth/login.svelte | 19 ++++++++++++------ .../builder/src/pages/builder/auth/org.svelte | 6 +++++- .../builder/portal/manage/auth/index.svelte | 2 -- packages/builder/src/stores/portal/auth.js | 2 +- 8 files changed, 50 insertions(+), 20 deletions(-) diff --git a/packages/auth/src/db/utils.js b/packages/auth/src/db/utils.js index 804d136086..501df2de25 100644 --- a/packages/auth/src/db/utils.js +++ b/packages/auth/src/db/utils.js @@ -87,7 +87,8 @@ exports.getGlobalDB = tenantId => { exports.getGlobalDBFromCtx = ctx => { const user = ctx.user || {} const params = ctx.request.params || {} - return exports.getGlobalDB(user.tenantId || params.tenantId) + const query = ctx.request.query || {} + return exports.getGlobalDB(user.tenantId || params.tenantId || query.tenantId) } /** diff --git a/packages/builder/src/pages/builder/admin/index.svelte b/packages/builder/src/pages/builder/admin/index.svelte index cf882132ad..870492c17f 100644 --- a/packages/builder/src/pages/builder/admin/index.svelte +++ b/packages/builder/src/pages/builder/admin/index.svelte @@ -6,6 +6,7 @@ Layout, Input, Body, + ActionButton, } from "@budibase/bbui" import { goto } from "@roxi/routify" import api from "builderStore/api" @@ -17,6 +18,7 @@ let error $: tenantId = $auth.tenantId + $: multiTenancyEnabled = $admin.multiTenancy async function save() { try { @@ -34,6 +36,11 @@ notifications.error(`Failed to create admin user`) } } + + function changeOrg() { + auth.setOrg(null) + $goto("../auth") + }
@@ -50,9 +57,16 @@ - + + + {#if multiTenancyEnabled} + + Change organisation + + {/if} +
diff --git a/packages/builder/src/pages/builder/auth/forgot.svelte b/packages/builder/src/pages/builder/auth/forgot.svelte index 85301b3f02..4cbd4c243b 100644 --- a/packages/builder/src/pages/builder/auth/forgot.svelte +++ b/packages/builder/src/pages/builder/auth/forgot.svelte @@ -6,10 +6,12 @@ Layout, Body, Heading, + ActionButton, } from "@budibase/bbui" - import { organisation, auth } from "stores/portal" + import {organisation, auth} from "stores/portal" import Logo from "assets/bb-emblem.svg" - import { onMount } from "svelte" + import {onMount} from "svelte" + import {goto} from "@roxi/routify" let email = "" @@ -41,9 +43,14 @@ - + + + $goto("../")}> + Back + + diff --git a/packages/builder/src/pages/builder/auth/index.svelte b/packages/builder/src/pages/builder/auth/index.svelte index bbdd9949ba..61c42ea089 100644 --- a/packages/builder/src/pages/builder/auth/index.svelte +++ b/packages/builder/src/pages/builder/auth/index.svelte @@ -9,7 +9,6 @@ let loaded = false $: { - console.log(loaded) if (loaded && multiTenancyEnabled && !tenantSet) { $redirect("./org") } else if (loaded) { diff --git a/packages/builder/src/pages/builder/auth/login.svelte b/packages/builder/src/pages/builder/auth/login.svelte index 5e50c6a8cd..66d8af5892 100644 --- a/packages/builder/src/pages/builder/auth/login.svelte +++ b/packages/builder/src/pages/builder/auth/login.svelte @@ -10,7 +10,7 @@ notifications, } from "@budibase/bbui" import { goto, params } from "@roxi/routify" - import { auth, organisation, oidc } from "stores/portal" + import {auth, organisation, oidc, admin} from "stores/portal" import GoogleButton from "./_components/GoogleButton.svelte" import OIDCButton from "./_components/OIDCButton.svelte" import Logo from "assets/bb-emblem.svg" @@ -18,8 +18,10 @@ let username = "" let password = "" + let loaded = false $: company = $organisation.company || "Budibase" + $: multiTenancyEnabled = $admin.multiTenancy async function login() { try { @@ -49,6 +51,7 @@ onMount(async () => { await organisation.init() + loaded = true }) @@ -60,8 +63,10 @@ logo Sign in to {company} - - + {#if loaded} + + + {/if} Sign in with email @@ -78,9 +83,11 @@ $goto("./forgot")}> Forgot password? - $goto("./org")}> - Change organisation - + {#if multiTenancyEnabled} + $goto("./org")}> + Change organisation + + {/if} diff --git a/packages/builder/src/pages/builder/auth/org.svelte b/packages/builder/src/pages/builder/auth/org.svelte index ee3f2b9d4a..166935a135 100644 --- a/packages/builder/src/pages/builder/auth/org.svelte +++ b/packages/builder/src/pages/builder/auth/org.svelte @@ -3,10 +3,14 @@ import { goto } from "@roxi/routify" import { auth, admin } from "stores/portal" import Logo from "assets/bb-emblem.svg" + import { get } from "svelte/store" - let tenantId = "" + let tenantId = get(auth).tenantSet ? get(auth).tenantId : "" async function setOrg() { + if (tenantId == null || tenantId === "") { + tenantId = "default" + } auth.setOrg(tenantId) // re-init now org selected await admin.init() diff --git a/packages/builder/src/pages/builder/portal/manage/auth/index.svelte b/packages/builder/src/pages/builder/portal/manage/auth/index.svelte index 904c27ecb0..c46b27a4de 100644 --- a/packages/builder/src/pages/builder/portal/manage/auth/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/auth/index.svelte @@ -248,8 +248,6 @@ const oidcResponse = await api.get(`/api/admin/configs/${ConfigTypes.OIDC}`) const oidcDoc = await oidcResponse.json() if (!oidcDoc._id) { - console.log("hi") - providers.oidc = { type: ConfigTypes.OIDC, config: { configs: [{ activated: true }] }, diff --git a/packages/builder/src/stores/portal/auth.js b/packages/builder/src/stores/portal/auth.js index 05a66138f7..fed8e9e1bd 100644 --- a/packages/builder/src/stores/portal/auth.js +++ b/packages/builder/src/stores/portal/auth.js @@ -52,7 +52,7 @@ export function createAuthStore() { setOrg: tenantId => { auth.update(store => { store.tenantId = tenantId - store.tenantSet = true + store.tenantSet = !!tenantId return store }) },