Mamadou DICKO 2023-11-06 16:58:03 +01:00 committed by GitHub
parent 6abba91a8f
commit 3c0819de09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 10 deletions

View File

@ -252,6 +252,10 @@ class Repository(ABC):
def remove_knowledge_by_id(self, knowledge_id: UUID):
pass
@abstractmethod
def remove_brain_all_knowledge(self, brain_id: UUID):
pass
@abstractmethod
def get_knowledge_by_id(self, knowledge_id: UUID):
pass

View File

@ -92,4 +92,23 @@ class Knowledges(Repository):
.execute()
).data
return all_knowledge
return [Knowledge(**knowledge) for knowledge in all_knowledge]
def remove_brain_all_knowledge(self, brain_id: UUID) -> None:
"""
Remove all knowledge in a brain
Args:
brain_id (UUID): The id of the brain
"""
all_knowledge = self.get_all_knowledge_in_brain(brain_id)
knowledge_to_delete_list = []
for knowledge in all_knowledge:
if knowledge.file_name:
knowledge_to_delete_list.append(f"{brain_id}/{knowledge.file_name}")
self.db.storage.from_("quivr").remove(knowledge_to_delete_list)
self.db.from_("knowledge").delete().filter(
"brain_id", "eq", str(brain_id)
).execute()

View File

@ -0,0 +1,14 @@
from uuid import UUID
from logger import get_logger
from models.settings import get_supabase_db
logger = get_logger(__name__)
def remove_brain_all_knowledge(brain_id: UUID) -> None:
supabase_db = get_supabase_db()
supabase_db.remove_brain_all_knowledge(brain_id)
logger.info(f"All knowledge in brain {brain_id} removed successfully from table")

View File

@ -9,6 +9,7 @@ from repository.files.generate_file_signed_url import generate_file_signed_url
from repository.knowledge.get_all_knowledge import get_all_knowledge
from repository.knowledge.get_knowledge import get_knowledge
from repository.knowledge.remove_knowledge import remove_knowledge
from routes.authorizations.brain_authorization import (
RoleEnum,
has_brain_authorization,

View File

@ -17,6 +17,9 @@ from repository.brain_subscription import (
SubscriptionInvitationService,
resend_invitation_email,
)
from repository.knowledge.remove_brain_all_knowledge import (
remove_brain_all_knowledge,
)
from repository.prompt import delete_prompt_by_id, get_prompt_by_id
from repository.user import get_user_email_by_user_id, get_user_id_by_user_email
@ -128,6 +131,14 @@ async def remove_user_subscription(
"""
Remove a user's subscription to a brain
"""
targeted_brain = get_brain_by_id(brain_id)
if targeted_brain is None:
raise HTTPException(
status_code=404,
detail="Brain not found while trying to delete",
)
brain = Brain(
id=brain_id,
)
@ -151,15 +162,15 @@ async def remove_user_subscription(
if len(brain_other_owners) == 0:
# Delete its prompt if it's private
brain_to_delete = get_brain_by_id(brain_id)
if brain_to_delete:
brain.delete_brain(current_user.id)
if brain_to_delete.prompt_id:
brain_to_delete_prompt = get_prompt_by_id(brain_to_delete.prompt_id)
if brain_to_delete_prompt is not None and (
brain_to_delete_prompt.status == PromptStatusEnum.private
):
delete_prompt_by_id(brain_to_delete.prompt_id)
remove_brain_all_knowledge(brain_id)
brain.delete_brain(current_user.id)
if targeted_brain.prompt_id:
brain_to_delete_prompt = get_prompt_by_id(targeted_brain.prompt_id)
if brain_to_delete_prompt is not None and (
brain_to_delete_prompt.status == PromptStatusEnum.private
):
delete_prompt_by_id(targeted_brain.prompt_id)
else:
brain.delete_user_from_brain(current_user.id)

View File

@ -62,6 +62,10 @@ export const usePrompt = (props: UsePromptProps) => {
promptId
);
useEffect(() => {
setCurrentPromptId(promptId);
}, [promptId]);
const fetchPrompt = async () => {
if (currentPromptId === "" || currentPromptId === undefined) {
return;