Skip to content

Commit

Permalink
feat: remove private prompts on brain deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
mamadoudicko committed Aug 3, 2023
1 parent b3fb8fc commit 5144425
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backend/core/routes/subscription_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
from fastapi import APIRouter, Depends, HTTPException
from models.brains import Brain
from models.brains_subscription_invitations import BrainSubscription
from models.prompt import PromptStatusEnum
from models.users import User
from pydantic import BaseModel
from repository.brain.create_brain_user import create_brain_user
from repository.brain.get_brain_by_id import get_brain_by_id
from repository.brain.get_brain_details import get_brain_details
from repository.brain.get_brain_for_user import get_brain_for_user
from repository.brain.update_user_rights import update_brain_user_rights
Expand All @@ -17,6 +19,8 @@
from repository.brain_subscription.subscription_invitation_service import (
SubscriptionInvitationService,
)
from repository.prompt.delete_prompt_py_id import delete_prompt_by_id
from repository.prompt.get_prompt_by_id import get_prompt_by_id
from repository.user.get_user_email_by_user_id import get_user_email_by_user_id
from repository.user.get_user_id_by_user_email import get_user_id_by_user_email

Expand Down Expand Up @@ -143,6 +147,14 @@ async def remove_user_subscription(
]

if len(brain_other_owners) == 0:
# Delete its prompt if it's private
deleting_brain = get_brain_by_id(brain_id)
if deleting_brain and deleting_brain.prompt_id:
deleting_brain_prompt = get_prompt_by_id(deleting_brain.prompt_id)
if deleting_brain_prompt is not None and (
deleting_brain_prompt.status == PromptStatusEnum.private
):
delete_prompt_by_id(deleting_brain.prompt_id)
brain.delete_brain(current_user.id)
else:
brain.delete_user_from_brain(current_user.id)
Expand Down

0 comments on commit 5144425

Please sign in to comment.