Merge pull request #12698 from Budibase/fix/multi-tenancy-dev-access
Fix local development of multi-tenancy apps
This commit is contained in:
commit
9fa94635b8
|
@ -134,7 +134,7 @@ export async function doInContext(appId: string, task: any): Promise<any> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function doInTenant<T>(
|
export async function doInTenant<T>(
|
||||||
tenantId: string | null,
|
tenantId: string | undefined,
|
||||||
task: () => T
|
task: () => T
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
// make sure default always selected in single tenancy
|
// make sure default always selected in single tenancy
|
||||||
|
|
|
@ -39,7 +39,7 @@ const ALL_STRATEGIES = Object.values(TenantResolutionStrategy)
|
||||||
export const getTenantIDFromCtx = (
|
export const getTenantIDFromCtx = (
|
||||||
ctx: BBContext,
|
ctx: BBContext,
|
||||||
opts: GetTenantIdOptions
|
opts: GetTenantIdOptions
|
||||||
): string | null => {
|
): string | undefined => {
|
||||||
// exit early if not multi-tenant
|
// exit early if not multi-tenant
|
||||||
if (!isMultiTenant()) {
|
if (!isMultiTenant()) {
|
||||||
return DEFAULT_TENANT_ID
|
return DEFAULT_TENANT_ID
|
||||||
|
@ -144,5 +144,5 @@ export const getTenantIDFromCtx = (
|
||||||
ctx.throw(403, "Tenant id not set")
|
ctx.throw(403, "Tenant id not set")
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,12 +157,12 @@ describe("getTenantIDFromCtx", () => {
|
||||||
TenantResolutionStrategy.PATH,
|
TenantResolutionStrategy.PATH,
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
expect(getTenantIDFromCtx(ctx, mockOpts)).toBeNull()
|
expect(getTenantIDFromCtx(ctx, mockOpts)).toBeUndefined()
|
||||||
expect(ctx.throw).toBeCalledTimes(1)
|
expect(ctx.throw).toBeCalledTimes(1)
|
||||||
expect(ctx.throw).toBeCalledWith(403, "Tenant id not set")
|
expect(ctx.throw).toBeCalledWith(403, "Tenant id not set")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("returns null if allowNoTenant is true", () => {
|
it("returns undefined if allowNoTenant is true", () => {
|
||||||
const ctx = createCtx({})
|
const ctx = createCtx({})
|
||||||
mockOpts = {
|
mockOpts = {
|
||||||
allowNoTenant: true,
|
allowNoTenant: true,
|
||||||
|
@ -172,7 +172,7 @@ describe("getTenantIDFromCtx", () => {
|
||||||
TenantResolutionStrategy.PATH,
|
TenantResolutionStrategy.PATH,
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
expect(getTenantIDFromCtx(ctx, mockOpts)).toBeNull()
|
expect(getTenantIDFromCtx(ctx, mockOpts)).toBeUndefined()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,8 @@ export async function resolveAppUrl(ctx: Ctx) {
|
||||||
const appUrl = ctx.path.split("/")[2]
|
const appUrl = ctx.path.split("/")[2]
|
||||||
let possibleAppUrl = `/${appUrl.toLowerCase()}`
|
let possibleAppUrl = `/${appUrl.toLowerCase()}`
|
||||||
|
|
||||||
let tenantId: string | null = context.getTenantId()
|
let tenantId: string | undefined = context.getTenantId()
|
||||||
if (env.MULTI_TENANCY) {
|
if (!env.isDev() && env.MULTI_TENANCY) {
|
||||||
// always use the tenant id from the subdomain in multi tenancy
|
// always use the tenant id from the subdomain in multi tenancy
|
||||||
// this ensures the logged-in user tenant id doesn't overwrite
|
// this ensures the logged-in user tenant id doesn't overwrite
|
||||||
// e.g. in the case of viewing a public app while already logged-in to another tenant
|
// e.g. in the case of viewing a public app while already logged-in to another tenant
|
||||||
|
@ -41,7 +41,7 @@ export async function resolveAppUrl(ctx: Ctx) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// search prod apps for a url that matches
|
// search prod apps for an url that matches
|
||||||
const apps: App[] = await context.doInTenant(
|
const apps: App[] = await context.doInTenant(
|
||||||
tenantId,
|
tenantId,
|
||||||
() => getAllApps({ dev: false }) as Promise<App[]>
|
() => getAllApps({ dev: false }) as Promise<App[]>
|
||||||
|
|
Loading…
Reference in New Issue