Skip to content

Commit

Permalink
[front] Keep space reoslution for legacy endpoints (#9758)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdraier authored Jan 4, 2025
1 parent 5485944 commit 72baf28
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions front/lib/api/resource_wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,19 +247,43 @@ function withDataSourceFromRoute<T, A extends SessionOrKeyAuthType>(

const dataSource = await DataSourceResource.fetchById(auth, dsId);

const { space } = resources;
if (!space) {
const shouldKeepLegacyEndpointSupport =
sessionOrKeyAuth === null || sessionOrKeyAuth instanceof Authenticator;

if (!dataSource) {
return apiError(req, res, {
status_code: 400,
status_code: 404,
api_error: {
type: "invalid_request_error",
message: "Invalid space id.",
type: "data_source_not_found",
message: "The data source you requested was not found.",
},
});
}

let { space } = resources;

if (!space) {
if (shouldKeepLegacyEndpointSupport) {
if (auth.isSystemKey()) {
// We also handle the legacy usage of connectors that taps into connected data sources which
// are not in the global space. If this is a system key we trust it and set the `spaceId` to the
// dataSource.space.sId.
space = dataSource.space;
} else {
space = await SpaceResource.fetchWorkspaceGlobalSpace(auth);
}
} else {
return apiError(req, res, {
status_code: 400,
api_error: {
type: "invalid_request_error",
message: "Invalid space id.",
},
});
}
}

if (
!dataSource ||
dataSource.space.sId !== space.sId ||
!spaceCheck(space) ||
!hasPermission(auth, dataSource, options.dataSource)
Expand All @@ -277,7 +301,7 @@ function withDataSourceFromRoute<T, A extends SessionOrKeyAuthType>(
req,
res,
auth,
{ ...resources, dataSource },
{ ...resources, space, dataSource },
options,
sessionOrKeyAuth
);
Expand Down

0 comments on commit 72baf28

Please sign in to comment.