Skip to content

Commit

Permalink
Fix webcrawler deletion logic (#3973)
Browse files Browse the repository at this point in the history
* Fix webcrawler deletion logic

* remove imports
  • Loading branch information
spolu authored Feb 27, 2024
1 parent 32e7d3e commit 7be3c0c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 30 deletions.
11 changes: 5 additions & 6 deletions front/lib/api/data_sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,11 @@ export async function deleteDataSource(

const dustAPIProjectId = dataSource.dustAPIProjectId;

if (
dataSource.connectorId &&
dataSource.connectorProvider &&
!MANAGED_DS_DELETABLE_AS_BUILDER.includes(dataSource.connectorProvider)
) {
if (!auth.isAdmin()) {
if (dataSource.connectorId && dataSource.connectorProvider) {
if (
!MANAGED_DS_DELETABLE_AS_BUILDER.includes(dataSource.connectorProvider) &&
!auth.isAdmin()
) {
return new Err({
type: "workspace_auth_error",
message:
Expand Down
25 changes: 1 addition & 24 deletions front/pages/api/w/[wId]/data_sources/[name]/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { DataSourceType, WithAPIErrorReponse } from "@dust-tt/types";
import { ConnectorsAPI } from "@dust-tt/types";
import type { NextApiRequest, NextApiResponse } from "next";

import {
Expand All @@ -9,7 +8,6 @@ import {
} from "@app/lib/api/data_sources";
import { Authenticator, getSession } from "@app/lib/auth";
import { DataSource } from "@app/lib/models";
import logger from "@app/logger/logger";
import { apiError, withLogging } from "@app/logger/withlogging";

export type GetOrPostDataSourceResponseBody = {
Expand Down Expand Up @@ -174,7 +172,7 @@ async function handler(
});
}

// We only expose deleted non-managed data sources.
// We only allow deleteing selected managed data sources as builder.
if (
dataSource.connectorId &&
dataSource.connectorProvider &&
Expand All @@ -189,27 +187,6 @@ async function handler(
});
}

if (dataSource.connectorId && !dataSource.connectorProvider) {
const connectorsAPI = new ConnectorsAPI(logger);
const deleteRes = await connectorsAPI.deleteConnector(
dataSource.connectorId
);
if (deleteRes.isErr()) {
return apiError(
req,
res,
{
status_code: 500,
api_error: {
type: "internal_server_error",
message: deleteRes.error.message,
},
},
new Error(deleteRes.error.message)
);
}
}

const dRes = await deleteDataSource(auth, dataSource.name);
if (dRes.isErr()) {
return apiError(req, res, {
Expand Down

0 comments on commit 7be3c0c

Please sign in to comment.