Adding mechanism to disable org functionality when multi-tenancy disabled.

This commit is contained in:
mike12345567 2021-07-21 17:52:42 +01:00
parent a9752c0939
commit be1558e1e7
8 changed files with 50 additions and 20 deletions

View File

@ -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)
}
/**

View File

@ -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")
}
</script>
<section>
@ -50,9 +57,16 @@
<Input label="Email" bind:value={adminUser.email} />
<PasswordRepeatInput bind:password={adminUser.password} bind:error />
</Layout>
<Button cta disabled={error} on:click={save}>
Create super admin user
</Button>
<Layout gap="XS" noPadding>
<Button cta disabled={error} on:click={save}>
Create super admin user
</Button>
{#if multiTenancyEnabled}
<ActionButton quiet on:click={changeOrg}>
Change organisation
</ActionButton>
{/if}
</Layout>
</Layout>
</div>
</section>

View File

@ -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 @@
</Body>
<Input label="Email" bind:value={email} />
</Layout>
<Button cta on:click={forgot} disabled={!email}>
Reset your password
</Button>
<Layout gap="XS" nopadding>
<Button cta on:click={forgot} disabled={!email}>
Reset your password
</Button>
<ActionButton quiet on:click={() => $goto("../")}>
Back
</ActionButton>
</Layout>
</Layout>
</div>
</div>

View File

@ -9,7 +9,6 @@
let loaded = false
$: {
console.log(loaded)
if (loaded && multiTenancyEnabled && !tenantSet) {
$redirect("./org")
} else if (loaded) {

View File

@ -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
})
</script>
@ -60,8 +63,10 @@
<img alt="logo" src={$organisation.logoUrl || Logo} />
<Heading>Sign in to {company}</Heading>
</Layout>
<GoogleButton />
<OIDCButton oidcIcon={$oidc.logo} oidcName={$oidc.name} />
{#if loaded}
<GoogleButton />
<OIDCButton oidcIcon={$oidc.logo} oidcName={$oidc.name} />
{/if}
<Divider noGrid />
<Layout gap="XS" noPadding>
<Body size="S" textAlign="center">Sign in with email</Body>
@ -78,9 +83,11 @@
<ActionButton quiet on:click={() => $goto("./forgot")}>
Forgot password?
</ActionButton>
<ActionButton quiet on:click={() => $goto("./org")}>
Change organisation
</ActionButton>
{#if multiTenancyEnabled}
<ActionButton quiet on:click={() => $goto("./org")}>
Change organisation
</ActionButton>
{/if}
</Layout>
</Layout>
</div>

View File

@ -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()

View File

@ -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 }] },

View File

@ -52,7 +52,7 @@ export function createAuthStore() {
setOrg: tenantId => {
auth.update(store => {
store.tenantId = tenantId
store.tenantSet = true
store.tenantSet = !!tenantId
return store
})
},