1
0
Fork 0
mirror of synced 2024-06-01 10:09:48 +12:00

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 29efa60eab
commit e62c858a8d
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
})
},