From d5a03bf5e3e085dc8c1e3b8360024bab3ead581e Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 17 Jul 2023 18:03:09 +0100 Subject: [PATCH] Making sure tenant ID is always available to the builder websocket. --- packages/backend-core/src/context/mainContext.ts | 9 --------- packages/server/src/websockets/builder.ts | 8 +++++--- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/packages/backend-core/src/context/mainContext.ts b/packages/backend-core/src/context/mainContext.ts index ae198aafc7..61d96bb4b0 100644 --- a/packages/backend-core/src/context/mainContext.ts +++ b/packages/backend-core/src/context/mainContext.ts @@ -203,15 +203,6 @@ export function getTenantId(): string { return tenantId } -export function hasTenantId(): boolean { - if (!isMultiTenant()) { - return true - } - const context = Context.get() - const tenantId = context?.tenantId - return tenantId != null -} - export function getAutomationId(): string | undefined { const context = Context.get() return context?.automationId diff --git a/packages/server/src/websockets/builder.ts b/packages/server/src/websockets/builder.ts index 5a12cb239d..020bc30d7a 100644 --- a/packages/server/src/websockets/builder.ts +++ b/packages/server/src/websockets/builder.ts @@ -15,7 +15,6 @@ import { gridSocket } from "./index" import { clearLock, updateLock } from "../utilities/redis" import { Socket } from "socket.io" import { BuilderSocketEvent } from "@budibase/shared-core" -import { hasTenantId } from "@budibase/backend-core/src/context" export default class BuilderSocket extends BaseSocket { constructor(app: Koa, server: http.Server) { @@ -36,8 +35,11 @@ export default class BuilderSocket extends BaseSocket { } }) - if (context.hasTenantId()) { - await events.user.dataCollaboration(Object.keys(userIdMap).length) + const tenantId = context.getTenantIDFromAppID(appId) + if (tenantId) { + await context.doInTenant(tenantId, async () => { + await events.user.dataCollaboration(Object.keys(userIdMap).length) + }) } // Reply with all current sessions