Skip to content
18 changes: 9 additions & 9 deletions packages/server/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export interface IChatFlow {
apiConfig?: string
category?: string
type?: ChatflowType
workspaceId?: string
workspaceId: string
}

export interface IChatMessage {
Expand Down Expand Up @@ -114,7 +114,7 @@ export interface ITool {
func?: string
updatedDate: Date
createdDate: Date
workspaceId?: string
workspaceId: string
}

export interface IAssistant {
Expand All @@ -124,7 +124,7 @@ export interface IAssistant {
iconSrc?: string
updatedDate: Date
createdDate: Date
workspaceId?: string
workspaceId: string
}

export interface ICredential {
Expand All @@ -134,7 +134,7 @@ export interface ICredential {
encryptedData: string
updatedDate: Date
createdDate: Date
workspaceId?: string
workspaceId: string
}

export interface IVariable {
Expand All @@ -144,7 +144,7 @@ export interface IVariable {
type: string
updatedDate: Date
createdDate: Date
workspaceId?: string
workspaceId: string
}

export interface ILead {
Expand Down Expand Up @@ -176,7 +176,7 @@ export interface IExecution {
createdDate: Date
updatedDate: Date
stoppedDate: Date
workspaceId?: string
workspaceId: string
}

export interface IComponentNodes {
Expand Down Expand Up @@ -332,7 +332,7 @@ export interface ICredentialReqBody {
name: string
credentialName: string
plainDataObj: ICredentialDataDecrypted
workspaceId?: string
workspaceId: string
}

// Decrypted credential object sent back to client
Expand All @@ -351,7 +351,7 @@ export interface IApiKey {
apiKey: string
apiSecret: string
updatedDate: Date
workspaceId?: string
workspaceId: string
}

export interface ICustomTemplate {
Expand All @@ -365,7 +365,7 @@ export interface ICustomTemplate {
badge?: string
framework?: string
usecases?: string
workspaceId?: string
workspaceId: string
}

export interface IFlowConfig {
Expand Down
15 changes: 15 additions & 0 deletions packages/server/src/controllers/apikey/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const getAllApiKeys = async (req: Request, res: Response, next: NextFunction) =>
try {
const autoCreateNewKey = true
const { page, limit } = getPageAndLimitParams(req)
if (!req.user?.activeWorkspaceId) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Workspace ID is required`)
}
const apiResponse = await apikeyService.getAllApiKeys(req.user?.activeWorkspaceId, autoCreateNewKey, page, limit)
return res.json(apiResponse)
} catch (error) {
Expand All @@ -21,6 +24,9 @@ const createApiKey = async (req: Request, res: Response, next: NextFunction) =>
if (typeof req.body === 'undefined' || !req.body.keyName) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.createApiKey - keyName not provided!`)
}
if (!req.user?.activeWorkspaceId) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Workspace ID is required`)
}
const apiResponse = await apikeyService.createApiKey(req.body.keyName, req.user?.activeWorkspaceId)
return res.json(apiResponse)
} catch (error) {
Expand All @@ -37,6 +43,9 @@ const updateApiKey = async (req: Request, res: Response, next: NextFunction) =>
if (typeof req.body === 'undefined' || !req.body.keyName) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.updateApiKey - keyName not provided!`)
}
if (!req.user?.activeWorkspaceId) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Workspace ID is required`)
}
const apiResponse = await apikeyService.updateApiKey(req.params.id, req.body.keyName, req.user?.activeWorkspaceId)
return res.json(apiResponse)
} catch (error) {
Expand All @@ -50,6 +59,9 @@ const importKeys = async (req: Request, res: Response, next: NextFunction) => {
if (typeof req.body === 'undefined' || !req.body.jsonFile) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.importKeys - body not provided!`)
}
if (!req.user?.activeWorkspaceId) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Workspace ID is required`)
}
req.body.workspaceId = req.user?.activeWorkspaceId
const apiResponse = await apikeyService.importKeys(req.body)
return res.json(apiResponse)
Expand All @@ -64,6 +76,9 @@ const deleteApiKey = async (req: Request, res: Response, next: NextFunction) =>
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.deleteApiKey - id not provided!`)
}
if (!req.user?.activeWorkspaceId) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Workspace ID is required`)
}
const apiResponse = await apikeyService.deleteApiKey(req.params.id, req.user?.activeWorkspaceId)
return res.json(apiResponse)
} catch (error) {
Expand Down
45 changes: 40 additions & 5 deletions packages/server/src/controllers/assistants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ const deleteAssistant = async (req: Request, res: Response, next: NextFunction)
`Error: assistantsController.deleteAssistant - id not provided!`
)
}
const apiResponse = await assistantsService.deleteAssistant(req.params.id, req.query.isDeleteBoth)
const workspaceId = req.user?.activeWorkspaceId
if (!workspaceId) {
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: assistantsController.deleteAssistant - workspace ${workspaceId} not found!`
)
}
const apiResponse = await assistantsService.deleteAssistant(req.params.id, req.query.isDeleteBoth, workspaceId)
return res.json(apiResponse)
} catch (error) {
next(error)
Expand All @@ -62,7 +69,14 @@ const deleteAssistant = async (req: Request, res: Response, next: NextFunction)
const getAllAssistants = async (req: Request, res: Response, next: NextFunction) => {
try {
const type = req.query.type as AssistantType
const apiResponse = await assistantsService.getAllAssistants(type, req.user?.activeWorkspaceId)
const workspaceId = req.user?.activeWorkspaceId
if (!workspaceId) {
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: assistantsController.getAllAssistants - workspace ${workspaceId} not found!`
)
}
const apiResponse = await assistantsService.getAllAssistants(workspaceId, type)
return res.json(apiResponse)
} catch (error) {
next(error)
Expand All @@ -77,7 +91,14 @@ const getAssistantById = async (req: Request, res: Response, next: NextFunction)
`Error: assistantsController.getAssistantById - id not provided!`
)
}
const apiResponse = await assistantsService.getAssistantById(req.params.id)
const workspaceId = req.user?.activeWorkspaceId
if (!workspaceId) {
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: assistantsController.getAssistantById - workspace ${workspaceId} not found!`
)
}
const apiResponse = await assistantsService.getAssistantById(req.params.id, workspaceId)
return res.json(apiResponse)
} catch (error) {
next(error)
Expand All @@ -98,7 +119,14 @@ const updateAssistant = async (req: Request, res: Response, next: NextFunction)
`Error: assistantsController.updateAssistant - body not provided!`
)
}
const apiResponse = await assistantsService.updateAssistant(req.params.id, req.body)
const workspaceId = req.user?.activeWorkspaceId
if (!workspaceId) {
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: assistantsController.updateAssistant - workspace ${workspaceId} not found!`
)
}
const apiResponse = await assistantsService.updateAssistant(req.params.id, req.body, workspaceId)
return res.json(apiResponse)
} catch (error) {
next(error)
Expand All @@ -116,7 +144,14 @@ const getChatModels = async (req: Request, res: Response, next: NextFunction) =>

const getDocumentStores = async (req: Request, res: Response, next: NextFunction) => {
try {
const apiResponse = await assistantsService.getDocumentStores(req.user?.activeWorkspaceId)
const workspaceId = req.user?.activeWorkspaceId
if (!workspaceId) {
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: assistantsController.getDocumentStores - workspace ${workspaceId} not found!`
)
}
const apiResponse = await assistantsService.getDocumentStores(workspaceId)
return res.json(apiResponse)
} catch (error) {
next(error)
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/controllers/chat-messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const removeAllChatMessages = async (req: Request, res: Response, next: NextFunc
)
}
const chatflowid = req.params.id
const chatflow = await chatflowsService.getChatflowById(req.params.id)
const chatflow = await chatflowsService.getChatflowById(req.params.id, workspaceId)
if (!chatflow) {
return res.status(404).send(`Chatflow ${req.params.id} not found`)
}
Expand Down
25 changes: 16 additions & 9 deletions packages/server/src/controllers/chatflows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,14 @@ const getChatflowById = async (req: Request, res: Response, next: NextFunction)
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsController.getChatflowById - id not provided!`)
}
const apiResponse = await chatflowsService.getChatflowById(req.params.id)
const workspaceId = req.user?.activeWorkspaceId
if (!workspaceId) {
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: chatflowsController.getChatflowById - workspace ${workspaceId} not found!`
)
}
const apiResponse = await chatflowsService.getChatflowById(req.params.id, workspaceId)
return res.json(apiResponse)
} catch (error) {
next(error)
Expand Down Expand Up @@ -165,7 +172,14 @@ const updateChatflow = async (req: Request, res: Response, next: NextFunction) =
if (typeof req.params === 'undefined' || !req.params.id) {
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsController.updateChatflow - id not provided!`)
}
const chatflow = await chatflowsService.getChatflowById(req.params.id)
const workspaceId = req.user?.activeWorkspaceId
if (!workspaceId) {
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: chatflowsController.saveChatflow - workspace ${workspaceId} not found!`
)
}
const chatflow = await chatflowsService.getChatflowById(req.params.id, workspaceId)
if (!chatflow) {
return res.status(404).send(`Chatflow ${req.params.id} not found`)
}
Expand All @@ -176,13 +190,6 @@ const updateChatflow = async (req: Request, res: Response, next: NextFunction) =
`Error: chatflowsController.saveChatflow - organization ${orgId} not found!`
)
}
const workspaceId = req.user?.activeWorkspaceId
if (!workspaceId) {
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: chatflowsController.saveChatflow - workspace ${workspaceId} not found!`
)
}
const subscriptionId = req.user?.activeOrganizationSubscriptionId || ''
const body = req.body
const updateChatFlow = new ChatFlow()
Expand Down
36 changes: 32 additions & 4 deletions packages/server/src/controllers/credentials/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ const deleteCredentials = async (req: Request, res: Response, next: NextFunction
`Error: credentialsController.deleteCredentials - id not provided!`
)
}
const apiResponse = await credentialsService.deleteCredentials(req.params.id)
const workspaceId = req.user?.activeWorkspaceId
if (!workspaceId) {
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: credentialsController.deleteCredentials - workspace ${workspaceId} not found!`
)
}
const apiResponse = await credentialsService.deleteCredentials(req.params.id, workspaceId)
return res.json(apiResponse)
} catch (error) {
next(error)
Expand All @@ -37,7 +44,14 @@ const deleteCredentials = async (req: Request, res: Response, next: NextFunction

const getAllCredentials = async (req: Request, res: Response, next: NextFunction) => {
try {
const apiResponse = await credentialsService.getAllCredentials(req.query.credentialName, req.user?.activeWorkspaceId)
const workspaceId = req.user?.activeWorkspaceId
if (!workspaceId) {
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: credentialsController.getAllCredentials - workspace ${workspaceId} not found!`
)
}
const apiResponse = await credentialsService.getAllCredentials(req.query.credentialName, workspaceId)
return res.json(apiResponse)
} catch (error) {
next(error)
Expand All @@ -52,7 +66,14 @@ const getCredentialById = async (req: Request, res: Response, next: NextFunction
`Error: credentialsController.getCredentialById - id not provided!`
)
}
const apiResponse = await credentialsService.getCredentialById(req.params.id, req.user?.activeWorkspaceId)
const workspaceId = req.user?.activeWorkspaceId
if (!workspaceId) {
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: credentialsController.getCredentialById - workspace ${workspaceId} not found!`
)
}
const apiResponse = await credentialsService.getCredentialById(req.params.id, workspaceId)
return res.json(apiResponse)
} catch (error) {
next(error)
Expand All @@ -73,7 +94,14 @@ const updateCredential = async (req: Request, res: Response, next: NextFunction)
`Error: credentialsController.updateCredential - body not provided!`
)
}
const apiResponse = await credentialsService.updateCredential(req.params.id, req.body)
const workspaceId = req.user?.activeWorkspaceId
if (!workspaceId) {
throw new InternalFlowiseError(
StatusCodes.NOT_FOUND,
`Error: credentialsController.updateCredential - workspace ${workspaceId} not found!`
)
}
const apiResponse = await credentialsService.updateCredential(req.params.id, req.body, workspaceId)
return res.json(apiResponse)
} catch (error) {
next(error)
Expand Down
Loading