[PR #5540] [CLOSED] fix: keep chat lookups scoped for null users #5473

Closed
opened 2026-06-05 15:21:28 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Mintplex-Labs/anything-llm/pull/5540
Author: @haimingZZ
Created: 4/27/2026
Status: Closed

Base: masterHead: fix/user-scoped-chat-null-filter-haimingzz


📝 Commits (1)

  • 5de943b fix: keep chat lookups scoped for null users

📊 Changes

4 files changed (+133 additions, -43 deletions)

View changed files

server/__tests__/utils/helpers/chat/userScopedChatClause.test.js (+50 -0)
📝 server/endpoints/workspaceThreads.js (+23 -12)
📝 server/endpoints/workspaces.js (+52 -31)
server/utils/helpers/chat/userScopedChatClause.js (+8 -0)

📄 Description

Summary

  • add a shared helper for workspace chat ownership filters so null-user sessions are scoped as user_id: null
  • use that helper for workspace and thread chat delete/edit/fork/feedback/TTS lookup paths
  • add focused Jest coverage to prevent undefined from dropping the user ownership filter, including thread and fork filters

Why

Some workspace chat routes built Prisma where clauses with user_id: user?.id. When user is missing, that value becomes undefined, which can be omitted from the query filter instead of matching only null-user chats. This keeps those routes scoped to the intended null-user chat records.

Tests

  • yarn test server/__tests__/utils/helpers/chat/userScopedChatClause.test.js --runInBand
  • node -c server/endpoints/workspaces.js && node -c server/endpoints/workspaceThreads.js && node -c server/utils/helpers/chat/userScopedChatClause.js && node -c server/__tests__/utils/helpers/chat/userScopedChatClause.test.js
  • git diff --check origin/master...HEAD

Local notes

  • yarn --cwd server lint:check --quiet could not run in this checkout because server/node_modules is absent and eslint is not installed locally.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Mintplex-Labs/anything-llm/pull/5540 **Author:** [@haimingZZ](https://github.com/haimingZZ) **Created:** 4/27/2026 **Status:** ❌ Closed **Base:** `master` ← **Head:** `fix/user-scoped-chat-null-filter-haimingzz` --- ### 📝 Commits (1) - [`5de943b`](https://github.com/Mintplex-Labs/anything-llm/commit/5de943b71155c3a48f96480f1ef8ac8733728879) fix: keep chat lookups scoped for null users ### 📊 Changes **4 files changed** (+133 additions, -43 deletions) <details> <summary>View changed files</summary> ➕ `server/__tests__/utils/helpers/chat/userScopedChatClause.test.js` (+50 -0) 📝 `server/endpoints/workspaceThreads.js` (+23 -12) 📝 `server/endpoints/workspaces.js` (+52 -31) ➕ `server/utils/helpers/chat/userScopedChatClause.js` (+8 -0) </details> ### 📄 Description ## Summary - add a shared helper for workspace chat ownership filters so null-user sessions are scoped as `user_id: null` - use that helper for workspace and thread chat delete/edit/fork/feedback/TTS lookup paths - add focused Jest coverage to prevent `undefined` from dropping the user ownership filter, including thread and fork filters ## Why Some workspace chat routes built Prisma `where` clauses with `user_id: user?.id`. When `user` is missing, that value becomes `undefined`, which can be omitted from the query filter instead of matching only null-user chats. This keeps those routes scoped to the intended null-user chat records. ## Tests - `yarn test server/__tests__/utils/helpers/chat/userScopedChatClause.test.js --runInBand` - `node -c server/endpoints/workspaces.js && node -c server/endpoints/workspaceThreads.js && node -c server/utils/helpers/chat/userScopedChatClause.js && node -c server/__tests__/utils/helpers/chat/userScopedChatClause.test.js` - `git diff --check origin/master...HEAD` ## Local notes - `yarn --cwd server lint:check --quiet` could not run in this checkout because `server/node_modules` is absent and `eslint` is not installed locally. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-05 15:21:28 -04:00
yindo closed this issue 2026-06-05 15:21:28 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#5473