mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Create API endpoint to unshare a public conversation
Pass isOwner field from the get shared conversation API endpoint if the currently authenticated user created the requested public conversation
This commit is contained in:
@@ -908,6 +908,10 @@ class PublicConversationAdapters:
|
||||
# Public conversations are viewable by anyone, but not editable.
|
||||
return f"/share/chat/{public_conversation.slug}/"
|
||||
|
||||
@staticmethod
|
||||
def delete_public_conversation_by_slug(user: KhojUser, slug: str):
|
||||
return PublicConversation.objects.filter(source_owner=user, slug=slug).first().delete()
|
||||
|
||||
|
||||
class ConversationAdapters:
|
||||
@staticmethod
|
||||
|
||||
@@ -11,7 +11,7 @@ from urllib.parse import unquote
|
||||
|
||||
from asgiref.sync import sync_to_async
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
from fastapi.responses import Response, StreamingResponse
|
||||
from fastapi.responses import RedirectResponse, Response, StreamingResponse
|
||||
from starlette.authentication import has_required_scope, requires
|
||||
|
||||
from khoj.app.settings import ALLOWED_HOSTS
|
||||
@@ -255,6 +255,7 @@ def chat_history(
|
||||
"conversation_id": conversation.id,
|
||||
"slug": conversation.title if conversation.title else conversation.slug,
|
||||
"agent": agent_metadata,
|
||||
"is_owner": conversation.user == user,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -332,6 +333,7 @@ def get_shared_chat(
|
||||
"conversation_id": conversation.id,
|
||||
"slug": scrubbed_title,
|
||||
"agent": agent_metadata,
|
||||
"is_owner": conversation.source_owner == user,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -449,6 +451,33 @@ def duplicate_chat_history_public_conversation(
|
||||
)
|
||||
|
||||
|
||||
@api_chat.delete("/share")
|
||||
@requires(["authenticated"])
|
||||
def delete_public_conversation(
|
||||
request: Request,
|
||||
common: CommonQueryParams,
|
||||
public_conversation_slug: str,
|
||||
):
|
||||
user = request.user.object
|
||||
|
||||
# Delete Public Conversation
|
||||
PublicConversationAdapters.delete_public_conversation_by_slug(user=user, slug=public_conversation_slug)
|
||||
|
||||
update_telemetry_state(
|
||||
request=request,
|
||||
telemetry_type="api",
|
||||
api="delete_chat_share",
|
||||
**common.__dict__,
|
||||
)
|
||||
|
||||
# Redirect to the main chat page
|
||||
redirect_uri = str(request.app.url_path_for("chat_page"))
|
||||
return RedirectResponse(
|
||||
url=redirect_uri,
|
||||
status_code=301,
|
||||
)
|
||||
|
||||
|
||||
@api_chat.get("/sessions")
|
||||
@requires(["authenticated"])
|
||||
def chat_sessions(
|
||||
|
||||
Reference in New Issue
Block a user