From a2cabb01d5253c4bfeb52b877915878dbe017334 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 4 Apr 2023 13:53:30 +0100 Subject: [PATCH] Removing user app sync calls from worker - no longer required. --- packages/worker/src/sdk/users/users.ts | 10 ----- packages/worker/src/utilities/appService.ts | 46 --------------------- 2 files changed, 56 deletions(-) delete mode 100644 packages/worker/src/utilities/appService.ts diff --git a/packages/worker/src/sdk/users/users.ts b/packages/worker/src/sdk/users/users.ts index f05c6b98d2..efc683302e 100644 --- a/packages/worker/src/sdk/users/users.ts +++ b/packages/worker/src/sdk/users/users.ts @@ -1,5 +1,4 @@ import env from "../../environment" -import * as apps from "../../utilities/appService" import * as eventHelpers from "./events" import { accounts, @@ -29,7 +28,6 @@ import { PlatformUser, PlatformUserByEmail, RowResponse, - SearchUsersRequest, User, SaveUserOpts, } from "@budibase/types" @@ -275,9 +273,6 @@ export const save = async ( await platform.users.addUser(tenantId, builtUser._id!, builtUser.email) await cache.user.invalidateUser(response.id) - // let server know to sync user - await apps.syncUserInApps(_id, dbUser) - await Promise.all(groupPromises) // finally returned the saved user from the db @@ -424,7 +419,6 @@ export const bulkCreate = async ( // instead of relying on looping tenant creation await platform.users.addUser(tenantId, user._id, user.email) await eventHelpers.handleSaveEvents(user, undefined) - await apps.syncUserInApps(user._id) } const saved = usersToBulkSave.map(user => { @@ -563,8 +557,6 @@ export const destroy = async (id: string) => { await eventHelpers.handleDeleteEvents(dbUser) await cache.user.invalidateUser(userId) await sessions.invalidateSessions(userId, { reason: "deletion" }) - // let server know to sync user - await apps.syncUserInApps(userId, dbUser) } const bulkDeleteProcessing = async (dbUser: User) => { @@ -573,8 +565,6 @@ const bulkDeleteProcessing = async (dbUser: User) => { await eventHelpers.handleDeleteEvents(dbUser) await cache.user.invalidateUser(userId) await sessions.invalidateSessions(userId, { reason: "bulk-deletion" }) - // let server know to sync user - await apps.syncUserInApps(userId, dbUser) } export const invite = async ( diff --git a/packages/worker/src/utilities/appService.ts b/packages/worker/src/utilities/appService.ts deleted file mode 100644 index 8f411d58fa..0000000000 --- a/packages/worker/src/utilities/appService.ts +++ /dev/null @@ -1,46 +0,0 @@ -import fetch from "node-fetch" -import { - constants, - tenancy, - logging, - env as coreEnv, -} from "@budibase/backend-core" -import { checkSlashesInUrl } from "../utilities" -import env from "../environment" -import { SyncUserRequest, User } from "@budibase/types" - -async function makeAppRequest(url: string, method: string, body: any) { - if (env.isTest()) { - return - } - const request: any = { headers: {} } - request.headers[constants.Header.API_KEY] = coreEnv.INTERNAL_API_KEY - if (tenancy.isTenantIdSet()) { - request.headers[constants.Header.TENANT_ID] = tenancy.getTenantId() - } - if (body) { - request.headers["Content-Type"] = "application/json" - request.body = JSON.stringify(body) - } - request.method = method - - // add x-budibase-correlation-id header - logging.correlation.setHeader(request.headers) - - return fetch(checkSlashesInUrl(env.APPS_URL + url), request) -} - -export async function syncUserInApps(userId: string, previousUser?: User) { - const body: SyncUserRequest = { - previousUser, - } - - const response = await makeAppRequest( - `/api/users/metadata/sync/${userId}`, - "POST", - body - ) - if (response && response.status !== 200) { - throw "Unable to sync user." - } -}