feat: adds context variable for the user object
This commit is contained in:
parent
c4545cdaa3
commit
e7fe66470a
2 changed files with 6 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ from cognee.modules.users.methods import get_default_user
|
|||
from cognee.modules.search.methods import search as search_function
|
||||
from cognee.modules.data.methods import get_authorized_existing_datasets
|
||||
from cognee.modules.data.exceptions import DatasetNotFoundError
|
||||
from cognee.context_global_variables import set_session_user_context_variable
|
||||
|
||||
|
||||
async def search(
|
||||
|
|
@ -168,6 +169,8 @@ async def search(
|
|||
if user is None:
|
||||
user = await get_default_user()
|
||||
|
||||
await set_session_user_context_variable(user)
|
||||
|
||||
# Transform string based datasets to UUID - String based datasets can only be found for current user
|
||||
if datasets is not None and [all(isinstance(dataset, str) for dataset in datasets)]:
|
||||
datasets = await get_authorized_existing_datasets(datasets, "read", user)
|
||||
|
|
|
|||
|
|
@ -12,9 +12,12 @@ from cognee.modules.users.methods import get_user
|
|||
# for different async tasks, threads and processes
|
||||
vector_db_config = ContextVar("vector_db_config", default=None)
|
||||
graph_db_config = ContextVar("graph_db_config", default=None)
|
||||
session_user = ContextVar("session_user", default=None)
|
||||
soup_crawler_config = ContextVar("soup_crawler_config", default=None)
|
||||
tavily_config = ContextVar("tavily_config", default=None)
|
||||
|
||||
async def set_session_user_context_variable(user):
|
||||
session_user.set(user)
|
||||
|
||||
async def set_database_global_context_variables(dataset: Union[str, UUID], user_id: UUID):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue