mirror of https://github.com/kortix-ai/suna.git
fix: policy and share page api error
This commit is contained in:
parent
655840de14
commit
8b6d9c0903
|
@ -0,0 +1,16 @@
|
|||
DROP POLICY IF EXISTS thread_select_policy ON threads;
|
||||
|
||||
CREATE POLICY thread_select_policy ON threads
|
||||
FOR SELECT
|
||||
USING (
|
||||
is_public IS TRUE
|
||||
OR basejump.has_role_on_account(account_id) = true
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM projects
|
||||
WHERE projects.project_id = threads.project_id
|
||||
AND (
|
||||
projects.is_public IS TRUE
|
||||
OR basejump.has_role_on_account(projects.account_id) = true
|
||||
)
|
||||
)
|
||||
);
|
File diff suppressed because it is too large
Load Diff
|
@ -54,7 +54,7 @@ export function NavAgents() {
|
|||
const [isLoading, setIsLoading] = useState(true)
|
||||
const [loadingThreadId, setLoadingThreadId] = useState<string | null>(null)
|
||||
const [showShareModal, setShowShareModal] = useState(false)
|
||||
const [selectedThreadId, setSelectedThreadId] = useState<string | null>(null)
|
||||
const [selectedItem, setSelectedItem] = useState<{ threadId: string, projectId: string } | null>(null)
|
||||
const pathname = usePathname()
|
||||
const router = useRouter()
|
||||
|
||||
|
@ -284,11 +284,11 @@ export function NavAgents() {
|
|||
align={isMobile ? "end" : "start"}
|
||||
>
|
||||
<DropdownMenuItem onClick={() => {
|
||||
setSelectedThreadId(thread?.threadId)
|
||||
setSelectedItem({ threadId: thread?.threadId, projectId: thread?.projectId })
|
||||
setShowShareModal(true)
|
||||
}}>
|
||||
<Share2 className="text-muted-foreground" />
|
||||
<span>Share</span>
|
||||
<span>Share Chat</span>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem asChild>
|
||||
<a href={thread.url} target="_blank" rel="noopener noreferrer">
|
||||
|
@ -321,7 +321,8 @@ export function NavAgents() {
|
|||
<ShareModal
|
||||
isOpen={showShareModal}
|
||||
onClose={() => setShowShareModal(false)}
|
||||
threadId={selectedThreadId}
|
||||
threadId={selectedItem?.threadId}
|
||||
projectId={selectedItem?.projectId}
|
||||
/>
|
||||
</SidebarGroup>
|
||||
)
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
} from "@/components/ui/dialog";
|
||||
import { X, Copy, Share2, Link, Link2Off, Check } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { getThread, toggleThreadPublicStatus } from "@/lib/api";
|
||||
import { getThread, updateProject, updateThread } from "@/lib/api";
|
||||
|
||||
interface SocialShareOption {
|
||||
name: string;
|
||||
|
@ -19,9 +19,10 @@ interface ShareModalProps {
|
|||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
threadId?: string;
|
||||
projectId?: string;
|
||||
}
|
||||
|
||||
export function ShareModal({ isOpen, onClose, threadId }: ShareModalProps) {
|
||||
export function ShareModal({ isOpen, onClose, threadId, projectId }: ShareModalProps) {
|
||||
const [shareLink, setShareLink] = useState<string | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isChecking, setIsChecking] = useState(false);
|
||||
|
@ -67,7 +68,7 @@ export function ShareModal({ isOpen, onClose, threadId }: ShareModalProps) {
|
|||
|
||||
try {
|
||||
// Use the API to mark the thread as public
|
||||
await toggleThreadPublicStatus(threadId, true);
|
||||
await updatePublicStatus(true);
|
||||
const generatedLink = generateShareLink();
|
||||
setShareLink(generatedLink);
|
||||
toast.success("Shareable link created successfully");
|
||||
|
@ -86,7 +87,7 @@ export function ShareModal({ isOpen, onClose, threadId }: ShareModalProps) {
|
|||
|
||||
try {
|
||||
// Use the API to mark the thread as private
|
||||
await toggleThreadPublicStatus(threadId, false);
|
||||
await updatePublicStatus(false);
|
||||
setShareLink(null);
|
||||
toast.success("Shareable link removed");
|
||||
} catch (error) {
|
||||
|
@ -97,6 +98,13 @@ export function ShareModal({ isOpen, onClose, threadId }: ShareModalProps) {
|
|||
}
|
||||
};
|
||||
|
||||
const updatePublicStatus = async (isPublic: boolean) => {
|
||||
console.log("Updating public status for thread:", threadId, "and project:", projectId, "to", isPublic);
|
||||
if (!threadId) return;
|
||||
await updateProject(projectId, { is_public: isPublic });
|
||||
await updateThread(threadId, { is_public: isPublic });
|
||||
};
|
||||
|
||||
const copyToClipboard = () => {
|
||||
if (shareLink) {
|
||||
setIsCopying(true);
|
||||
|
|
|
@ -237,6 +237,7 @@ export function SiteHeader({
|
|||
isOpen={showShareModal}
|
||||
onClose={() => setShowShareModal(false)}
|
||||
threadId={threadId}
|
||||
projectId={projectId}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
|
|
|
@ -1048,10 +1048,6 @@ export const updateThread = async (threadId: string, data: Partial<Thread>): Pro
|
|||
return updatedThread;
|
||||
};
|
||||
|
||||
export const toggleThreadPublicStatus = async (threadId: string, isPublic: boolean): Promise<Thread> => {
|
||||
return updateThread(threadId, { is_public: isPublic });
|
||||
};
|
||||
|
||||
// Function to get public projects
|
||||
export const getPublicProjects = async (): Promise<Project[]> => {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue