From 09c38a6d95f6221df9a0bedb378145a3cff3b515 Mon Sep 17 00:00:00 2001 From: Flavien David Date: Thu, 1 Aug 2024 18:19:51 +0200 Subject: [PATCH 01/11] Pass group ids to core when creating runs --- .../api/v1/w/[wId]/apps/[aId]/runs/index.ts | 3 +- .../api/w/[wId]/apps/[aId]/runs/index.ts | 3 +- types/src/front/lib/core_api.ts | 72 ++++++++++--------- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts b/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts index d61eac15f31a..4a33393878c6 100644 --- a/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts +++ b/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts @@ -285,9 +285,8 @@ async function handler( "App run creation" ); - const runRes = await coreAPI.createRunStream({ + const runRes = await coreAPI.createRunStream(auth, { projectId: app.dustAPIProjectId, - runAsWorkspaceId: keyWorkspaceId, runType: "deploy", specificationHash: specificationHash, config: { blocks: config }, diff --git a/front/pages/api/w/[wId]/apps/[aId]/runs/index.ts b/front/pages/api/w/[wId]/apps/[aId]/runs/index.ts index 8b9ebcf7df63..d010cbf8227c 100644 --- a/front/pages/api/w/[wId]/apps/[aId]/runs/index.ts +++ b/front/pages/api/w/[wId]/apps/[aId]/runs/index.ts @@ -111,9 +111,8 @@ async function handler( ); const inputDataset = inputConfigEntry ? inputConfigEntry.dataset : null; - const dustRun = await coreAPI.createRun({ + const dustRun = await coreAPI.createRun(auth, { projectId: app.dustAPIProjectId, - runAsWorkspaceId: owner.sId, runType: "local", specification: dumpSpecification( JSON.parse(req.body.specification), diff --git a/types/src/front/lib/core_api.ts b/types/src/front/lib/core_api.ts index e175784b9da8..f338a43c6634 100644 --- a/types/src/front/lib/core_api.ts +++ b/types/src/front/lib/core_api.ts @@ -22,6 +22,7 @@ import { } from "../../front/run"; import { LoggerInterface } from "../../shared/logger"; import { Err, Ok, Result } from "../../shared/result"; +import { BaseAuthenticator } from "../auth"; export const MAX_CHUNK_SIZE = 512; @@ -89,7 +90,6 @@ export type CoreAPITokenType = [number, string]; type CoreAPICreateRunParams = { projectId: string; - runAsWorkspaceId: string; runType: RunRunType; specification?: string | null; specificationHash?: string | null; @@ -280,28 +280,31 @@ export class CoreAPI { return this._resultFromResponse(response); } - async createRun({ - projectId, - runAsWorkspaceId, - runType, - specification, - specificationHash, - datasetId, - inputs, - config, - credentials, - secrets, - }: CoreAPICreateRunParams): Promise> { - // TODO(GROUPS_INFRA): use the auth as argument of that method instead of `runAsWorkspaceId` - // and pass both X-Dust-Workspace-Id and X-Dust-Group-Ids. - + async createRun( + auth: BaseAuthenticator, + { + projectId, + runType, + specification, + specificationHash, + datasetId, + inputs, + config, + credentials, + secrets, + }: CoreAPICreateRunParams + ): Promise> { const response = await this._fetchWithError( `${this._url}/projects/${encodeURIComponent(projectId)}/runs`, { method: "POST", headers: { "Content-Type": "application/json", - "X-Dust-Workspace-Id": runAsWorkspaceId, + "X-Dust-Workspace-Id": auth.getNonNullableWorkspace().sId, + "X-Dust-Group-Ids": auth + .groups() + .map((g) => g.sId) + .join(","), }, body: JSON.stringify({ run_type: runType, @@ -319,33 +322,36 @@ export class CoreAPI { return this._resultFromResponse(response); } - async createRunStream({ - projectId, - runAsWorkspaceId, - runType, - specification, - specificationHash, - datasetId, - inputs, - config, - credentials, - secrets, - }: CoreAPICreateRunParams): Promise< + async createRunStream( + auth: BaseAuthenticator, + { + projectId, + runType, + specification, + specificationHash, + datasetId, + inputs, + config, + credentials, + secrets, + }: CoreAPICreateRunParams + ): Promise< CoreAPIResponse<{ chunkStream: AsyncGenerator; dustRunId: Promise; }> > { - // TODO(GROUPS_INFRA): use the auth as argument of that method instead of `runAsWorkspaceId` - // and pass both X-Dust-Workspace-Id and X-Dust-Group-Ids. - const res = await this._fetchWithError( `${this._url}/projects/${projectId}/runs/stream`, { method: "POST", headers: { "Content-Type": "application/json", - "X-Dust-Workspace-Id": runAsWorkspaceId, + "X-Dust-Workspace-Id": auth.getNonNullableWorkspace().sId, + "X-Dust-Group-Ids": auth + .groups() + .map((g) => g.sId) + .join(","), }, body: JSON.stringify({ run_type: runType, From 2e236187bf600d85a6ef10b8cf66cdaca1cbb987 Mon Sep 17 00:00:00 2001 From: Flavien David Date: Thu, 1 Aug 2024 18:21:17 +0200 Subject: [PATCH 02/11] Add BaseAuthenticator type --- types/src/front/auth.ts | 11 +++++++++++ types/src/index.ts | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 types/src/front/auth.ts diff --git a/types/src/front/auth.ts b/types/src/front/auth.ts new file mode 100644 index 000000000000..51643d90ca0e --- /dev/null +++ b/types/src/front/auth.ts @@ -0,0 +1,11 @@ +import { GroupType } from "./groups"; +import { LightWorkspaceType } from "./user"; + +// Authenticator is a concept that lives in front, +// but it's used when doing api calls to other services. +// This interface is a cheap way to represent the concept of an authenticator within types. +export interface BaseAuthenticator { + groups: () => GroupType[]; + + getNonNullableWorkspace: () => LightWorkspaceType; +} diff --git a/types/src/index.ts b/types/src/index.ts index 1cc99b31acc7..bcef466992f9 100644 --- a/types/src/index.ts +++ b/types/src/index.ts @@ -25,13 +25,14 @@ export * from "./front/assistant/actions/guards"; export * from "./front/assistant/actions/process"; export * from "./front/assistant/actions/retrieval"; export * from "./front/assistant/actions/tables_query"; +export * from "./front/assistant/actions/visualization"; export * from "./front/assistant/actions/websearch"; export * from "./front/assistant/agent"; export * from "./front/assistant/avatar"; export * from "./front/assistant/builder"; export * from "./front/assistant/conversation"; export * from "./front/assistant/templates"; -export * from "./front/assistant/visualization"; +export * from "./front/auth"; export * from "./front/content_fragment"; export * from "./front/data_source"; export * from "./front/data_source_view"; @@ -49,6 +50,7 @@ export * from "./front/lib/api/assistant/actions/index"; export * from "./front/lib/api/assistant/actions/process"; export * from "./front/lib/api/assistant/actions/retrieval"; export * from "./front/lib/api/assistant/actions/tables_query"; +export * from "./front/lib/api/assistant/actions/visualization"; export * from "./front/lib/api/assistant/actions/websearch"; export * from "./front/lib/api/assistant/agent"; export * from "./front/lib/api/assistant/conversation"; From 5b42e29456b1fca0798f10b6de57007103cfda72 Mon Sep 17 00:00:00 2001 From: Flavien David Date: Thu, 1 Aug 2024 18:23:15 +0200 Subject: [PATCH 03/11] :see_no_evil: --- types/src/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/types/src/index.ts b/types/src/index.ts index bcef466992f9..8efb3e848098 100644 --- a/types/src/index.ts +++ b/types/src/index.ts @@ -25,13 +25,13 @@ export * from "./front/assistant/actions/guards"; export * from "./front/assistant/actions/process"; export * from "./front/assistant/actions/retrieval"; export * from "./front/assistant/actions/tables_query"; -export * from "./front/assistant/actions/visualization"; export * from "./front/assistant/actions/websearch"; export * from "./front/assistant/agent"; export * from "./front/assistant/avatar"; export * from "./front/assistant/builder"; export * from "./front/assistant/conversation"; export * from "./front/assistant/templates"; +export * from "./front/assistant/visualization"; export * from "./front/auth"; export * from "./front/content_fragment"; export * from "./front/data_source"; @@ -50,7 +50,6 @@ export * from "./front/lib/api/assistant/actions/index"; export * from "./front/lib/api/assistant/actions/process"; export * from "./front/lib/api/assistant/actions/retrieval"; export * from "./front/lib/api/assistant/actions/tables_query"; -export * from "./front/lib/api/assistant/actions/visualization"; export * from "./front/lib/api/assistant/actions/websearch"; export * from "./front/lib/api/assistant/agent"; export * from "./front/lib/api/assistant/conversation"; From f705369103bd79a6dd43cda15cbde04d27a016ee Mon Sep 17 00:00:00 2001 From: Flavien David Date: Thu, 1 Aug 2024 18:32:33 +0200 Subject: [PATCH 04/11] :scissors: --- front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts b/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts index 4a33393878c6..07fcf3f03d83 100644 --- a/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts +++ b/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts @@ -173,7 +173,7 @@ async function handler( if (keyRes.isErr()) { return apiError(req, res, keyRes.error); } - const { auth, keyWorkspaceId } = await Authenticator.fromKey( + const { auth } = await Authenticator.fromKey( keyRes.value, req.query.wId as string ); From f674fffd7002db0f3cef138ed2f163ed845abba1 Mon Sep 17 00:00:00 2001 From: Flavien David Date: Thu, 1 Aug 2024 19:27:30 +0200 Subject: [PATCH 05/11] :sparkles: --- .../api/v1/w/[wId]/apps/[aId]/runs/index.ts | 22 +++++++++------ .../api/w/[wId]/apps/[aId]/runs/index.ts | 28 +++++++++++-------- types/src/front/auth.ts | 11 -------- types/src/front/lib/core_api.ts | 23 +++++++-------- types/src/index.ts | 1 - 5 files changed, 39 insertions(+), 46 deletions(-) delete mode 100644 types/src/front/auth.ts diff --git a/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts b/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts index 07fcf3f03d83..8d1de2043693 100644 --- a/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts +++ b/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts @@ -285,15 +285,19 @@ async function handler( "App run creation" ); - const runRes = await coreAPI.createRunStream(auth, { - projectId: app.dustAPIProjectId, - runType: "deploy", - specificationHash: specificationHash, - config: { blocks: config }, - inputs, - credentials, - secrets, - }); + const runRes = await coreAPI.createRunStream( + auth.getNonNullableWorkspace(), + auth.groups(), + { + projectId: app.dustAPIProjectId, + runType: "deploy", + specificationHash: specificationHash, + config: { blocks: config }, + inputs, + credentials, + secrets, + } + ); if (runRes.isErr()) { return apiError(req, res, { diff --git a/front/pages/api/w/[wId]/apps/[aId]/runs/index.ts b/front/pages/api/w/[wId]/apps/[aId]/runs/index.ts index d010cbf8227c..525ff235eb81 100644 --- a/front/pages/api/w/[wId]/apps/[aId]/runs/index.ts +++ b/front/pages/api/w/[wId]/apps/[aId]/runs/index.ts @@ -111,18 +111,22 @@ async function handler( ); const inputDataset = inputConfigEntry ? inputConfigEntry.dataset : null; - const dustRun = await coreAPI.createRun(auth, { - projectId: app.dustAPIProjectId, - runType: "local", - specification: dumpSpecification( - JSON.parse(req.body.specification), - latestDatasets - ), - datasetId: inputDataset, - config: { blocks: config }, - credentials: credentialsFromProviders(providers), - secrets, - }); + const dustRun = await coreAPI.createRun( + auth.getNonNullableWorkspace(), + auth.groups(), + { + projectId: app.dustAPIProjectId, + runType: "local", + specification: dumpSpecification( + JSON.parse(req.body.specification), + latestDatasets + ), + datasetId: inputDataset, + config: { blocks: config }, + credentials: credentialsFromProviders(providers), + secrets, + } + ); if (dustRun.isErr()) { return apiError(req, res, { diff --git a/types/src/front/auth.ts b/types/src/front/auth.ts deleted file mode 100644 index 51643d90ca0e..000000000000 --- a/types/src/front/auth.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { GroupType } from "./groups"; -import { LightWorkspaceType } from "./user"; - -// Authenticator is a concept that lives in front, -// but it's used when doing api calls to other services. -// This interface is a cheap way to represent the concept of an authenticator within types. -export interface BaseAuthenticator { - groups: () => GroupType[]; - - getNonNullableWorkspace: () => LightWorkspaceType; -} diff --git a/types/src/front/lib/core_api.ts b/types/src/front/lib/core_api.ts index f338a43c6634..ab51bb74f9c5 100644 --- a/types/src/front/lib/core_api.ts +++ b/types/src/front/lib/core_api.ts @@ -22,7 +22,8 @@ import { } from "../../front/run"; import { LoggerInterface } from "../../shared/logger"; import { Err, Ok, Result } from "../../shared/result"; -import { BaseAuthenticator } from "../auth"; +import { GroupType } from "../groups"; +import { LightWorkspaceType } from "../user"; export const MAX_CHUNK_SIZE = 512; @@ -281,7 +282,8 @@ export class CoreAPI { } async createRun( - auth: BaseAuthenticator, + workspace: LightWorkspaceType, + groups: GroupType[], { projectId, runType, @@ -300,11 +302,8 @@ export class CoreAPI { method: "POST", headers: { "Content-Type": "application/json", - "X-Dust-Workspace-Id": auth.getNonNullableWorkspace().sId, - "X-Dust-Group-Ids": auth - .groups() - .map((g) => g.sId) - .join(","), + "X-Dust-Workspace-Id": workspace.sId, + "X-Dust-Group-Ids": groups.map((g) => g.sId).join(","), }, body: JSON.stringify({ run_type: runType, @@ -323,7 +322,8 @@ export class CoreAPI { } async createRunStream( - auth: BaseAuthenticator, + workspace: LightWorkspaceType, + groups: GroupType[], { projectId, runType, @@ -347,11 +347,8 @@ export class CoreAPI { method: "POST", headers: { "Content-Type": "application/json", - "X-Dust-Workspace-Id": auth.getNonNullableWorkspace().sId, - "X-Dust-Group-Ids": auth - .groups() - .map((g) => g.sId) - .join(","), + "X-Dust-Workspace-Id": workspace.sId, + "X-Dust-Group-Ids": groups.map((g) => g.sId).join(","), }, body: JSON.stringify({ run_type: runType, diff --git a/types/src/index.ts b/types/src/index.ts index 8efb3e848098..1cc99b31acc7 100644 --- a/types/src/index.ts +++ b/types/src/index.ts @@ -32,7 +32,6 @@ export * from "./front/assistant/builder"; export * from "./front/assistant/conversation"; export * from "./front/assistant/templates"; export * from "./front/assistant/visualization"; -export * from "./front/auth"; export * from "./front/content_fragment"; export * from "./front/data_source"; export * from "./front/data_source_view"; From cad90403204feca8bbf0d6b3dc25ee1d726c691a Mon Sep 17 00:00:00 2001 From: Flavien David Date: Thu, 1 Aug 2024 19:45:56 +0200 Subject: [PATCH 06/11] Address comments from review --- .../api/v1/w/[wId]/apps/[aId]/runs/index.ts | 26 ++++++------- .../api/w/[wId]/apps/[aId]/runs/index.ts | 39 +++++++++++-------- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts b/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts index 8d1de2043693..e8c2edb2e8a8 100644 --- a/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts +++ b/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts @@ -183,8 +183,8 @@ async function handler( return apiError(req, res, { status_code: 404, api_error: { - type: "app_not_found", - message: "The app you're trying to run was not found", + type: "workspace_not_found", + message: "The workspace was not found.", }, }); } @@ -285,19 +285,15 @@ async function handler( "App run creation" ); - const runRes = await coreAPI.createRunStream( - auth.getNonNullableWorkspace(), - auth.groups(), - { - projectId: app.dustAPIProjectId, - runType: "deploy", - specificationHash: specificationHash, - config: { blocks: config }, - inputs, - credentials, - secrets, - } - ); + const runRes = await coreAPI.createRunStream(owner, auth.groups(), { + projectId: app.dustAPIProjectId, + runType: "deploy", + specificationHash: specificationHash, + config: { blocks: config }, + inputs, + credentials, + secrets, + }); if (runRes.isErr()) { return apiError(req, res, { diff --git a/front/pages/api/w/[wId]/apps/[aId]/runs/index.ts b/front/pages/api/w/[wId]/apps/[aId]/runs/index.ts index 525ff235eb81..f8a5a88d0dd0 100644 --- a/front/pages/api/w/[wId]/apps/[aId]/runs/index.ts +++ b/front/pages/api/w/[wId]/apps/[aId]/runs/index.ts @@ -32,7 +32,16 @@ async function handler( auth: Authenticator, session: SessionWithUser ) { - let owner = auth.getNonNullableWorkspace(); + let owner = auth.workspace(); + if (!owner) { + return apiError(req, res, { + status_code: 404, + api_error: { + type: "workspace_not_found", + message: "The workspace was not found.", + }, + }); + } const app = await getApp(auth, req.query.aId as string); @@ -111,22 +120,18 @@ async function handler( ); const inputDataset = inputConfigEntry ? inputConfigEntry.dataset : null; - const dustRun = await coreAPI.createRun( - auth.getNonNullableWorkspace(), - auth.groups(), - { - projectId: app.dustAPIProjectId, - runType: "local", - specification: dumpSpecification( - JSON.parse(req.body.specification), - latestDatasets - ), - datasetId: inputDataset, - config: { blocks: config }, - credentials: credentialsFromProviders(providers), - secrets, - } - ); + const dustRun = await coreAPI.createRun(owner, auth.groups(), { + projectId: app.dustAPIProjectId, + runType: "local", + specification: dumpSpecification( + JSON.parse(req.body.specification), + latestDatasets + ), + datasetId: inputDataset, + config: { blocks: config }, + credentials: credentialsFromProviders(providers), + secrets, + }); if (dustRun.isErr()) { return apiError(req, res, { From cf1147f370259af462765439999603057f00d283 Mon Sep 17 00:00:00 2001 From: Flavien David Date: Thu, 1 Aug 2024 20:43:12 +0200 Subject: [PATCH 07/11] Use key workspace and groups --- front/lib/auth.ts | 7 ++++++- front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/front/lib/auth.ts b/front/lib/auth.ts index 8af4c6297cf5..3c3f773e8a71 100644 --- a/front/lib/auth.ts +++ b/front/lib/auth.ts @@ -289,7 +289,11 @@ export class Authenticator { static async fromKey( key: KeyResource, wId: string - ): Promise<{ auth: Authenticator; keyWorkspaceId: string }> { + ): Promise<{ + auth: Authenticator; + keyWorkspaceId: string; + keyWorkspace: LightWorkspaceType; + }> { const [workspace, keyWorkspace] = await Promise.all([ (async () => { return Workspace.findOne({ @@ -346,6 +350,7 @@ export class Authenticator { flags, key: key.toAuthJSON(), }), + keyWorkspace: keyWorkspace, keyWorkspaceId: keyWorkspace.sId, }; } diff --git a/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts b/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts index e8c2edb2e8a8..c4424aa24339 100644 --- a/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts +++ b/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts @@ -22,6 +22,7 @@ import apiConfig from "@app/lib/api/config"; import { getDustAppSecrets } from "@app/lib/api/dust_app_secrets"; import { Authenticator, getAPIKey } from "@app/lib/auth"; import { Provider } from "@app/lib/models/apps"; +import { GroupResource } from "@app/lib/resources/group_resource"; import type { RunUsageType } from "@app/lib/resources/run_resource"; import { RunResource } from "@app/lib/resources/run_resource"; import logger from "@app/logger/logger"; @@ -173,7 +174,7 @@ async function handler( if (keyRes.isErr()) { return apiError(req, res, keyRes.error); } - const { auth } = await Authenticator.fromKey( + const { auth, keyWorkspace } = await Authenticator.fromKey( keyRes.value, req.query.wId as string ); @@ -285,7 +286,14 @@ async function handler( "App run creation" ); - const runRes = await coreAPI.createRunStream(owner, auth.groups(), { + const isSameWorkspace = keyWorkspace.sId === owner.sId; + const runAsWorkspace = isSameWorkspace ? owner : keyWorkspace; + + const groups = await GroupResource.listWorkspaceGroupsFromKey( + keyRes.value + ); + + const runRes = await coreAPI.createRunStream(runAsWorkspace, groups, { projectId: app.dustAPIProjectId, runType: "deploy", specificationHash: specificationHash, From 38d60df51f93476a7393458c386b227bcf70986c Mon Sep 17 00:00:00 2001 From: Flavien David Date: Fri, 2 Aug 2024 08:29:08 +0200 Subject: [PATCH 08/11] :shirt: --- front/lib/auth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/lib/auth.ts b/front/lib/auth.ts index 3c3f773e8a71..9aea8e1ecd29 100644 --- a/front/lib/auth.ts +++ b/front/lib/auth.ts @@ -350,7 +350,7 @@ export class Authenticator { flags, key: key.toAuthJSON(), }), - keyWorkspace: keyWorkspace, + keyWorkspace: renderLightWorkspaceType({ workspace: keyWorkspace }), keyWorkspaceId: keyWorkspace.sId, }; } From c0f10e745662157b2c82000cbd1c0302ec75375d Mon Sep 17 00:00:00 2001 From: Flavien David Date: Fri, 2 Aug 2024 09:24:33 +0200 Subject: [PATCH 09/11] Address comments from review --- front/lib/auth.ts | 2 -- front/pages/api/v1/w/[wId]/assistant/agent_configurations.ts | 4 ++-- .../[wId]/assistant/conversations/[cId]/content_fragments.ts | 4 ++-- .../api/v1/w/[wId]/assistant/conversations/[cId]/events.ts | 4 ++-- .../api/v1/w/[wId]/assistant/conversations/[cId]/index.ts | 4 ++-- .../assistant/conversations/[cId]/messages/[mId]/events.ts | 4 ++-- .../w/[wId]/assistant/conversations/[cId]/messages/index.ts | 4 ++-- front/pages/api/v1/w/[wId]/assistant/conversations/index.ts | 4 ++-- 8 files changed, 14 insertions(+), 16 deletions(-) diff --git a/front/lib/auth.ts b/front/lib/auth.ts index 9aea8e1ecd29..4d5abdaa21fd 100644 --- a/front/lib/auth.ts +++ b/front/lib/auth.ts @@ -291,7 +291,6 @@ export class Authenticator { wId: string ): Promise<{ auth: Authenticator; - keyWorkspaceId: string; keyWorkspace: LightWorkspaceType; }> { const [workspace, keyWorkspace] = await Promise.all([ @@ -351,7 +350,6 @@ export class Authenticator { key: key.toAuthJSON(), }), keyWorkspace: renderLightWorkspaceType({ workspace: keyWorkspace }), - keyWorkspaceId: keyWorkspace.sId, }; } diff --git a/front/pages/api/v1/w/[wId]/assistant/agent_configurations.ts b/front/pages/api/v1/w/[wId]/assistant/agent_configurations.ts index 9be4039ebd71..30e1f95d5b17 100644 --- a/front/pages/api/v1/w/[wId]/assistant/agent_configurations.ts +++ b/front/pages/api/v1/w/[wId]/assistant/agent_configurations.ts @@ -53,12 +53,12 @@ async function handler( return apiError(req, res, keyRes.error); } - const { auth, keyWorkspaceId } = await Authenticator.fromKey( + const { auth, keyWorkspace } = await Authenticator.fromKey( keyRes.value, req.query.wId as string ); - if (!auth.isBuilder() || keyWorkspaceId !== req.query.wId) { + if (!auth.isBuilder() || keyWorkspace.sId !== req.query.wId) { return apiError(req, res, { status_code: 400, api_error: { diff --git a/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/content_fragments.ts b/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/content_fragments.ts index 162ab435b1c5..2b6871dacc1b 100644 --- a/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/content_fragments.ts +++ b/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/content_fragments.ts @@ -74,12 +74,12 @@ async function handler( return apiError(req, res, keyRes.error); } - const { auth, keyWorkspaceId } = await Authenticator.fromKey( + const { auth, keyWorkspace } = await Authenticator.fromKey( keyRes.value, req.query.wId as string ); - if (!auth.isBuilder() || keyWorkspaceId !== req.query.wId) { + if (!auth.isBuilder() || keyWorkspace.sId !== req.query.wId) { return apiError(req, res, { status_code: 400, api_error: { diff --git a/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/events.ts b/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/events.ts index c6c1c3fe307e..aa44f70379f6 100644 --- a/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/events.ts +++ b/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/events.ts @@ -53,12 +53,12 @@ async function handler( return apiError(req, res, keyRes.error); } - const { auth, keyWorkspaceId } = await Authenticator.fromKey( + const { auth, keyWorkspace } = await Authenticator.fromKey( keyRes.value, req.query.wId as string ); - if (!auth.isBuilder() || keyWorkspaceId !== req.query.wId) { + if (!auth.isBuilder() || keyWorkspace.sId !== req.query.wId) { return apiError(req, res, { status_code: 400, api_error: { diff --git a/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/index.ts b/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/index.ts index 4eb18cd337ec..a8b8efb8ab0e 100644 --- a/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/index.ts +++ b/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/index.ts @@ -56,12 +56,12 @@ async function handler( return apiError(req, res, keyRes.error); } - const { auth, keyWorkspaceId } = await Authenticator.fromKey( + const { auth, keyWorkspace } = await Authenticator.fromKey( keyRes.value, req.query.wId as string ); - if (!auth.isBuilder() || keyWorkspaceId !== req.query.wId) { + if (!auth.isBuilder() || keyWorkspace.sId !== req.query.wId) { return apiError(req, res, { status_code: 400, api_error: { diff --git a/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/messages/[mId]/events.ts b/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/messages/[mId]/events.ts index 2e126d6537cf..e2f24271454d 100644 --- a/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/messages/[mId]/events.ts +++ b/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/messages/[mId]/events.ts @@ -83,12 +83,12 @@ async function handler( return apiError(req, res, keyRes.error); } - const { auth, keyWorkspaceId } = await Authenticator.fromKey( + const { auth, keyWorkspace } = await Authenticator.fromKey( keyRes.value, req.query.wId as string ); - if (!auth.isBuilder() || keyWorkspaceId !== req.query.wId) { + if (!auth.isBuilder() || keyWorkspace.sId !== req.query.wId) { return apiError(req, res, { status_code: 400, api_error: { diff --git a/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/messages/index.ts b/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/messages/index.ts index dffefc4a56a2..a19923a84f2d 100644 --- a/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/messages/index.ts +++ b/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/messages/index.ts @@ -79,9 +79,9 @@ async function handler( req.query.wId as string ); let { auth } = authenticator; - const { keyWorkspaceId } = authenticator; + const { keyWorkspace } = authenticator; - if (!auth.isBuilder() || keyWorkspaceId !== req.query.wId) { + if (!auth.isBuilder() || keyWorkspace.sId !== req.query.wId) { return apiError(req, res, { status_code: 400, api_error: { diff --git a/front/pages/api/v1/w/[wId]/assistant/conversations/index.ts b/front/pages/api/v1/w/[wId]/assistant/conversations/index.ts index 33a00053758d..19b72a4dc333 100644 --- a/front/pages/api/v1/w/[wId]/assistant/conversations/index.ts +++ b/front/pages/api/v1/w/[wId]/assistant/conversations/index.ts @@ -101,9 +101,9 @@ async function handler( req.query.wId as string ); let { auth } = authenticator; - const { keyWorkspaceId } = authenticator; + const { keyWorkspace } = authenticator; - if (!auth.isBuilder() || keyWorkspaceId !== req.query.wId) { + if (!auth.isBuilder() || keyWorkspace.sId !== req.query.wId) { return apiError(req, res, { status_code: 400, api_error: { From 3c8d8331401220743b97dfa263a9245505df8ff6 Mon Sep 17 00:00:00 2001 From: Flavien David Date: Fri, 2 Aug 2024 09:29:23 +0200 Subject: [PATCH 10/11] :sparkles: --- front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts b/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts index c4424aa24339..6bbaf2093db2 100644 --- a/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts +++ b/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts @@ -286,14 +286,11 @@ async function handler( "App run creation" ); - const isSameWorkspace = keyWorkspace.sId === owner.sId; - const runAsWorkspace = isSameWorkspace ? owner : keyWorkspace; - const groups = await GroupResource.listWorkspaceGroupsFromKey( keyRes.value ); - const runRes = await coreAPI.createRunStream(runAsWorkspace, groups, { + const runRes = await coreAPI.createRunStream(keyWorkspace, groups, { projectId: app.dustAPIProjectId, runType: "deploy", specificationHash: specificationHash, From 4195df3c75041eac07dcf1dfdc3fc1b88ff8cda2 Mon Sep 17 00:00:00 2001 From: Flavien David Date: Fri, 2 Aug 2024 09:38:01 +0200 Subject: [PATCH 11/11] :book: --- front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts b/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts index 6bbaf2093db2..6d08c31ebb29 100644 --- a/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts +++ b/front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts @@ -174,6 +174,10 @@ async function handler( if (keyRes.isErr()) { return apiError(req, res, keyRes.error); } + + // TODO(2024-08-02 flav) Refactor auth.fromKey logic. + // Confusingly, the auth workspace here is the the one from the URL, not the one from the key. + // Where as auth.groups are the groups associated with the the key. const { auth, keyWorkspace } = await Authenticator.fromKey( keyRes.value, req.query.wId as string