From 4cc19fb7d1560c999ebf4aef01017a2aa91a0b15 Mon Sep 17 00:00:00 2001 From: timothycarambat Date: Mon, 16 Oct 2023 16:43:23 -0700 Subject: [PATCH] block tool jobs when organization has no connection --- backend/endpoints/v1/tools/index.js | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/backend/endpoints/v1/tools/index.js b/backend/endpoints/v1/tools/index.js index 1a67056..a3e0a9f 100644 --- a/backend/endpoints/v1/tools/index.js +++ b/backend/endpoints/v1/tools/index.js @@ -1,4 +1,7 @@ const { Organization } = require("../../../models/organization"); +const { + OrganizationConnection, +} = require("../../../models/organizationConnection"); const { Queue } = require("../../../models/queue"); const { userFromSession, @@ -51,6 +54,20 @@ function toolEndpoints(app) { return; } + const originalConnector = await OrganizationConnection.get({ + organization_id: Number(organization.id), + }); + if (!originalConnector) { + response + .status(200) + .json({ + success: false, + message: + "No vector database is connected to the original organization.", + }); + return; + } + const destinationOrg = await Organization.get({ id: Number(destinationOrgId), }); @@ -62,6 +79,20 @@ function toolEndpoints(app) { return; } + const destinationConnector = await OrganizationConnection.get({ + organization_id: Number(destinationOrg.id), + }); + if (!destinationConnector) { + response + .status(200) + .json({ + success: false, + message: + "No vector database is connected to the destination organization.", + }); + return; + } + const existingJobForOrg = await Queue.get({ taskName: "workspace/migrate", status: "pending", @@ -114,6 +145,19 @@ function toolEndpoints(app) { return; } + const connector = await OrganizationConnection.get({ + organization_id: Number(organization.id), + }); + if (!connector) { + response + .status(200) + .json({ + success: false, + message: "No vector database is connected to this organization.", + }); + return; + } + const pendingJobs = await Queue.where({ status: "pending", organization_id: organization.id,