Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make userId actually optional for workspaceThread endpoint #2276

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions server/endpoints/api/workspaceThread/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ const { WorkspaceThread } = require("../../../models/workspaceThread");
const { Workspace } = require("../../../models/workspace");
const { validApiKey } = require("../../../utils/middleware/validApiKey");
const { reqBody, multiUserMode } = require("../../../utils/http");
const {
streamChatWithWorkspace,
VALID_CHAT_MODE,
} = require("../../../utils/chats/stream");
const { VALID_CHAT_MODE } = require("../../../utils/chats/stream");
const { Telemetry } = require("../../../models/telemetry");
const { EventLogs } = require("../../../models/eventLogs");
const {
Expand Down Expand Up @@ -71,14 +68,19 @@ function apiWorkspaceThreadEndpoints(app) {
*/
try {
const { slug } = request.params;
const { userId } = reqBody(request);
let { userId = null } = reqBody(request);
const workspace = await Workspace.get({ slug });

if (!workspace) {
response.sendStatus(400).end();
return;
}

// If the system is not multi-user and you pass in a userId
// it needs to be nullified as no users exist. This can still fail validation
// as we don't check if the userID is valid.
if (!response.locals.multiUserMode && !!userId) userId = null;

const { thread, message } = await WorkspaceThread.new(
workspace,
userId ? Number(userId) : null
Expand Down