Skip to content

Commit 173797a

Browse files
authored
refactor: allow Thread Sharing by user-defined callback (#2521)
I want to allow admins to view any threads. I determine if a user is an admin using custom RBAC roles and saving in the user.metadata. Presumably other developers will have other ways of doing this. This change makes it so that as long as the `@cl.on_shared_thread_view` returns True then the thread can be viewed, instead of requiring the user to share the thread. Developers can customize the logic within this callback however they see fit.
1 parent 517eaa7 commit 173797a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

backend/chainlit/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,8 +1001,8 @@ async def get_shared_thread(
10011001

10021002
is_shared = bool(metadata.get("is_shared"))
10031003

1004-
# Proceed only if both conditions are True.
1005-
if not (user_can_view and is_shared):
1004+
# Proceed only raise an error if both conditions are False.
1005+
if (not user_can_view) and (not is_shared):
10061006
raise HTTPException(status_code=404, detail="Thread not found")
10071007

10081008
metadata.pop("chat_profile", None)

0 commit comments

Comments
 (0)