diff --git a/surfsense_web/components/new-chat/chat-share-button.tsx b/surfsense_web/components/new-chat/chat-share-button.tsx index f523752f1..85e76966e 100644 --- a/surfsense_web/components/new-chat/chat-share-button.tsx +++ b/surfsense_web/components/new-chat/chat-share-button.tsx @@ -3,10 +3,11 @@ import { useQueryClient } from "@tanstack/react-query"; import { useAtomValue, useSetAtom } from "jotai"; import { Globe, User, Users } from "lucide-react"; -import { useCallback, useState } from "react"; +import { useCallback, useMemo, useState } from "react"; import { toast } from "sonner"; import { createSnapshotMutationAtom } from "@/atoms/chat/chat-thread-mutation.atoms"; import { currentThreadAtom, setThreadVisibilityAtom } from "@/atoms/chat/current-thread.atom"; +import { myAccessAtom } from "@/atoms/members/members-query.atoms"; import { Button } from "@/components/ui/button"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; @@ -56,6 +57,14 @@ export function ChatShareButton({ thread, onVisibilityChange, className }: ChatS createSnapshotMutationAtom ); + // Permission check for public sharing + const { data: access } = useAtomValue(myAccessAtom); + const canCreatePublicLink = useMemo(() => { + if (!access) return false; + if (access.is_owner) return true; + return access.permissions?.includes("public_sharing:create") ?? false; + }, [access]); + // Use Jotai visibility if available (synced from chat page), otherwise fall back to thread prop const currentVisibility = currentThreadState.visibility ?? thread?.visibility ?? "PRIVATE"; @@ -183,35 +192,39 @@ export function ChatShareButton({ thread, onVisibilityChange, className }: ChatS ); })} - {/* Divider */} -
+ {canCreatePublicLink && ( + <> + {/* Divider */} + - {/* Public Link Option */} - + {/* Public Link Option */} + + > + )}