mirror of
https://github.com/StanGirard/quivr.git
synced 2024-09-11 13:15:41 +03:00
feat(shareBrain): use subscription delete endpoint for brain deletion (#634)
This commit is contained in:
parent
e61f437ce8
commit
4d00a1ec92
@ -10,6 +10,7 @@ from models.brains import (
|
||||
)
|
||||
from models.settings import common_dependencies
|
||||
from models.users import User
|
||||
|
||||
from routes.authorizations.brain_authorization import has_brain_authorization
|
||||
|
||||
logger = get_logger(__name__)
|
||||
@ -89,25 +90,6 @@ async def get_brain_endpoint(
|
||||
)
|
||||
|
||||
|
||||
# delete one brain
|
||||
@brain_router.delete(
|
||||
"/brains/{brain_id}/",
|
||||
dependencies=[Depends(AuthBearer()), Depends(has_brain_authorization())],
|
||||
tags=["Brain"],
|
||||
)
|
||||
async def delete_brain_endpoint(
|
||||
brain_id: UUID,
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""
|
||||
Delete a specific brain by brain ID.
|
||||
"""
|
||||
brain = Brain(id=brain_id)
|
||||
brain.delete_brain(current_user.id)
|
||||
|
||||
return {"message": f"{brain_id} has been deleted."}
|
||||
|
||||
|
||||
# create new brain
|
||||
@brain_router.post("/brains/", dependencies=[Depends(AuthBearer())], tags=["Brain"])
|
||||
async def create_brain_endpoint(
|
||||
|
@ -118,7 +118,7 @@ def test_delete_all_brains(client, api_key):
|
||||
|
||||
# Send a DELETE request to delete the specific brain
|
||||
delete_response = client.delete(
|
||||
f"/brains/{brain_id}/",
|
||||
f"/brain/{brain_id}/subscription",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
)
|
||||
|
||||
|
@ -70,7 +70,7 @@ describe("useBrainApi", () => {
|
||||
await deleteBrain(id);
|
||||
|
||||
expect(axiosDeleteMock).toHaveBeenCalledTimes(1);
|
||||
expect(axiosDeleteMock).toHaveBeenCalledWith(`/brains/${id}/`);
|
||||
expect(axiosDeleteMock).toHaveBeenCalledWith(`/brain/${id}/subscription`);
|
||||
});
|
||||
|
||||
it("should call getDefaultBrain with the correct parameters", async () => {
|
||||
|
@ -40,7 +40,7 @@ export const deleteBrain = async (
|
||||
brainId: string,
|
||||
axiosInstance: AxiosInstance
|
||||
): Promise<void> => {
|
||||
await axiosInstance.delete(`/brains/${brainId}/`);
|
||||
await axiosInstance.delete(`/brain/${brainId}/subscription`);
|
||||
};
|
||||
|
||||
export const getDefaultBrain = async (
|
||||
|
@ -49,6 +49,10 @@ export const useBrainProvider = () => {
|
||||
await deleteBrain(id);
|
||||
setAllBrains((prevBrains) => prevBrains.filter((brain) => brain.id !== id));
|
||||
void track("DELETE_BRAIN");
|
||||
publish({
|
||||
variant: "success",
|
||||
text: "Brain deleted",
|
||||
});
|
||||
};
|
||||
|
||||
const fetchAllBrains = useCallback(async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user