From 7930586017614702e87b1f212d5014b904f7d8e0 Mon Sep 17 00:00:00 2001 From: Vasilije <8619304+Vasilije1990@users.noreply.github.com> Date: Sat, 27 Jul 2024 12:48:03 +0200 Subject: [PATCH] Fixes to the ACL model --- cognee/api/v1/cognify/cognify_v2.py | 7 ++++--- .../databases/relational/user_authentication/users.py | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cognee/api/v1/cognify/cognify_v2.py b/cognee/api/v1/cognify/cognify_v2.py index 4d2c49440..94ead86e7 100644 --- a/cognee/api/v1/cognify/cognify_v2.py +++ b/cognee/api/v1/cognify/cognify_v2.py @@ -10,7 +10,7 @@ from cognee.infrastructure.databases.graph import get_graph_config from cognee.infrastructure.databases.relational.user_authentication.authentication_db import async_session_maker from cognee.infrastructure.databases.relational.user_authentication.users import has_permission_document, \ - get_user_permissions, get_async_session_context + get_user_permissions, get_async_session_context, fast_api_users_init # from cognee.infrastructure.databases.relational.user_authentication.authentication_db import async_session_maker # from cognee.infrastructure.databases.relational.user_authentication.users import get_user_permissions, fastapi_users from cognee.modules.cognify.config import get_cognify_config @@ -40,7 +40,7 @@ def __init__(self, message: str): self.message = message super().__init__(self.message) -async def cognify(datasets: Union[str, list[str]] = None, root_node_id: str = None, user_id:str="default_user"): +async def cognify(datasets: Union[str, list[str]] = None, root_node_id: str = None): relational_config = get_relationaldb_config() db_engine = relational_config.database_engine @@ -57,8 +57,9 @@ async def run_cognify_pipeline(dataset_name: str, files: list[dict]): file["name"] = file["name"].replace(" ", "_") async with get_async_session_context() as session: + active_user = await fast_api_users_init() - out = await has_permission_document(user_id, file["id"], "write", session) + out = await has_permission_document(active_user.current_user(active=True), file["id"], "write", session) async with update_status_lock: diff --git a/cognee/infrastructure/databases/relational/user_authentication/users.py b/cognee/infrastructure/databases/relational/user_authentication/users.py index cc2fe950a..e48a4d9f4 100644 --- a/cognee/infrastructure/databases/relational/user_authentication/users.py +++ b/cognee/infrastructure/databases/relational/user_authentication/users.py @@ -61,6 +61,9 @@ def get_jwt_strategy() -> JWTStrategy[models.UP, models.ID]: fastapi_users = FastAPIUsers[User, uuid.UUID](get_user_manager, [auth_backend]) +async def fast_api_users_init(): + return fastapi_users + current_active_user = fastapi_users.current_user(active=True)