Skip to content

Commit

Permalink
Clean up bugs around user deletion (#1769)
Browse files Browse the repository at this point in the history
* Hotfix: Resend Verification Email HS

* Clean up bugs around user deletion
  • Loading branch information
NolanTrem authored Jan 7, 2025
1 parent 389c00b commit cb89d2a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
20 changes: 16 additions & 4 deletions js/sdk/__tests__/RetrievalIntegrationSuperUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,23 @@ describe("r2rClient V3 Documents Integration Tests", () => {
// expect(content.length).toBeGreaterThan(0);
// }, 30000);

test("Delete untitled document", async () => {
const response = await client.documents.delete({
id: "28ce9a4c-4d15-5287-b0c6-67834b9c4546",
});
test("List and delete conversations", async () => {
const listResponse = await client.conversations.list();
expect(listResponse.results).toBeDefined();

for (const conversation of listResponse.results) {
const deleteResponse = await client.conversations.delete({
id: conversation.id,
});
expect(deleteResponse.results).toBeDefined();
}

const finalListResponse = await client.conversations.list();
expect(finalListResponse.results.length).toBe(0);
});

test("Delete document", async () => {
const response = await client.documents.delete({ id: documentId });
expect(response.results).toBeDefined();
});
});
9 changes: 8 additions & 1 deletion py/core/database/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import asyncpg
import httpx
from asyncpg.exceptions import UndefinedTableError, UniqueViolationError
from asyncpg.exceptions import UniqueViolationError
from fastapi import HTTPException

from core.base.abstractions import (
Expand Down Expand Up @@ -2286,6 +2286,13 @@ async def delete(self, collection_id: UUID) -> None:
QUERY = f"""
DELETE FROM {self._get_table_name("graphs")} WHERE collection_id = $1
"""
try:
await self.connection_manager.execute_query(QUERY, [collection_id])
except Exception as e:
raise HTTPException(
status_code=500,
detail=f"An error occurred while deleting the graph: {e}",
) from e

async def perform_graph_clustering(
self,
Expand Down
3 changes: 1 addition & 2 deletions py/core/main/api/v3/collections_router.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import textwrap
from tempfile import NamedTemporaryFile
from typing import Optional
from uuid import UUID

Expand Down Expand Up @@ -655,7 +654,7 @@ async def delete_collection(
auth_user, id, CollectionAction.DELETE, self.services
)

await self.services.management.delete_collection(id)
await self.services.management.delete_collection(collection_id=id)
return GenericBooleanResponse(success=True) # type: ignore

@self.router.post(
Expand Down
4 changes: 3 additions & 1 deletion py/core/main/services/auth_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ async def register(self, email: str, password: str) -> User:
return await self.providers.auth.register(email, password)

@telemetry_event("SendVerificationEmail")
async def send_verification_email(self, email: str) -> dict[str, str]:
async def send_verification_email(
self, email: str
) -> tuple[str, datetime]:
return await self.providers.auth.send_verification_email(email=email)

@telemetry_event("VerifyEmail")
Expand Down
11 changes: 9 additions & 2 deletions py/core/main/services/management_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,14 @@ async def delete_collection(self, collection_id: UUID) -> bool:
await self.providers.database.chunks_handler.delete_collection_vector(
collection_id
)
try:
await self.providers.database.graphs_handler.delete(
collection_id=collection_id,
)
except Exception as e:
logger.warning(
f"Error deleting graph for collection {collection_id}: {e}"
)
return True

@telemetry_event("ListCollections")
Expand Down Expand Up @@ -619,10 +627,9 @@ async def add_user_to_collection(
async def remove_user_from_collection(
self, user_id: UUID, collection_id: UUID
) -> bool:
x = await self.providers.database.users_handler.remove_user_from_collection(
return await self.providers.database.users_handler.remove_user_from_collection(
user_id, collection_id
)
return x

@telemetry_event("GetUsersInCollection")
async def get_users_in_collection(
Expand Down

0 comments on commit cb89d2a

Please sign in to comment.