From a80dd25ee44b891a5bbed034e9f296ef4565f771 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Mon, 2 Feb 2026 14:24:59 +0200 Subject: [PATCH] feat: hide public link option based on permission --- .../components/new-chat/chat-share-button.tsx | 71 +++++++++++-------- 1 file changed, 42 insertions(+), 29 deletions(-) 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 */} + + + )}